From ed5edbdc249a831e1e2cea1e3d67c0ae45408f66 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 25 Mar 2024 16:27:23 +0100 Subject: [PATCH] Bug 35560: Add filter on status Signed-off-by: Lucas Gass Signed-off-by: Jonathan Druart Signed-off-by: David Nind --- .../prog/en/modules/members/holdshistory.tt | 99 +++++++++++++++++-- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt index e5985d09a58..caba6eda369 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/holdshistory.tt @@ -54,6 +54,30 @@

Current holds

[% IF patron.holds.count %] +
+

+ + + + + + + + + + + + + + + + + + + + +

+
@@ -79,6 +103,22 @@

Historical holds

[% IF patron.old_holds.count %] +
+

+ + + + + + + + + + + + +

+
@@ -118,12 +158,46 @@ //Remove item type column settings table_settings['columns'] = table_settings['columns'].filter(function(c){return c['columnname'] != 'itemtype';}); [% END %] - build_holds_table("#table_holdshistory"); - build_holds_table("#table_oldholdshistory", 1); + let current_holds_table = build_holds_table("#table_holdshistory"); + let old_holds_table = build_holds_table("#table_oldholdshistory", 1); function build_holds_table(table_id, old){ + let additional_filters = { + "-or": function(){ + let statuses = []; + let include_cancelled = false; + if ( table_id == '#table_holdshistory' ) { + if ( $("#current_pending_filter").is(":checked") ) { + statuses.push(null); + } + if ( $("#current_waiting_filter").is(":checked") ) { + statuses.push("W"); + } + if ( $("#current_processing_filter").is(":checked") ) { + statuses.push("P"); + } + if ( $("#current_transit_filter").is(":checked") ) { + statuses.push("T"); + } + } else { + if ( $("#old_fulfilled_filter").is(":checked") ) { + statuses.push("F"); + } + if ( $("#old_cancelled_filter").is(":checked") ) { + include_cancelled = true; + } + } + if ( include_cancelled ) { + return [{status: statuses}, { cancellation_date: {"<": new Date().toISOString() } } ]; // cancellation_date cannot be in the future. Would be better a 'not null' here however. + } else { + return [{status: statuses}]; + } + }, + + }; + let table_url = '/api/v1/patrons/[% patron.borrowernumber | uri %]/holds'; if (old){table_url += '?old=1'} - $(table_id).kohaTable({ + return $(table_id).kohaTable({ ajax: { url: table_url, }, @@ -221,8 +295,8 @@ }, [% END %] { - data: "found", // FIXME filter with dropdown list - searchable: true, + data: "status", + searchable: false, orderable: true, render: function (data, type, row, meta) { if ( row.status == 'F' ) { @@ -245,8 +319,21 @@ } }, ], - }, table_settings); + }, table_settings, true, additional_filters); } + $("#current_holds_filters :checkbox, #old_holds_filters :checkbox").on("change", function(e){ + e.preventDefault(); + let container = $(this).closest("div"); + if ( $(this).hasClass("show_all") ) { + if ( $(this).is(":checked") ) { + container.find(":checkbox").prop("checked", true); + } + } else if ( $(this).not(":checked") ) { + container.find(".show_all").prop("checked", false); + } + let table_dt = $("#"+container.data("table-id")).DataTable(); + table_dt.draw(); + }); }); [% END %] -- 2.39.5