From f1d8a6e01d208c31524e35c19e9c037fc4c9d5b3 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. --- .../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 eebb3d11114..d831c30673b 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 46776432bfd..7461ce94885 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.45.2