Lines 7-17
Link Here
|
7 |
[% USE Asset %] |
7 |
[% USE Asset %] |
8 |
[% USE To %] |
8 |
[% USE To %] |
9 |
|
9 |
|
|
|
10 |
[% SET search_results_block_id = 'searchresults' %] |
11 |
|
10 |
[%# Display a simple form %] |
12 |
[%# Display a simple form %] |
11 |
[% BLOCK patron_search_filters_simple %] |
13 |
[% BLOCK patron_search_filters_simple %] |
12 |
<form id="patron_search_form"> |
14 |
<form class="patron_search_form"> |
13 |
<div class="hint">Enter patron card number or partial name:</div> |
15 |
<div class="hint">Enter patron card number or partial name:</div> |
14 |
<input type="text" size="40" id="search_patron_filter" class="focus" autocomplete="off" /> |
16 |
<input type="text" size="40" class="search_patron_filter" class="focus" autocomplete="off" /> |
15 |
<input type="submit" class="btn btn-primary" value="Search" /> |
17 |
<input type="submit" class="btn btn-primary" value="Search" /> |
16 |
</form> |
18 |
</form> |
17 |
[% END %] |
19 |
[% END %] |
Lines 27-39
Link Here
|
27 |
[%# - search_type: select 'contains' or 'starts with' %] |
29 |
[%# - search_type: select 'contains' or 'starts with' %] |
28 |
[%- searchtype = searchtype || Koha.Preference('DefaultPatronSearchMethod') -%] |
30 |
[%- searchtype = searchtype || Koha.Preference('DefaultPatronSearchMethod') -%] |
29 |
[% BLOCK patron_search_filters %] |
31 |
[% BLOCK patron_search_filters %] |
30 |
<form id="patron_search_form"> |
32 |
|
|
|
33 |
<form class="patron_search_form"> |
31 |
<fieldset class="brief"> |
34 |
<fieldset class="brief"> |
32 |
<h3>Search for patron</h3> |
35 |
<h3>Search for patron</h3> |
33 |
<ol> |
36 |
<ol> |
34 |
<li> |
37 |
<li> |
35 |
<label for="search_patron_filter">Search:</label> |
38 |
<label for="search_patron_filter">Search:</label> |
36 |
<input type="text" id="search_patron_filter" value="[% search_filter | html %]" class="focus" /> |
39 |
<input type="text" class="search_patron_filter" value="[% search_filter | html %]" class="focus" /> |
37 |
</li> |
40 |
</li> |
38 |
|
41 |
|
39 |
[% FOR f IN filters %] |
42 |
[% FOR f IN filters %] |
Lines 41-47
Link Here
|
41 |
[% CASE 'branch' %] |
44 |
[% CASE 'branch' %] |
42 |
<li> |
45 |
<li> |
43 |
<label for="branchcode_filter">Library:</label> |
46 |
<label for="branchcode_filter">Library:</label> |
44 |
<select id="branchcode_filter"> |
47 |
<select class="branchcode_filter"> |
45 |
[% SET libraries = Branches.all( only_from_group => 1 ) %] |
48 |
[% SET libraries = Branches.all( only_from_group => 1 ) %] |
46 |
[% IF libraries.size != 1 %] |
49 |
[% IF libraries.size != 1 %] |
47 |
<option value="">Any</option> |
50 |
<option value="">Any</option> |
Lines 54-60
Link Here
|
54 |
[% CASE 'category' %] |
57 |
[% CASE 'category' %] |
55 |
<li> |
58 |
<li> |
56 |
<label for="categorycode_filter">Category:</label> |
59 |
<label for="categorycode_filter">Category:</label> |
57 |
<select id="categorycode_filter"> |
60 |
<select class="categorycode_filter"> |
58 |
<option value="">Any</option> |
61 |
<option value="">Any</option> |
59 |
[% FOREACH category IN Categories.limited.unblessed %] |
62 |
[% FOREACH category IN Categories.limited.unblessed %] |
60 |
<option value="[% category.categorycode | html %]">[% category.description | html %]</option> |
63 |
<option value="[% category.categorycode | html %]">[% category.description | html %]</option> |
Lines 64-75
Link Here
|
64 |
[% CASE 'sort1' %] |
67 |
[% CASE 'sort1' %] |
65 |
<li> |
68 |
<li> |
66 |
<label for="sort1_filter">Sort 1:</label> |
69 |
<label for="sort1_filter">Sort 1:</label> |
67 |
[% PROCESS 'av-build-dropbox.inc' name="sort1_filter", category="Bsort1", empty=1, size = 20 %] |
70 |
[% PROCESS 'av-build-dropbox.inc' no_id => 1, name="sort1_filter", category="Bsort1", empty=1, size = 20 %] |
68 |
</li> |
71 |
</li> |
69 |
[% CASE 'sort2' %] |
72 |
[% CASE 'sort2' %] |
70 |
<li> |
73 |
<li> |
71 |
<label for="sort2_filter">Sort 2:</label> |
74 |
<label for="sort2_filter">Sort 2:</label> |
72 |
[% PROCESS 'av-build-dropbox.inc' name="sort2_filter", category="Bsort2", empty=1, size = 20 %] |
75 |
[% PROCESS 'av-build-dropbox.inc' no_id => 1, name="sort2_filter", category="Bsort2", empty=1, size = 20 %] |
73 |
</li> |
76 |
</li> |
74 |
[% CASE 'search_field' %] |
77 |
[% CASE 'search_field' %] |
75 |
<li> |
78 |
<li> |
Lines 78-84
Link Here
|
78 |
[% CASE 'search_type' %] |
81 |
[% CASE 'search_type' %] |
79 |
<li> |
82 |
<li> |
80 |
<label for="searchtype_filter">Search type:</label> |
83 |
<label for="searchtype_filter">Search type:</label> |
81 |
<select name="searchtype" id="searchtype_filter"> |
84 |
<select name="searchtype" class="searchtype_filter"> |
82 |
[% IF searchtype == "starts_with" %] |
85 |
[% IF searchtype == "starts_with" %] |
83 |
<option value='starts_with' selected="selected">Starts with</option> |
86 |
<option value='starts_with' selected="selected">Starts with</option> |
84 |
<option value="contains">Contains</option> |
87 |
<option value="contains">Contains</option> |
Lines 93-99
Link Here
|
93 |
</ol> |
96 |
</ol> |
94 |
<fieldset class="action"> |
97 |
<fieldset class="action"> |
95 |
<input type="submit" class="btn btn-primary" value="Search" /> |
98 |
<input type="submit" class="btn btn-primary" value="Search" /> |
96 |
<input type="button" value="Clear" id="clear_search" /> |
99 |
<input type="button" value="Clear" class="clear_search" /> |
97 |
</fieldset> |
100 |
</fieldset> |
98 |
</fieldset> |
101 |
</fieldset> |
99 |
</form> |
102 |
</form> |
Lines 135-148
Link Here
|
135 |
[% END %] |
138 |
[% END %] |
136 |
</div> |
139 |
</div> |
137 |
|
140 |
|
138 |
<h3 style="display: none;">Patrons found for: <span id="searchpattern"></span></h3> |
141 |
<h3 style="display: none;">Patrons found for: <span class="searchpattern"></span></h3> |
139 |
|
142 |
|
140 |
<div id="[% table_id | html %]_search_results" style="display:none;"> |
143 |
<div id="[% table_id | html %]_search_results" style="display:none;"> |
141 |
|
144 |
|
142 |
<div id="info" class="dialog message" style="display: none;"></div> |
145 |
<div class="info" class="dialog message" style="display: none;"></div> |
143 |
<div id="error" class="dialog alert" style="display: none;"></div> |
146 |
<div class="error" class="dialog alert" style="display: none;"></div> |
144 |
|
147 |
|
145 |
<input type="hidden" id="firstletter_filter" value="" /> |
148 |
<input type="hidden" class="firstletter_filter" value="" /> |
146 |
[% IF open_on_row_click %] |
149 |
[% IF open_on_row_click %] |
147 |
<table id="[% table_id | html %]" class="selections-table"> |
150 |
<table id="[% table_id | html %]" class="selections-table"> |
148 |
[% ELSE %] |
151 |
[% ELSE %] |
Lines 203-208
Link Here
|
203 |
[%# sticky_header and sticky_to: If we need a sticky header %] |
206 |
[%# sticky_header and sticky_to: If we need a sticky header %] |
204 |
[%# callback: name of the JS function that will be called when a patron is selected. Only work with action=select %] |
207 |
[%# callback: name of the JS function that will be called when a patron is selected. Only work with action=select %] |
205 |
[%# display_search_description: boolean, default off. Display the description of the search %] |
208 |
[%# display_search_description: boolean, default off. Display the description of the search %] |
|
|
209 |
[%# adjust_history: boolean, default off. Change the current url when a first letter is selected %] |
206 |
[% BLOCK patron_search_js %] |
210 |
[% BLOCK patron_search_js %] |
207 |
|
211 |
|
208 |
[% IF redirect_if_one_result && !redirect_url %] |
212 |
[% IF redirect_if_one_result && !redirect_url %] |
Lines 212-244
Link Here
|
212 |
<script> |
216 |
<script> |
213 |
[% SET libraries = Branches.all %] |
217 |
[% SET libraries = Branches.all %] |
214 |
[% SET categories = Categories.limited.unblessed %] |
218 |
[% SET categories = Categories.limited.unblessed %] |
215 |
let categories = [% To.json(categories) | $raw %].map(e => { |
219 |
var categories = [% To.json(categories) | $raw %].map(e => { |
216 |
e['_id'] = e.categorycode.toLowerCase(); |
220 |
e['_id'] = e.categorycode.toLowerCase(); |
217 |
e['_str'] = e.description; |
221 |
e['_str'] = e.description; |
218 |
return e; |
222 |
return e; |
219 |
}); |
223 |
}); |
220 |
let categories_map = categories.reduce((map, e) => { |
224 |
var categories_map = categories.reduce((map, e) => { |
221 |
map[e._id] = e; |
225 |
map[e._id] = e; |
222 |
return map; |
226 |
return map; |
223 |
}, {}); |
227 |
}, {}); |
224 |
let libraries = [% To.json(libraries) | $raw %].map(e => { |
228 |
var libraries = [% To.json(libraries) | $raw %].map(e => { |
225 |
e['_id'] = e.branchcode; |
229 |
e['_id'] = e.branchcode; |
226 |
e['_str'] = e.branchname; |
230 |
e['_str'] = e.branchname; |
227 |
return e; |
231 |
return e; |
228 |
}); |
232 |
}); |
229 |
let libraries_map = libraries.reduce((map, e) => { |
233 |
var libraries_map = libraries.reduce((map, e) => { |
230 |
map[e._id] = e; |
234 |
map[e._id] = e; |
231 |
return map; |
235 |
return map; |
232 |
}, {}); |
236 |
}, {}); |
233 |
|
237 |
|
234 |
[% IF Koha.Preference('ExtendedPatronAttributes') %] |
238 |
[% IF Koha.Preference('ExtendedPatronAttributes') %] |
235 |
[% SET extended_attribute_types = [ ExtendedAttributeTypes.codes( staff_searchable => 1, searched_by_default => 1 ) ] %] |
239 |
[% SET extended_attribute_types = [ ExtendedAttributeTypes.codes( staff_searchable => 1, searched_by_default => 1 ) ] %] |
236 |
let extended_attribute_types = [% To.json(extended_attribute_types || []) | $raw %]; |
240 |
var extended_attribute_types = [% To.json(extended_attribute_types || []) | $raw %]; |
237 |
[% END %] |
241 |
[% END %] |
238 |
|
242 |
|
239 |
$(document).ready(function() { |
243 |
$(document).ready(function() { |
240 |
$('select#sort1_filter').select2({allowClear:true}); |
244 |
$('select[name="sort1_filter"]').select2({allowClear:true}); |
241 |
$('select#sort2_filter').select2({allowClear:true}); |
245 |
$('select[name="sort2_filter"]').select2({allowClear:true}); |
242 |
}); |
246 |
}); |
243 |
</script> |
247 |
</script> |
244 |
|
248 |
|
Lines 251-260
Link Here
|
251 |
[% END %] |
255 |
[% END %] |
252 |
|
256 |
|
253 |
<script> |
257 |
<script> |
254 |
var first_draw = 0; |
258 |
{ |
|
|
259 |
|
260 |
function get_patron_search_form(){ |
261 |
let parent_block = $("#[% search_results_block_id | html %]"); |
262 |
let patron_search_form = parent_block.siblings(".patron_search_form"); |
263 |
if ( !patron_search_form.length ) patron_search_form = $(".patron_search_form"); |
264 |
return patron_search_form; |
265 |
} |
266 |
let first_draw = 0; |
255 |
let patrons_table; |
267 |
let patrons_table; |
256 |
var Sticky; |
268 |
let Sticky; |
257 |
var singleBranchMode = '[% singleBranchMode | html %]'; |
269 |
let singleBranchMode = '[% singleBranchMode | html %]'; |
258 |
let logged_in_library_id = "[% Branches.GetLoggedInBranchcode | html %]"; |
270 |
let logged_in_library_id = "[% Branches.GetLoggedInBranchcode | html %]"; |
259 |
[% IF do_not_defer_loading %] |
271 |
[% IF do_not_defer_loading %] |
260 |
let defer_loading = 0; |
272 |
let defer_loading = 0; |
Lines 262-271
Link Here
|
262 |
let defer_loading = 1; |
274 |
let defer_loading = 1; |
263 |
[% END %] |
275 |
[% END %] |
264 |
|
276 |
|
265 |
/* popstate event triggered by forward and back button. Need to refresh search */ |
277 |
[% IF adjust_history %] |
266 |
window.addEventListener('popstate', (event) => { |
278 |
/* popstate event triggered by forward and back button. Need to refresh search */ |
267 |
getSearchByLocation( false ); |
279 |
window.addEventListener('popstate', (event) => { |
268 |
}); |
280 |
getSearchByLocation( false ); |
|
|
281 |
}); |
282 |
[% END %] |
269 |
|
283 |
|
270 |
[% SWITCH filter %] |
284 |
[% SWITCH filter %] |
271 |
[% CASE 'suggestions_managers' %] |
285 |
[% CASE 'suggestions_managers' %] |
Lines 283-293
Link Here
|
283 |
[% END %] |
297 |
[% END %] |
284 |
$(document).ready(function(){ |
298 |
$(document).ready(function(){ |
285 |
|
299 |
|
286 |
$("#info").hide(); |
300 |
let parent_block = $("#[% search_results_block_id | html %]"); |
287 |
$("#error").hide(); |
301 |
let patron_search_form = get_patron_search_form(); |
|
|
302 |
|
303 |
parent_block.find(".info").hide(); |
304 |
parent_block.find(".error").hide(); |
288 |
|
305 |
|
289 |
// Build the aLengthMenu |
306 |
// Build the aLengthMenu |
290 |
var aLengthMenu = [ |
307 |
let aLengthMenu = [ |
291 |
[% Koha.Preference('PatronsPerPage') | html %], 10, 20, 50, 100, -1 |
308 |
[% Koha.Preference('PatronsPerPage') | html %], 10, 20, 50, 100, -1 |
292 |
]; |
309 |
]; |
293 |
jQuery.unique(aLengthMenu); |
310 |
jQuery.unique(aLengthMenu); |
Lines 300-306
Link Here
|
300 |
} |
317 |
} |
301 |
return parseInt(a) < parseInt(b) ? -1 : 1;} |
318 |
return parseInt(a) < parseInt(b) ? -1 : 1;} |
302 |
); |
319 |
); |
303 |
var aLengthMenuLabel = []; |
320 |
let aLengthMenuLabel = []; |
304 |
$(aLengthMenu).each(function(){ |
321 |
$(aLengthMenu).each(function(){ |
305 |
if ( this == -1 ) { |
322 |
if ( this == -1 ) { |
306 |
// Label for -1 is "All" |
323 |
// Label for -1 is "All" |
Lines 312-327
Link Here
|
312 |
|
329 |
|
313 |
let additional_filters = { |
330 |
let additional_filters = { |
314 |
surname: function(){ |
331 |
surname: function(){ |
315 |
let start_with = $("#firstletter_filter").val() |
332 |
let start_with = parent_block.find(".firstletter_filter").val() |
316 |
if (!start_with) return ""; |
333 |
if (!start_with) return ""; |
317 |
return { "like": start_with + "%" } |
334 |
return { "like": start_with + "%" } |
318 |
}, |
335 |
}, |
319 |
"-and": function(){ |
336 |
"-and": function(){ |
320 |
let filters = []; |
337 |
let filters = []; |
321 |
|
338 |
|
322 |
let search_type = $("#searchtype_filter").val(); |
339 |
let search_type = patron_search_form.find(".searchtype_filter").val(); |
323 |
let search_fields = $("#searchfieldstype_filter").val() || "standard"; |
340 |
let search_fields = patron_search_form.find(".searchfieldstype_filter").val() || "standard"; |
324 |
let pattern = $("#search_patron_filter").val(); |
341 |
let pattern = patron_search_form.find(".search_patron_filter").val(); |
325 |
|
342 |
|
326 |
filters = buildPatronSearchQuery( |
343 |
filters = buildPatronSearchQuery( |
327 |
pattern, |
344 |
pattern, |
Lines 332-344
Link Here
|
332 |
} |
349 |
} |
333 |
); |
350 |
); |
334 |
|
351 |
|
335 |
let f_sort1 = $("#sort1_filter").val(); |
352 |
let f_sort1 = patron_search_form.find("select[name='sort1_filter']").val(); |
336 |
if ( f_sort1 ) { |
353 |
if ( f_sort1 ) { |
337 |
filters.push({ |
354 |
filters.push({ |
338 |
"me.sort1": f_sort1 |
355 |
"me.sort1": f_sort1 |
339 |
}); |
356 |
}); |
340 |
} |
357 |
} |
341 |
let f_sort2 = $("#sort2_filter").val(); |
358 |
let f_sort2 = patron_search_form.find("select[name='sort2_filter']").val(); |
342 |
if ( f_sort2 ) { |
359 |
if ( f_sort2 ) { |
343 |
filters.push({ |
360 |
filters.push({ |
344 |
"me.sort2": f_sort2 |
361 |
"me.sort2": f_sort2 |
Lines 410-416
Link Here
|
410 |
"searchable": false, |
427 |
"searchable": false, |
411 |
"orderable": false, |
428 |
"orderable": false, |
412 |
"render": function( data, type, row, meta ) { |
429 |
"render": function( data, type, row, meta ) { |
413 |
return "<label for='check" + data + "' class='content_hidden'>" + _("Select patron") + "</label><input type='checkbox' id='check" + data + "' class='selection' name='borrowernumber' value='" + data + "' />"; |
430 |
return "<label for='check" + data + "' class='content_hidden'>" + _("Select patron") + "</label><input type='checkbox' class='check" + data + "' class='selection' name='borrowernumber' value='" + data + "' />"; |
414 |
} |
431 |
} |
415 |
} |
432 |
} |
416 |
[% CASE 'cardnumber' %] |
433 |
[% CASE 'cardnumber' %] |
Lines 608-614
Link Here
|
608 |
[% END %] |
625 |
[% END %] |
609 |
|
626 |
|
610 |
let patron_str = JSON.stringify(row); |
627 |
let patron_str = JSON.stringify(row); |
611 |
let input_node = $('<input type="hidden" id="borrower_data' + patron_id + '" name="borrower_data'+ patron_id + '"/>'); |
628 |
let input_node = $('<input type="hidden" name="borrower_data'+ patron_id + '"/>'); |
612 |
$(input_node).val(patron_str); |
629 |
$(input_node).val(patron_str); |
613 |
action_node += $(input_node).prop('outerHTML'); |
630 |
action_node += $(input_node).prop('outerHTML'); |
614 |
|
631 |
|
Lines 639-665
Link Here
|
639 |
[% END %] |
656 |
[% END %] |
640 |
}, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters); |
657 |
}, typeof table_settings !== 'undefined' ? table_settings : null, 1, additional_filters); |
641 |
|
658 |
|
642 |
$("#patron_search_form").on('submit', filter); |
659 |
patron_search_form.on('submit', filter); |
643 |
$("#patron_search_form").on('submit', update_search_type); |
660 |
patron_search_form.on('submit', update_search_type); |
|
|
661 |
|
644 |
$(".filterByLetter").on("click",function(e){ |
662 |
$(".filterByLetter").on("click",function(e){ |
645 |
e.preventDefault(); |
663 |
e.preventDefault(); |
646 |
filterByFirstLetterSurname($(this).text(), true); |
664 |
filterByFirstLetterSurname($(this).text(), true); |
647 |
}); |
665 |
}); |
648 |
$("body").on("click",".add_user",function(e){ |
666 |
patrons_table.on("click",".add_user",function(e){ |
649 |
e.preventDefault(); |
667 |
e.preventDefault(); |
650 |
var borrowernumber = $(this).data("borrowernumber"); |
668 |
var borrowernumber = $(this).data("borrowernumber"); |
651 |
var borrower_data = JSON.parse($("#borrower_data"+borrowernumber).val()); |
669 |
var borrower_data = JSON.parse(patrons_table.find("input[name='borrower_data"+borrowernumber+"']").val()); |
652 |
modal_add_user( borrowernumber, borrower_data.firstname + " " + borrower_data.surname ); |
670 |
modal_add_user( borrowernumber, borrower_data.firstname + " " + borrower_data.surname ); |
653 |
}); |
671 |
}); |
654 |
$("body").on("click",".select_user",function(e){ |
672 |
patrons_table.on("click",".select_user",function(e){ |
655 |
e.preventDefault(); |
673 |
e.preventDefault(); |
656 |
var borrowernumber = $(this).data("borrowernumber"); |
674 |
var borrowernumber = $(this).data("borrowernumber"); |
657 |
var borrower_data = JSON.parse($("#borrower_data"+borrowernumber).val()); |
675 |
var borrower_data = JSON.parse(patrons_table.find("input[name='borrower_data"+borrowernumber+"']").val()); |
658 |
modal_select_user( borrowernumber, borrower_data ); |
676 |
modal_select_user( borrowernumber, borrower_data ); |
659 |
$(this).closest(".modal").modal('hide'); |
677 |
$(this).closest(".modal").modal('hide'); |
660 |
}); |
678 |
}); |
661 |
|
679 |
|
662 |
$("body").on("click",".patron_preview", function( e ){ |
680 |
patrons_table.on("click",".patron_preview", function( e ){ |
663 |
e.preventDefault(); |
681 |
e.preventDefault(); |
664 |
var borrowernumber = $(this).data("borrowernumber"); |
682 |
var borrowernumber = $(this).data("borrowernumber"); |
665 |
var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber; |
683 |
var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber; |
Lines 675-756
Link Here
|
675 |
$("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading"); |
693 |
$("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading"); |
676 |
}); |
694 |
}); |
677 |
|
695 |
|
678 |
$("#clear_search").on("click",function(e){ |
696 |
patron_search_form.find(".clear_search").on("click",function(e){ |
679 |
e.preventDefault(); |
697 |
e.preventDefault(); |
680 |
clearFilters(); |
698 |
clearFilters(); |
681 |
$("#searchpattern").parent().hide(); |
699 |
patron_search_form.find(".searchpattern").parent().hide(); |
682 |
}); |
700 |
}); |
683 |
|
701 |
|
684 |
if ( !defer_loading ) { |
702 |
if ( !defer_loading ) { |
685 |
$("#patron_search_form").submit(); |
703 |
patron_search_form.submit(); |
686 |
} |
704 |
} |
687 |
|
705 |
|
688 |
/* Initial page load does not trigger the popstate event, so we explicitly call this */ |
706 |
[% IF adjust_history %] |
689 |
getSearchByLocation( false ); |
707 |
/* Initial page load does not trigger the popstate event, so we explicitly call this */ |
690 |
|
708 |
getSearchByLocation( false ); |
|
|
709 |
[% END %] |
691 |
}); |
710 |
}); |
692 |
|
711 |
|
693 |
function getSearchByLocation( setstate ){ |
712 |
[% IF adjust_history %] |
694 |
/* Check to see if the URL contains a search parameter */ |
713 |
function getSearchByLocation( setstate ){ |
695 |
if( location.search != ""){ |
714 |
/* Check to see if the URL contains a search parameter */ |
696 |
var params = new URLSearchParams( location.search ); |
715 |
if( location.search != ""){ |
697 |
var firstletter = params.get("firstletter"); |
716 |
var params = new URLSearchParams( location.search ); |
698 |
/* Check to see if search is a first letter param */ |
717 |
var firstletter = params.get("firstletter"); |
699 |
if( firstletter ){ |
718 |
/* Check to see if search is a first letter param */ |
700 |
/* Trigger function to return search results by letter */ |
719 |
if( firstletter ){ |
701 |
filterByFirstLetterSurname( firstletter, setstate ); |
720 |
/* Trigger function to return search results by letter */ |
|
|
721 |
filterByFirstLetterSurname( firstletter, setstate ); |
722 |
} |
702 |
} |
723 |
} |
703 |
} |
724 |
} |
704 |
} |
725 |
[% END %] |
705 |
|
726 |
|
706 |
function update_search_type(){ |
727 |
function update_search_type(){ |
707 |
$("#searchtype").val($("#searchtype_filter").val()); |
728 |
$("#searchtype").val($("#searchtype_filter").val()); |
708 |
} |
729 |
} |
709 |
|
730 |
|
710 |
function update_search_description(){ |
731 |
function update_search_description(){ |
711 |
var searched = $("#searchfieldstype_filter").find("option:selected").text(); |
732 |
let parent_block = $("#[% search_results_block_id | html %]"); |
712 |
if ( $("#search_patron_filter").val() ) { |
733 |
let patron_search_form = get_patron_search_form(); |
713 |
if ( $("#searchtype_filter").val() == 'starts_with' ) { |
734 |
var searched = patron_search_form.find(".searchfieldstype_filter").find("option:selected").text(); |
|
|
735 |
let pattern = patron_search_form.find(".search_patron_filter").val(); |
736 |
if ( pattern ) { |
737 |
if ( patron_search_form.find(".searchtype_filter").val() == 'starts_with' ) { |
714 |
searched += _(" starting with "); |
738 |
searched += _(" starting with "); |
715 |
} else { |
739 |
} else { |
716 |
searched += _(" containing "); |
740 |
searched += _(" containing "); |
717 |
} |
741 |
} |
718 |
searched += "'" + $("#search_patron_filter").val() + "'"; |
742 |
searched += "'" + pattern + "'"; |
719 |
} |
743 |
} |
720 |
if ( $("#firstletter_filter").val() ) { |
744 |
let firstletter_filter = parent_block.find(".firstletter_filter").val(); |
721 |
searched += _(" begins with ") + "'" + $("#firstletter_filter").val() +"'"; |
745 |
if ( firstletter_filter ) { |
|
|
746 |
searched += _(" begins with ") + "'" + firstletter_filter +"'"; |
722 |
} |
747 |
} |
723 |
if ( $("#categorycode_filter").val() ) { |
748 |
|
724 |
searched += _(" with category ") + "'" + $("#categorycode_filter").find("option:selected").text() + "'"; |
749 |
if ( patron_search_form.find(".categorycode_filter").val() ) { |
|
|
750 |
searched += _(" with category ") + "'" + patron_search_form.find(".categorycode_filter option:selected").text() + "'"; |
725 |
} |
751 |
} |
726 |
if ( $("#branchcode_filter").val() ) { |
752 |
if ( patron_search_form.find(".branchcode_filter").val() ) { |
727 |
searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text(); |
753 |
searched += _(" in library ") + patron_search_form.find(".branchcode_filter option:selected").text(); |
728 |
} |
754 |
} |
729 |
if ( $("#sort1_filter").val() ) { |
755 |
if ( patron_search_form.find("select[name='sort1_filter']").val() ) { |
730 |
searched += _(" with sort1 ") |
756 |
searched += _(" with sort1 ") |
731 |
if ( $("select#sort1_filter") ) { |
757 |
if ( patron_search_form.find("select[name='sort1_filter']") ) { |
732 |
searched += $("select#sort1_filter").find("option:selected").text(); |
758 |
searched += patron_search_form.find("select[name='sort1_filter'] option:selected").text(); |
733 |
} |
759 |
} |
734 |
else { |
760 |
else { |
735 |
searched += $("#sort1_filter").val(); |
761 |
searched += paron_search_form.find("select[name='sort1_filter']").val(); |
736 |
} |
762 |
} |
737 |
} |
763 |
} |
738 |
if ( $("#sort2_filter").val() ) { |
764 |
if ( patron_search_form.find("select[name='sort2_filter']").val() ) { |
739 |
searched += _(" with sort2 "); |
765 |
searched += _(" with sort2 ") |
740 |
if ( $("select#sort2_filter") ) { |
766 |
if ( patron_search_form.find("select[name='sort2_filter']") ) { |
741 |
searched += $("select#sort2_filter").find("option:selected").text(); |
767 |
searched += patron_search_form.find("select[name='sort2_filter'] option:selected").text(); |
742 |
} |
768 |
} |
743 |
else { |
769 |
else { |
744 |
searched += $("#sort2_filter").val(); |
770 |
searched += paron_search_form.find("select[name='sort2_filter']").val(); |
745 |
} |
771 |
} |
746 |
} |
772 |
} |
747 |
$("#searchpattern").text(searched); |
773 |
patron_search_form.find(".searchpattern").text(searched); |
748 |
$("#searchpattern").parent().show(); |
774 |
patron_search_form.find(".searchpattern").parent().show(); |
749 |
} |
775 |
} |
750 |
|
776 |
|
751 |
function filter() { |
777 |
function filter() { |
|
|
778 |
let parent_block = $("#[% search_results_block_id | html %]"); |
779 |
let patron_search_form = get_patron_search_form(); |
752 |
[% IF redirect_if_attribute_equal %] |
780 |
[% IF redirect_if_attribute_equal %] |
753 |
let filter = $("#search_patron_filter").val(); |
781 |
let filter = patron_search_form.find(".search_patron_filter").val(); |
754 |
if ( filter ) { |
782 |
if ( filter ) { |
755 |
$.ajax({ |
783 |
$.ajax({ |
756 |
data: { cardnumber: filter, _match: 'exact' }, |
784 |
data: { cardnumber: filter, _match: 'exact' }, |
Lines 771-788
Link Here
|
771 |
}); |
799 |
}); |
772 |
} |
800 |
} |
773 |
[% END %] |
801 |
[% END %] |
774 |
$("#firstletter_filter").val(''); |
802 |
parent_block.find(".firstletter_filter").val(''); |
775 |
$("#[% table_id | html %]_search_results").show(); |
803 |
$("#[% table_id | html %]_search_results").show(); |
776 |
|
804 |
|
777 |
let table_dt = patrons_table.DataTable(); |
805 |
let table_dt = patrons_table.DataTable(); |
778 |
[% FOR c IN columns %] |
806 |
[% FOR c IN columns %] |
779 |
[% SWITCH c %] |
807 |
[% SWITCH c %] |
780 |
[% CASE 'branch' %] |
808 |
[% CASE 'branch' %] |
781 |
library_id = $("#branchcode_filter").val() || ""; |
809 |
let library_id = patron_search_form.find(".branchcode_filter").val() || ""; |
782 |
patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id); |
810 |
patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id); |
783 |
table_dt.column([% loop.count - 1 %]).search(library_id ? '^'+library_id+'$' : ''); |
811 |
table_dt.column([% loop.count - 1 %]).search(library_id ? '^'+library_id+'$' : ''); |
784 |
[% CASE 'category' %] |
812 |
[% CASE 'category' %] |
785 |
let category_id = $("#categorycode_filter").val() || ""; |
813 |
let category_id = patron_search_form.find(".categorycode_filter").val() || ""; |
786 |
patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id.toLowerCase()); |
814 |
patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id.toLowerCase()); |
787 |
table_dt.column([% loop.count - 1 %]).search(category_id ? '^'+category_id+'$' : ''); |
815 |
table_dt.column([% loop.count - 1 %]).search(category_id ? '^'+category_id+'$' : ''); |
788 |
[% END %] |
816 |
[% END %] |
Lines 797-812
Link Here
|
797 |
} |
825 |
} |
798 |
|
826 |
|
799 |
function clearFilters() { |
827 |
function clearFilters() { |
800 |
$("#searchfieldstype_filter option:first").prop("selected", true); |
828 |
let parent_block = $("#[% search_results_block_id | html %]"); |
801 |
$("#searchtype_filter option[value='[% searchtype | html %]']").prop("selected", true); |
829 |
let patron_search_form = get_patron_search_form(); |
802 |
$("#categorycode_filter option:first").prop("selected", true); |
830 |
patron_search_form.find(".searchfieldstype_filter option:first").prop("selected", true); |
803 |
$("#branchcode_filter option:first").prop("selected", true); |
831 |
patron_search_form.find(".searchtype_filter option[value='[% searchtype | html %]']").prop("selected", true); |
804 |
$("#sort1_filter").val('').trigger("change"); |
832 |
patron_search_form.find(".categorycode_filter option:first").prop("selected", true); |
805 |
$("#sort2_filter").val('').trigger("change"); |
833 |
patron_search_form.find(".branchcode_filter option:first").prop("selected", true); |
806 |
$("#firstletter_filter").val(''); |
834 |
patron_search_form.find("select[name='sort1_filter']").val('').trigger("change"); |
807 |
$("#search_patron_filter").val(''); |
835 |
patron_search_form.find("select[name='sort2_filter']").val('').trigger("change"); |
808 |
/* remove any search string added by firstletter search */ |
836 |
parent_block.find(".firstletter_filter").val(''); |
809 |
history.pushState( {}, null, window.location.href.split("?" )[0]); |
837 |
patron_search_form.find(".search_patron_filter").val(''); |
|
|
838 |
[% IF adjust_history %] |
839 |
/* remove any search string added by firstletter search */ |
840 |
history.pushState( {}, null, window.location.href.split("?" )[0]); |
841 |
[% END %] |
810 |
$("#[% table_id | html %]_search_results").hide(); |
842 |
$("#[% table_id | html %]_search_results").hide(); |
811 |
[% IF display_search_description %] |
843 |
[% IF display_search_description %] |
812 |
update_search_description(); |
844 |
update_search_description(); |
Lines 815-827
Link Here
|
815 |
|
847 |
|
816 |
// User has clicked on a letter |
848 |
// User has clicked on a letter |
817 |
function filterByFirstLetterSurname(letter, setstate ) { |
849 |
function filterByFirstLetterSurname(letter, setstate ) { |
818 |
$("#firstletter_filter").val(letter); |
850 |
let parent_block = $("#[% search_results_block_id | html %]"); |
|
|
851 |
parent_block.find(".firstletter_filter").val(letter); |
819 |
|
852 |
|
820 |
$("#[% table_id | html %]_search_results").show(); |
853 |
$("#[% table_id | html %]_search_results").show(); |
821 |
|
854 |
|
822 |
if ( setstate ) { |
855 |
[% IF adjust_history %] |
823 |
history.pushState( null, null, "?firstletter=" + letter ); |
856 |
if ( setstate ) { |
824 |
} |
857 |
history.pushState( null, null, "?firstletter=" + letter ); |
|
|
858 |
} |
859 |
[% END %] |
825 |
|
860 |
|
826 |
patrons_table.DataTable().draw(); |
861 |
patrons_table.DataTable().draw(); |
827 |
[% IF display_search_description %] |
862 |
[% IF display_search_description %] |
Lines 832-845
Link Here
|
832 |
// modify parent window owner element |
867 |
// modify parent window owner element |
833 |
function modal_add_user(borrowernumber, borrowername) { |
868 |
function modal_add_user(borrowernumber, borrowername) { |
834 |
[%# Note that add_user could sent data instead of borrowername too %] |
869 |
[%# Note that add_user could sent data instead of borrowername too %] |
835 |
$("#info").hide(); |
870 |
let parent_block = $("#[% search_results_block_id | html %]"); |
836 |
$("#error").hide(); |
871 |
parent_block.find(".info").hide(); |
|
|
872 |
parent_block.find(".error").hide(); |
837 |
if ( add_user(borrowernumber, borrowername) < 0 ) { |
873 |
if ( add_user(borrowernumber, borrowername) < 0 ) { |
838 |
$("#error").html(_("Patron '%s' is already in the list.").format(borrowername)); |
874 |
parent_block.find(".error").html(_("Patron '%s' is already in the list.").format(borrowername)).show(); |
839 |
$("#error").show(); |
|
|
840 |
} else { |
875 |
} else { |
841 |
$("#info").html(_("Patron '%s' added.").format(borrowername)); |
876 |
parent_block.find(".info").html(_("Patron '%s' added.").format(borrowername)).show(); |
842 |
$("#info").show(); |
|
|
843 |
} |
877 |
} |
844 |
} |
878 |
} |
845 |
function modal_select_user(borrowernumber, data) { |
879 |
function modal_select_user(borrowernumber, data) { |
Lines 853-858
Link Here
|
853 |
[% END %] |
887 |
[% END %] |
854 |
} |
888 |
} |
855 |
} |
889 |
} |
|
|
890 |
} |
856 |
</script> |
891 |
</script> |
857 |
[% END %] |
892 |
[% END %] |
858 |
|
893 |
|
Lines 861-866
Link Here
|
861 |
[% UNLESS patron_search_modal_id %] |
896 |
[% UNLESS patron_search_modal_id %] |
862 |
[% patron_search_modal_id = "patron_search_modal" %] |
897 |
[% patron_search_modal_id = "patron_search_modal" %] |
863 |
[% END %] |
898 |
[% END %] |
|
|
899 |
[% UNLESS table_id %] |
900 |
[% table_id = "memberresultst" %] |
901 |
[% END %] |
902 |
|
903 |
[% search_results_block_id = patron_search_modal_id _ '_searchresults' %] |
904 |
|
864 |
<div id="[% patron_search_modal_id | html %]" class="modal modal-full" tabindex="-1" role="dialog" aria-labelledby="patronSearchLabel" aria-hidden="true" data-backdrop=""> |
905 |
<div id="[% patron_search_modal_id | html %]" class="modal modal-full" tabindex="-1" role="dialog" aria-labelledby="patronSearchLabel" aria-hidden="true" data-backdrop=""> |
865 |
<div class="modal-dialog" role="document"> |
906 |
<div class="modal-dialog" role="document"> |
866 |
<div class="modal-content"> |
907 |
<div class="modal-content"> |
Lines 871-877
Link Here
|
871 |
<div class="modal-body"> |
912 |
<div class="modal-body"> |
872 |
[% PROCESS patron_search_filters filters => ['branch','category','sort1','sort2'] %] |
913 |
[% PROCESS patron_search_filters filters => ['branch','category','sort1','sort2'] %] |
873 |
|
914 |
|
874 |
<div id="searchresults"> |
915 |
<div id="[% search_results_block_id | html %]"> <!-- FIXME removed style from #searchresults, is that bad? --> |
875 |
[% IF columns.grep('checkbox').size %] |
916 |
[% IF columns.grep('checkbox').size %] |
876 |
<div class="searchheader fh-fixedHeader" id="searchheader" style="display:none;"> |
917 |
<div class="searchheader fh-fixedHeader" id="searchheader" style="display:none;"> |
877 |
<div> |
918 |
<div> |
Lines 884-890
Link Here
|
884 |
</div> |
925 |
</div> |
885 |
</div> |
926 |
</div> |
886 |
[% END %] |
927 |
[% END %] |
887 |
[% PROCESS patron_search_table table_id => 'memberresultst' columns => columns %] |
928 |
[% PROCESS patron_search_table table_id => table_id, columns => columns %] |
888 |
</div> |
929 |
</div> |
889 |
</div> |
930 |
</div> |
890 |
<div class="modal-footer"> |
931 |
<div class="modal-footer"> |