From b9537cbdd5d5f4287304dceb15afb2fecc3d731b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 20 Jun 2024 11:41:15 +0100 Subject: [PATCH] Bug 37065: Filter completed bookings by default This patch adds a default filter for the bookings table on the bookings tab of a biblio. We also add the option to turn off the filtering after initial page load. Signed-off-by: David Nind --- .../prog/en/modules/bookings/list.tt | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt index f1c299a40c..2fa1cd694a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -43,6 +43,10 @@

Bookings for [% INCLUDE 'biblio-title-head.inc' %]

@@ -198,6 +202,18 @@ } ); + let filter_completed = true; + let additional_filters = { + end_date: function(){ + if ( filter_completed ) { + let today = new Date(); + return { ">=": today.toISOString() } + } else { + return; + } + } + }; + var bookings_table_url = "/api/v1/biblios/[% biblionumber | uri %]/bookings"; bookings_table = $('#bookings_table').kohaTable({ "ajax": { @@ -281,7 +297,22 @@ return result; } }] - }, [], 0); + }, [], 0, additional_filters); + + var txtActivefilter = _("Include completed"); + var txtInactivefilter = _("Filter completed"); + $('#completed_filter').on("click", function() { + if ($(this).hasClass('filtered')){ + filter_completed = false; + $(this).html(' '+txtActivefilter); + } else { + filter_completed = true; + $(this).html(' '+txtInactivefilter); + } + bookings_table.DataTable().draw(); + $(this).toggleClass('filtered'); + }); + }); [% END %] -- 2.39.2