Bug 32520: Use DefaultPatronSearchFields in patron_autocomplete
This patch updates js_includes.inc to set a new global js variable `defaultPatronSearchFields` with the content of the corresponding system preference. We then update the patron_autocomplete function to use this new global variable and iterate in the same way as koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc. NOTE: This changes the behaviour of the autocomplete from always searching using contains on surname or firstname or starts with on cardnumber to searching using 'contains' on any of the fields listed in the DefaultPatronSearchFields system preference of defaulting to 'firstname,middle_name,surname,othernames,cardnumber,userid'. Test plan 1. Ensure autocomplete still works everywhere 2. Confirm the system preference fields are being used. Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
a99d188e78
commit
6898f1f132
|
|
@ -71,6 +71,7 @@
|
|||
[% IF ( PatronAutoComplete ) %]
|
||||
<script>
|
||||
// PatronAutoComplete
|
||||
var defaultPatronSearchFields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]";
|
||||
var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]';
|
||||
var singleBranchMode = '[% singleBranchMode | html %]';
|
||||
var loggedInClass = "";
|
||||
|
|
|
|||
|
|
@ -13,20 +13,19 @@ function patron_autocomplete(node, options) {
|
|||
on_select_callback = options['on-select-callback'];
|
||||
}
|
||||
}
|
||||
const search_fields = ['me.surname', 'me.firstname', 'me.cardnumber'];
|
||||
return node.autocomplete({
|
||||
source: function( request, response ) {
|
||||
let subquery_and = [];
|
||||
request.term.split(/[\s,]+/)
|
||||
.filter(function(s){ return s.length })
|
||||
.forEach(function(pattern,i){
|
||||
subquery_and.push(
|
||||
[
|
||||
{'me.surname': {'like': '%' + pattern + '%'}},
|
||||
{'me.firstname': {'like': '%' + pattern + '%'}},
|
||||
{'me.cardnumber': {'like': pattern + '%'}},
|
||||
]
|
||||
);
|
||||
let subquery_or = [];
|
||||
defaultPatronSearchFields.split(',').forEach(function(field,i){
|
||||
subquery_or.push(
|
||||
{["me."+field]: {'like': '%' + pattern + '%'}}
|
||||
);
|
||||
});
|
||||
subquery_and.push(subquery_or);
|
||||
});
|
||||
let q = {"-and": subquery_and};
|
||||
let params = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue