Bug 34094: Use DefaultPatronSearchMethod consistently

This patch updates the patron search bar and pages to default search
method to that defined by DefaultPatronSearchMethod system preference.

Test plan
1) Prior to this patch confirm that regardless of what you set
   DefaultPatronSearchMethod to, the search in /members/member.pl,
   members/members-home.pl and the search from the patrons search top bar
   all default to 'contains'.
2) Apply the patch
3) Confirm that the system preference now affects the default option for
   match type upon page load.

Signed-off-by: Sam Lau <samalau@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2023-06-22 15:37:55 +01:00 committed by Tomas Cohen Arazi
parent e3803577ee
commit b804313c20
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
5 changed files with 20 additions and 20 deletions

View file

@ -150,8 +150,6 @@ my @failedreturns = $query->multi_param('failedreturn');
our %return_failed = ();
for (@failedreturns) { $return_failed{$_} = 1; }
my $searchtype = $query->param('searchtype') || q{contain};
my $branch = C4::Context->userenv->{'branch'};
for my $barcode ( @$barcodes ) {

View file

@ -4,6 +4,7 @@
[% USE Koha %]
[% PROCESS 'patronfields.inc' %]
[% IF CAN_user_borrowers_edit_borrowers %]
[%- SET searchtype = Koha.Preference('DefaultPatronSearchMethod') -%]
[% IF( bs_tab_active ) %]
<div id="patron_search" role="tabpanel" class="tab-pane active">
[% ELSE %]
@ -36,12 +37,12 @@
<div>
<label for="searchtype" class="control-label">Search type</label>
<select name="searchtype" id="searchtype" class="form-control">
[% IF searchtype == 'start_with' %]
<option value='start_with' selected='selected'>Starts with</option>
<option value='contain'>Contains</option>
[% IF searchtype == 'starts_with' %]
<option value='starts_with' selected='selected'>Starts with</option>
<option value='contains'>Contains</option>
[% ELSE %]
<option value='start_with'>Starts with</option>
<option value='contain' selected='selected'>Contains</option>
<option value='starts_with'>Starts with</option>
<option value='contains' selected='selected'>Contains</option>
[% END %]
</select>
</div>

View file

@ -20,7 +20,8 @@
[%# - branch: select library list %]
[%# - category: select patron category list %]
[%# - search_field: select patron field list %]
[%# - search_type: select 'contain' or 'start with' %]
[%# - search_type: select 'contains' or 'starts with' %]
[%- SET searchtype = Koha.Preference('DefaultPatronSearchMethod') -%]
[% BLOCK patron_search_filters %]
<form id="patron_search_form">
<fieldset class="brief">
@ -74,12 +75,12 @@
<li>
<label for="searchtype_filter">Search type:</label>
<select name="searchtype" id="searchtype_filter">
[% IF searchtype == "start_with" %]
<option value='start_with' selected="selected">Starts with</option>
<option value="contain">Contains</option>
[% IF searchtype == "starts_with" %]
<option value='starts_with' selected="selected">Starts with</option>
<option value="contains">Contains</option>
[% ELSE %]
<option value='start_with'>Starts with</option>
<option value="contain" selected="selected">Contains</option>
<option value='starts_with'>Starts with</option>
<option value="contains" selected="selected">Contains</option>
[% END %]
</select>
</li>
@ -339,7 +340,7 @@
}
let patterns = pattern.split(/[\s,]+/).filter(function(s){ return s.length });
let search_type = $("#searchtype_filter").val() || "contain";
let search_type = $("#searchtype_filter").val() || "contains";
let search_fields = $("#searchfieldstype_filter").val();
if ( !search_fields ) {
search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]";
@ -349,7 +350,7 @@
patterns.forEach(function(pattern,i){
let sub_or = [];
search_fields.split(',').forEach(function(attr,ii){
sub_or.push({["me."+attr]:{"like":(search_type == "contain" ? "%" : "" ) + pattern + "%"}});
sub_or.push({["me."+attr]:{"like":(search_type == "contains" ? "%" : "" ) + pattern + "%"}});
if ( attr == 'dateofbirth' ) {
try {
let d = $date_to_rfc3339(pattern);
@ -368,7 +369,7 @@
patterns.forEach(function(pattern,i){
let sub_or = [];
sub_or.push({
"extended_attributes.value": { "like": "%" + pattern + (search_type == "contain" ? "%" : "" )},
"extended_attributes.value": { "like": "%" + pattern + (search_type == "contains" ? "%" : "" )},
"extended_attributes.code": extended_attribute_types
});
subquery_and.push(sub_or);
@ -758,7 +759,7 @@
function update_search_description(){
var searched = $("#searchfieldstype_filter").find("option:selected").text();
if ( $("#search_patron_filter").val() ) {
if ( $("#searchtype_filter").val() == 'start_with' ) {
if ( $("#searchtype_filter").val() == 'starts_with' ) {
searched += _(" starting with ");
} else {
searched += _(" containing ");
@ -846,7 +847,7 @@
function clearFilters() {
$("#searchfieldstype_filter option:first").prop("selected", true);
$("#searchtype_filter option[value='contain']").prop("selected", true);
$("#searchtype_filter option[value='[% searchtype || 'contains' | html %]']").prop("selected", true);
$("#categorycode_filter option:first").prop("selected", true);
$("#branchcode_filter option:first").prop("selected", true);
$("#sort1_filter").val('').trigger("change");

View file

@ -9,6 +9,7 @@
[% SET libraries = Branches.all %]
[% SET categories = Categories.all.unblessed %]
[% SET columns = ['cardnumber', 'name-address', 'dateofbirth', 'branch', 'category', 'dateexpiry', 'checkouts', 'account_balance', 'borrowernotes', 'action'] %]
[% SET searchtype = Koha.Preference('DefaultPatronSearchMethod') %]
[% PROCESS 'patron-search.inc' %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Patrons[% IF ( searching ) %] &rsaquo; Search results[% END %] &rsaquo; Koha</title>
@ -282,7 +283,7 @@
$("searchfieldstype_filter").val("[% searchfieldstype | html %]");
[% END %]
[% IF searchtype %]
$("#searchtype_filter").val("[% searchtype | html %]");
$("#searchtype_filter option[value='[% searchtype | html %]']").prop("selected", true);
[% END %]
[% IF categorycode_filter %]
$("#categorycode_filter").val("[% categorycode_filter | html %]");

View file

@ -75,7 +75,6 @@ $template->param(
searchmember => $searchmember,
branchcode_filter => scalar $input->param('branchcode_filter'),
categorycode_filter => scalar $input->param('categorycode_filter'),
searchtype => scalar $input->param('searchtype') || 'contain',
searchfieldstype => $searchfieldstype,
PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
do_not_defer_loading => !$defer_loading,