From 4c9040cd18c4da9e5e31d488a0ff357742d6d984 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 Signed-off-by: David Nind --- .../bootstrap/en/modules/opac-detail.tt | 23 +++++++++++++++++++ 1 file changed, 23 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 03acede510..2e3fef2a7b 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,28 @@ $("#libraryInfoModalLabel, #libraryInfo").html(""); $("#libraryInfoLink").attr("href", ""); }); + + // Search 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 + + $.each(elsTr, function(index, elTr) { + if(!reg.test(elTr.textContent)){ + $(elTr).addClass('d-none'); + }else{ + $(elTr).removeClass('d-none'); + } + }); + }; + + $('#holdings_search_input').on('input',function(e){ + filterRows(e); + }); }); function showBsTab( container, panelid ){ -- 2.39.2