From 92390aed7cfed869995dc97e3598c53f6e7f2db9 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 4 Sep 2024 13:05:17 +0000 Subject: [PATCH] Bug 37830: Add ability to filter holdings in OPAC Test plan: 1) Visit any OPAC biblio page, ktd: opac_url/cgi-bin/koha/opac-detail.pl?biblionumber=336 2) Notice a new "Search holdings" input on top of the holdings table 3) Type something in the input, notice it filters rows 4) Clear the filter, notice all rows show Sponsored-by: NHS England Signed-off-by: David Nind --- .../bootstrap/en/modules/opac-detail.tt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 03acede5109..c9e9842df44 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -530,6 +530,7 @@ [% END # / IF serialcollection %] [% WRAPPER tab_panel tabname="holdings" %] + [% IF too_many_items %]

This record has many physical items ([% items_count | html %]). View all the physical items.

[% ELSIF ( itemloop.size ) %] @@ -2047,6 +2048,36 @@ $("#libraryInfoModalLabel, #libraryInfo").html(""); $("#libraryInfoLink").attr("href", ""); }); + + // Filter holdings rows: + const elsTr = $("#holdingst tbody tr"); + const elSearch = $("#holdings_search_input"); + const regEsc = (v) => v.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + + const filterRows = (evt) => { + const val = evt.currentTarget.value.trim(); // Trim from whitespaces + const reg = new RegExp(regEsc(val), "i"); // "i" = case insensitive + + $('#holdings_noresultsfound').remove(); + + $.each(elsTr, function(index, elTr) { + if(!reg.test(elTr.textContent)){ + $(elTr).addClass('d-none'); + }else{ + $(elTr).removeClass('d-none'); + } + }); + + if (val) { + const visibleCount = $(elsTr).filter(':visible').length; + const totalCount = $(elsTr).length; + $(elSearch).after(`Showing ${visibleCount} out of ${totalCount} holdings`); + } + }; + + $(elSearch).on('input',function(e){ + filterRows(e); + }); }); function showBsTab( container, panelid ){ -- 2.39.5