From 4288cb6c1ec7b158c4b1886be2c73e02998a56b6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 20 Jun 2024 12:01:34 +0100 Subject: [PATCH] Bug 37141: Add 'Include completed' option to bookings tab This patch adds the 'Include 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 b220d7952af..a4a06ad9dd3 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 ) %] +
+ Include completed +
[% 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 585c1af94c2..d794d4cccf2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js +++ b/koha-tmpl/intranet-tmpl/prog/js/tables/bookings.js @@ -5,8 +5,21 @@ $(document).ready(function () { // Load bookings table on tab selection $("#bookings-tab").on("click", function () { + let filter_completed = true; + let additional_filters = { + patron_id: patron_borrowernumber, + end_date: function () { + if (filter_completed) { + 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( { @@ -88,13 +101,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 = _("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'); + }); + }); }); -- 2.45.2