4 [% USE ColumnsSettings %]
8 [% PROCESS 'patronfields.inc' %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Koha › Patrons [% IF ( searching ) %]› Search results[% END %]</title>
11 [% INCLUDE 'doc-head-close.inc' %]
14 <body id="pat_member" class="pat">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'patron-search.inc' %]
18 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › [% IF ( searching ) %]<a href="/cgi-bin/koha/members/members-home.pl">Patrons</a> › Search results[% ELSE %]Patrons[% END %]</div>
20 <div class="main container-fluid">
22 <div class="col-sm-10 col-sm-push-2">
25 [% IF CAN_user_tools_manage_patron_lists %]
26 <div id="patron_list_dialog" class="dialog alert">
27 Added <span class="patrons-length"></span> patrons to <a></a>.
31 [% INCLUDE 'patron-toolbar.inc' %]
32 [% INCLUDE 'noadd-warnings.inc' %]
36 [% FOREACH letter IN alphabet.split(' ') %]
37 <a href="#" class="filterByLetter">[% letter | html %]</a>
41 [% IF CAN_user_borrowers_edit_borrowers && pending_borrower_modifications %]
42 <div class="pending-info" id="patron_updates_pending">
43 <a href="/cgi-bin/koha/members/members-update.pl">Patrons requesting modifications</a>:
44 <span class="number_box"><a href="/cgi-bin/koha/members/members-update.pl">[% pending_borrower_modifications | html %]</a></span>
48 <div id="searchresults">
49 <div id="searchheader">
50 <h3>Patrons found for: <span id="searchpattern">[% IF searchmember %] for '[% searchmember | html %]'[% END %]</span></h3>
52 [% IF CAN_user_tools_manage_patron_lists || CAN_user_borrowers_edit_borrowers %]
53 <div id="searchheader">
55 <a href="#" id="select_all"><i class="fa fa-check"></i> Select all</a>
57 <a href="#" id="clear_all"><i class="fa fa-remove"></i> Clear all</a>
58 [% IF CAN_user_tools_manage_patron_lists %]
61 <label for="add_to_patron_list">Add selected patrons to:</label>
62 <select id="add_to_patron_list" name="add_to_patron_list">
63 <option value=""></option>
65 <optgroup label="Patron lists:">
66 [% FOREACH pl IN patron_lists %]
67 <option value="[% pl.patron_list_id | html %]">[% pl.name | html %]</option>
72 <option value="new">[ New list ]</option>
75 <input type="text" id="new_patron_list" name="new_patron_list" id="new_patron_list" />
77 <input id="add_to_patron_list_submit" type="submit" class="submit" value="Save">
81 [% IF CAN_user_tools_manage_patron_lists && CAN_user_borrowers_edit_borrowers %]
85 [% IF CAN_user_borrowers_edit_borrowers %]
86 <button id="merge-patrons" type="submit">Merge selected patrons</button>
92 <table id="memberresultst">
95 [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
100 <th>Date of birth</th>
104 <th>OD/Checkouts</th>
115 </div> <!-- /.col-sm-10.col-sm-push-2 -->
117 <div class="col-sm-2 col-sm-pull-10">
119 <form method="get" id="searchform">
120 <input type="hidden" id="firstletter_filter" value="" />
121 <fieldset class="brief">
125 <label for="searchmember_filter">Search:</label>
126 <input type="text" id="searchmember_filter" value="[% searchmember | html %]"/>
129 <label for="searchfieldstype_filter">Search fields:</label>
130 <select name="searchfieldstype" id="searchfieldstype_filter">
131 [% pref_fields = Koha.Preference('DefaultPatronSearchFields').split(',') %]
132 [% default_fields = [ 'standard', 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
133 [% search_options = default_fields.merge(pref_fields).unique %]
134 [% FOREACH s_o IN search_options %]
135 [% display_name = PROCESS patron_fields name=s_o %]
136 [% NEXT IF !display_name %]
137 [% IF searchfieldstype == s_o %]
138 <option selected="selected" value=[% s_o | html %]>[% display_name | $raw %]</option>
140 <option value=[% s_o | html %]>[% display_name | $raw %]</option>
146 <label for="searchtype_filter">Search type:</label>
147 <select name="searchtype" id="searchtype_filter">
148 [% IF searchtype == "start_with" %]
149 <option value='start_with' selected="selected">Starts with</option>
150 <option value="contain">Contains</option>
152 <option value='start_with'>Starts with</option>
153 <option value="contain" selected="selected">Contains</option>
158 <label for="categorycode_filter">Category:</label>
159 [% SET categories = Categories.all() %]
160 <select id="categorycode_filter">
161 <option value="">Any</option>
162 [% FOREACH cat IN categories %]
163 [% IF cat.categorycode == categorycode_filter %]
164 <option selected="selected" value="[% cat.categorycode | html %]">[% cat.description | html %]</option>
166 <option value="[% cat.categorycode | html %]">[% cat.description | html %]</option>
173 <label for="branchcode_filter">Library:</label>
174 [% SET branches = Branches.all( selected => branchcode_filter, only_from_group => 1 ) %]
175 <select id="branchcode_filter">
176 [% IF branches.size != 1 %]
177 <option value="">Any</option>
179 [% PROCESS options_for_libraries libraries => branches %]
183 <fieldset class="action">
184 <input type="submit" value="Search" />
185 <input type="button" value="Clear" id="clear_search" />
190 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
191 </div> <!-- /.row -->
193 [% MACRO jsinclude BLOCK %]
194 [% INCLUDE 'datatables.inc' %]
195 [% INCLUDE 'columns_settings.inc' %]
196 [% INCLUDE 'str/members-menu.inc' %]
197 [% Asset.js("js/members-menu.js") | $raw %]
199 $(document).ready(function() {
200 $('#merge-patrons').prop('disabled', true);
201 $('#memberresultst').on('change', 'input.selection', function() {
202 if ( $('.selection:checked').length > 1 ) {
203 $('#merge-patrons').prop('disabled', false);
205 $('#merge-patrons').prop('disabled', true);
208 $('#merge-patrons').on('click', function() {
209 var merge_patrons_url = 'merge-patrons.pl?' + $('.selection:checked')
211 return "id=" + $(this).val()
214 window.location.href = merge_patrons_url;
217 $('#add_to_patron_list_submit').prop('disabled', true);
218 $('#new_patron_list').hide();
220 $('#add_to_patron_list').change(function() {
221 var value = $('#add_to_patron_list').val();
222 if ( value == 'new' ) {
223 $('#new_patron_list').val('')
224 $('#new_patron_list').show();
225 $('#new_patron_list').focus();
226 } else if ( value ) {
227 $('#new_patron_list').hide();
228 $('#add_to_patron_list_submit').prop('disabled', false);
230 $('#new_patron_list').hide();
231 $('#add_to_patron_list_submit').prop('disabled', true);
235 $('#new_patron_list').on('input', function() {
236 if ( $('#new_patron_list').val() ) {
237 $('#add_to_patron_list_submit').prop('disabled', false);
239 $('#add_to_patron_list_submit').prop('disabled', true);
243 $("#add_to_patron_list_submit").on('click', function(e){
244 if ( $('#add_to_patron_list').val() == 'new' ) {
245 if ( $('#new_patron_list').val() ) {
246 $("#add_to_patron_list option").each(function() {
247 if ( $(this).text() == $('#new_patron_list').val() ) {
248 alert( _("You already have a list with that name!") );
253 alert( _("You must give your new patron list a name!") );
258 if ( $("#memberresultst input:checkbox:checked").length == 0 ) {
259 alert( _("You have not selected any patrons to add to a list!") );
263 var borrowernumbers = [];
264 $("#memberresultst").find("input:checkbox:checked").each(function(){
265 borrowernumbers.push($(this).val());
268 add_to_patron_list: $("#add_to_patron_list").val(),
269 new_patron_list: $("#new_patron_list").val(),
270 borrowernumbers: borrowernumbers
275 url: '/cgi-bin/koha/svc/members/add_to_list',
276 success: function(data) {
277 $("#patron_list_dialog").show();
278 $("#patron_list_dialog > span.patrons-length").html(data.patrons_added_to_list);
279 $("#patron_list_dialog > a").attr("href", "/cgi-bin/koha/patron_lists/list.pl?patron_list_id=" + data.patron_list.patron_list_id);
280 $("#patron_list_dialog > a").html(data.patron_list.name);
281 if ( $('#add_to_patron_list').val() == 'new' ) {
282 var new_patron_list_added = $("<option>", {
283 value: data.patron_list.patron_list_id,
284 text: data.patron_list.name
286 $("#add_to_patron_list optgroup").append(new_patron_list_added);
287 $("#add_to_patron_list").val(data.patron_list.patron_list_id);
288 $("#new_patron_list").val('');
289 $('#add_to_patron_list').change();
293 alert("an error occurred");
298 $(".filterByLetter").on("click",function(e){
300 filterByFirstLetterSurname($(this).text());
302 $("#select_all").on("click",function(e){
304 $(".selection").prop("checked", true).change();
306 $("#clear_all").on("click",function(e){
308 $(".selection").prop("checked", false).change();
310 $("#clear_search").on("click",function(e){
314 $("#searchform").on("submit", filter);
319 $(document).ready(function() {
320 [% IF searchmember %]
321 $("#searchmember_filter").val("[% searchmember | html %]");
323 [% IF searchfieldstype %]
324 $("searchfieldstype_filter").val("[% searchfieldstype | html %]");
327 $("#searchtype_filter").val("[% searchtype | html %]");
329 [% IF categorycode %]
330 $("#categorycode_filter").val("[% categorycode_filter | html %]");
333 $("#branchcode_filter").val("[% branchcode_filter | html %]");
336 [% IF view != "show_results" %]
339 $("#searchresults").show();
342 // Build the aLengthMenu
344 [% PatronsPerPage | html %], 10, 20, 50, 100, -1
346 jQuery.unique(aLengthMenu);
347 aLengthMenu.sort(function( a, b ){
348 // Put "All" at the end
351 } else if ( b == -1 ) {
354 return parseInt(a) < parseInt(b) ? -1 : 1;}
356 var aLengthMenuLabel = [];
357 $(aLengthMenu).each(function(){
359 // Label for -1 is "All"
360 aLengthMenuLabel.push(_("All"));
362 aLengthMenuLabel.push(this);
366 // Apply DataTables on the results table
367 var columns_settings = [% ColumnsSettings.GetColumns( 'members', 'member', 'memberresultst', 'json' ) | $raw %];
368 [% UNLESS CAN_user_borrowers_edit_borrowers OR CAN_user_tools_manage_patron_lists %]
369 [%# Remove the first column if we do not display the checkbox %]
370 columns_settings.splice(0, 1);
372 dtMemberResults = KohaTable("memberresultst", {
374 'sAjaxSource': "/cgi-bin/koha/svc/members/search",
375 'fnServerData': function(sSource, aoData, fnCallback) {
380 'name': 'searchmember',
381 'value': $("#searchmember_filter").val()
383 'name': 'firstletter',
384 'value': $("#firstletter_filter").val()
386 'name': 'searchfieldstype',
387 'value': $("#searchfieldstype_filter").val()
389 'name': 'searchtype',
390 'value': $("#searchtype_filter").val()
392 'name': 'categorycode',
393 'value': $("#categorycode_filter").val()
395 'name': 'branchcode',
396 'value': $("#branchcode_filter").val()
398 'name': 'name_sorton',
399 'value': 'borrowers.surname borrowers.firstname'
401 'name': 'dateofbirth',
402 'value': 'borrowers.dateofbirth',
404 'name': 'category_sorton',
405 'value': 'categories.description',
407 'name': 'branch_sorton',
408 'value': 'branches.branchname'
410 'name': 'template_path',
411 'value': 'members/tables/members_results.tt',
418 'success': function(json){
419 // redirect if there is only 1 result.
420 if ( json.aaData.length == 1 ) {
421 var borrowernumber = json.aaData[0].borrowernumber;
422 document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
430 [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
431 { 'mDataProp': 'dt_borrowernumber', 'bSortable': false },
433 { 'mDataProp': 'dt_cardnumber' },
434 { 'mDataProp': 'dt_name' },
435 { 'mDataProp': 'dt_dateofbirth' },
436 { 'mDataProp': 'dt_category' },
437 { 'mDataProp': 'dt_branch' },
438 { 'mDataProp': 'dt_dateexpiry' },
439 { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
440 { 'mDataProp': 'dt_fines', 'bSortable': false },
441 { 'mDataProp': 'dt_borrowernotes' },
442 { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
446 [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
447 'aaSorting': [[2, 'asc']],
449 'aaSorting': [[1, 'asc']],
451 "aLengthMenu": [aLengthMenu, aLengthMenuLabel],
452 'sPaginationType': 'full_numbers',
453 "iDisplayLength": [% PatronsPerPage | html %],
455 }, columns_settings);
459 // Update the string "Results found ..."
460 function update_searched(){
461 var searched = $("#searchfieldstype_filter").find("option:selected").text();
462 if ( $("#searchmember_filter").val() ) {
463 if ( $("#searchtype_filter").val() == 'start_with' ) {
464 searched += _(" starting with ");
466 searched += _(" containing ");
468 searched += "'" + $("#searchmember_filter").val() + "'";
470 if ( $("#firstletter_filter").val() ) {
471 searched += _(" begins with ") + "'" + $("#firstletter_filter").val() +"'";
473 if ( $("#categorycode_filter").val() ) {
474 searched += _(" with category ") + "'" + $("#categorycode_filter").find("option:selected").text() + "'";
476 if ( $("#branchcode_filter").val() ) {
477 searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
479 $("#searchpattern").text(searched);
484 $("#firstletter_filter").val('');
487 $("#searchresults").show();
488 dtMemberResults.fnDraw();
492 // User has clicked on the Clear button
493 function clearFilters(redraw) {
494 $("#searchform select").val('');
495 $("#firstletter_filter").val('');
496 $("#searchmember_filter").val('');
499 $("#searchresults").show();
500 dtMemberResults.fnDraw();
504 // User has clicked on a letter
505 function filterByFirstLetterSurname(letter) {
507 $("#firstletter_filter").val(letter);
510 $("#searchresults").show();
511 dtMemberResults.fnDraw();
516 [% INCLUDE 'intranet-bottom.inc' %]