Koha/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc
Martin Renvoize 6898f1f132
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>
2023-01-27 16:20:54 -03:00

90 lines
3 KiB
PHP

[% USE raw %]
[% USE Asset %]
[% USE AudioAlerts %]
[% USE Branches %]
[% USE To %]
[% USE Koha %]
[%# Prevent XFS attacks -%]
[% UNLESS popup %]
<script>
if (self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
}
</script>
[% END %]
[% Asset.js("lib/jquery/jquery-3.6.0.min.js") | $raw %]
[% Asset.js("lib/jquery/jquery-migrate-3.3.2.min.js") | $raw %]
[% Asset.js("lib/jquery/jquery-ui-1.13.1.min.js") | $raw %]
[% Asset.js("lib/shortcut/shortcut.js") | $raw %]
[% Asset.js("lib/js-cookie/js.cookie-2.2.1.min.js") | $raw %]
[% Asset.js("lib/jquery/plugins/jquery.highlight-3.js") | $raw %]
[% Asset.js("lib/bootstrap/bootstrap.min.js") | $raw %]
[% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %]
<!-- koha core js -->
[% Asset.js("js/staff-global.js") | $raw %]
[% INCLUDE 'js-date-format.inc' %]
[% INCLUDE 'js-patron-get-age.inc' %]
[% Asset.js("js/patron-autocomplete.js") | $raw %]
[% INCLUDE 'validator-strings.inc' %]
[% IF ( IntranetUserJS ) %]
<!-- js_includes.inc: IntranetUserJS -->
<script>
[% IntranetUserJS | $raw %]
</script>
<!-- / js_includes.inc: IntranetUserJS -->
[% END %]
<!-- js_includes.inc -->
[% IF ( Koha.Preference('virtualshelves') || Koha.Preference('intranetbookbag') ) %]
[% Asset.js("js/basket.js") | $raw %]
[% END %]
[% IF LocalCoverImages %]
[% Asset.js("js/localcovers.js") | $raw %]
[% END %]
[% IF Koha.Preference('AudioAlerts') || AudioAlertsPage %]
<script>
// AudioAlerts
var AUDIO_ALERT_PATH = '[% interface | html %]/[% theme | html %]/sound/';
var AUDIO_ALERTS = JSON.parse( "[% To.json(AudioAlerts.AudioAlerts) | $raw %]" );
$( document ).ready(function() {
if ( AUDIO_ALERTS ) {
for ( var k in AUDIO_ALERTS ) {
var alert = AUDIO_ALERTS[k];
if ( $( alert.selector ).length ) {
playSound( alert.sound );
break;
}
}
}
});
</script>
[% END %]
[% 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 = "";
$(document).ready(function(){
[% IF ( CAN_user_circulate_circulate_remaining_permissions ) %]
if ( $("#findborrower").length ) {
patron_autocomplete($("#findborrower"), { 'link-to': 'circ' });
}
[% END %]
if ( $("#searchmember").length ) {
patron_autocomplete($("#searchmember"), { 'link-to': 'patron' });
}
});
</script>
[% END %]
<!-- / js_includes.inc -->