From 92f419ee7e43071072d9f79ee376b9f802035532 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 20 Jun 2024 12:01:34 +0100 Subject: [PATCH] Bug 37141: Add 'Show completed' option to bookings tab This patch adds the 'Show completed' filter toggle option to the bookings display tab on both the patron details and circulation pages. Signed-off-by: Paul Derscheid Signed-off-by: David Nind --- .../prog/en/includes/patron-detail-tabs.inc | 3 ++ .../intranet-tmpl/prog/js/tables/bookings.js | 37 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc index eebb3d1111..d831c30673 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-detail-tabs.inc @@ -228,6 +228,9 @@ [% WRAPPER tab_panel tabname="bookings" %] [% IF ( bookings_count ) %] +
+ Show expired +
[% ELSE %]

Patron has nothing booked.

diff --git a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js b/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js index 46776432bf..7461ce9488 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js +++ b/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js @@ -4,8 +4,21 @@ var bookings_table; $(document).ready(function () { // Load bookings table on tab selection $("#bookings-tab").on("click", function () { + let filter_expired = true; + let additional_filters = { + patron_id: patron_borrowernumber, + end_date: function () { + if (filter_expired) { + let today = new Date(); + return { ">=": today.toISOString() } + } else { + return; + } + } + }; + if (!bookings_table) { - var today = new Date(); + var bookings_table_url = "/api/v1/bookings"; bookings_table = $("#bookings_table").kohaTable( { @@ -87,13 +100,23 @@ $(document).ready(function () { }, ], }, - table_settings_bookings_table, - 0, - { - patron_id: patron_borrowernumber, - end_date: { ">=": today.toISOString() }, - } + table_settings_bookings_table, 0, additional_filters ); } }); + + var txtActivefilter = _("Show expired"); + var txtInactivefilter = _("Hide expired"); + $("#expired_filter").on("click", function () { + if ($(this).hasClass('filtered')) { + filter_expired = false; + $(this).html(' ' + txtInactivefilter); + } else { + filter_expired = true; + $(this).html(' ' + txtActivefilter); + } + bookings_table.DataTable().draw(); + $(this).toggleClass('filtered'); + }); + }); -- 2.39.2