From e4b77f47c44531f1bf814e0ba3abf1588e76948c 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 Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- .../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 d30705b9f5..84b33bafd6 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 @@ -214,6 +214,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 ee6d404b04..72c47c9a7e 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.5