From 3a691d4581ef68659661fb38b6c945ad8d4ba612 Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Tue, 23 Jul 2024 19:59:57 +0000 Subject: [PATCH] Bug 37442: Add customizable dropdown selections for the advanced search filters To test: 1) Apply patch, restart_all 2) Visit Tools->HTML customizations 3) Click 'New entry using text editor' 4) For 'Display location', select "StaffAdvancedSearchList" 5) Make the publication date today. 6) For the content, put some dropdown options... you can paste in this block for example: 7) Visit the Advanced search page 8) In the search dropdowns, notice that there are only the options that you provided (Author, Title, Barcode) 9) In the top search dropdown, select 'Title' and type in "the" 10) Press 'Search'. The search completes succesfully. Now press 'Edit this search' 11) You should be brought back to the 'Advanced search' page and the top dropdown should be selected as 'Title' and have "the" prefilled. 12) In the second search dropdown, select "Author" and type in "John" 13) Now press search. Once again press "Edit this search" and note the items are prefilled correctly. 14) Go back to Tools->HTML customizations and delete the 'StaffAdvancedSearchList' we initially created. 15) Back at the 'Advanced search' page, the dropdown options should be back to the default. Do some searches to ensure the searches work, and when editing, the options are correctly prefilled. Signed-off-by: Eric Garcia --- .../prog/en/includes/search_indexes.inc | 170 ++---------------- .../prog/en/modules/catalogue/advsearch.tt | 20 ++- .../en/modules/tools/additional-contents.tt | 2 +- 3 files changed, 32 insertions(+), 160 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/search_indexes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/search_indexes.inc index f668fdcc9b..c0dfc00947 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/search_indexes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/search_indexes.inc @@ -1,189 +1,45 @@ [% USE Koha %] +[% USE AdditionalContents %] +[% USE raw %] + [% IF refiner %] - [% ELSE %] - [% END %] - [% IF ms_kw %] - + [% SET StaffAdvancedSearchList = AdditionalContents.get( location => "StaffAdvancedSearchList", lang => lang, library => logged_in_user.branchcode ) -%] + [% IF StaffAdvancedSearchList.content %] + [% FOREACH block IN StaffAdvancedSearchList.content %] + [%- block.content | $raw -%] + [% END %] [% ELSE %] - [% END %] - [% IF ms_kwcommaphr %] - - [% ELSE %] - [% END %] - [% IF ms_au %] - - [% ELSE %] - [% END %] - [% IF ms_aucommaphr %] - - [% ELSE %] - [% END %] - [% IF ms_cpn %] - - [% ELSE %] - [% END %] - [% IF ms_cfn %] - - [% ELSE %] - [% END %] - [% IF ms_cpncommaphr %] - - [% ELSE %] - [% END %] - [% IF ms_cfncommaphr %] - - [% ELSE %] - [% END %] - [% IF ms_pn %] - - [% ELSE %] - [% END %] - [% IF ms_pncommaphr %] - - [% ELSE %] - [% END %] - [% IF ms_ti %] - - [% ELSE %] - [% END %] - [% IF ms_ticommaphr %] - - [% ELSE %] - [% END %] - [% IF ms_se %] - - [% ELSE %] - [% END %] - [% IF ms_su %] - - [% ELSE %] - [% END %] - [% IF ms_sucommaphr %] - - [% ELSE %] - [% END %] - [% IF ( expanded_options ) %] - [% IF ms_sudashbr %] - - [% ELSE %] - - [% END %] - [% IF ms_sudashna %] - - [% ELSE %] - - [% END %] - [% IF ms_sudashrl %] - - [% ELSE %] - - [% END %] - [% END %] - [% IF ms_bc %] - - [% ELSE %] - [% END %] - [% IF ms_locationcommawrdl %] - - [% ELSE %] - [% END %] - [% IF ( Koha.Preference('IntranetNumbersPreferPhrase') ) %] - [% IF ms_identcommaphr %] - - [% ELSE %] - - [% END %] - [% ELSE %] - [% IF ms_ident %] - - [% ELSE %] - - [% END %] - [% END %] - [% IF ms_nb %] - - [% ELSE %] + - [% END %] - [% IF ms_ns %] - - [% ELSE %] - [% END %] - [% IF ( Koha.Preference('IntranetNumbersPreferPhrase') ) %] - [% IF ms_callnumcommaphr %] - - [% ELSE %] - - [% END %] - [% ELSE %] - [% IF ms_callnum %] - - [% ELSE %] - - [% END %] - [% END %] - [% IF ms_lncommartrn %] - - [% ELSE %] + - [% END %] - [% IF ms_nt %] - - [% ELSE %] - [% END %] - [% IF (marcflavour != 'UNIMARC' ) %] - [% IF ms_curriculum %] - - [% ELSE %] - - [% END %] - [% END %] - [% IF ms_pb %] - - [% ELSE %] + - [% END %] - [% IF ms_pl %] - - [% ELSE %] - [% END %] - - [%# Use non-normalized st-year instead of st-numeric, %] - [%# since pubdate can include 'u' to signify unknown %] - [%# dates. See "Legal Characters" at: %] - [%# http://www.loc.gov/marc/bibliographic/bd008a.html %] - [%# This search is also for date ranges due to the %] - [%# special Zebra r=r CCL mapping for 'yr' %] - [% IF ms_yrcommastdashyear %] - - [% ELSE %] - [% END %] - [% IF ms_acqdatecommastdashdatedashnormalized %] - - [% ELSE %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt index 0d0ec4ce3f..3a4bfe55f2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -174,8 +174,8 @@ [% ELSE %]
[% END %] - [% SET preselect = 'ms_' _ indexes.${loop.index}.replace(',','comma') %] - [% INCLUDE 'search_indexes.inc' ${preselect} = 1 %] + [% SET preselect = indexes.${loop.index} %] + [% INCLUDE 'search_indexes.inc' ${preselect} = preselect index = loop.index %] [% IF ( expanded_options ) %] [% IF ( loop.last ) %] @@ -516,6 +516,22 @@ }); [% END %] + function preselectOptions() { + const dropdowns = document.querySelectorAll('.advsearch'); + dropdowns.forEach(dropdown => { + const preselectValue = dropdown.dataset.preselect; + if (preselectValue) { + const options = dropdown.querySelectorAll('option'); + for (let i = 0; i < options.length; i++) { + if (options[i].value === preselectValue) { + options[i].selected = true; + break; + } + } + } + }); + } + preselectOptions(); }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt index bdf8a0a089..470ae82a2c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt @@ -536,7 +536,7 @@ [% END %] [% END %] - [% SET staff_available_options = [ 'IntranetmainUserblock', 'StaffAcquisitionsHome', 'StaffAuthoritiesHome', 'StaffCataloguingHome', 'StaffListsHome', 'StaffPatronsHome', 'StaffPOSHome', 'StaffSerialsHome' ] %] + [% SET staff_available_options = [ 'IntranetmainUserblock', 'StaffAcquisitionsHome', 'StaffAdvancedSearchList', 'StaffAuthoritiesHome', 'StaffCataloguingHome', 'StaffListsHome', 'StaffPatronsHome', 'StaffPOSHome', 'StaffSerialsHome' ] %] [% FOREACH l IN staff_available_options.sort %] [% IF l == location %] -- 2.30.2