8 [% INCLUDE 'doc-head-open.inc' %]
9 [% SET libraries = Branches.all %]
10 [% SET categories = Categories.all.unblessed %]
11 <title>Patron search › Koha</title>
12 [% INCLUDE 'doc-head-close.inc' %]
13 <style> .modal-body .close { display: none; } </style>
16 <body id="common_patron_search" class="common">
17 <div id="patron_search" class="yui-t7">
18 <div class="container-fluid">
20 <form id="searchform">
21 <fieldset class="brief">
22 <h3>Search for patron</h3>
25 <label for="searchmember_filter">Search:</label>
26 <input type="text" id="searchmember_filter" value="[% searchmember | html %]" class="focus" />
29 [% FOR column IN columns %]
33 <label for="branchcode_filter">Library:</label>
34 <select id="branchcode_filter">
35 [% SET libraries = Branches.all( only_from_group => 1 ) %]
36 [% IF libraries.size != 1 %]
37 <option value="">Any</option>
39 [% FOREACH l IN libraries %]
40 <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option>
46 <label for="categorycode_filter">Category:</label>
47 <select id="categorycode_filter">
48 <option value="">Any</option>
49 [% FOREACH category IN categories %]
50 <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
57 <fieldset class="action">
58 <input type="submit" value="Search" />
63 [% IF patrons_with_acq_perm_only %]
64 <div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div>
67 [% IF patrons_with_suggestion_perm_only %]
68 <div class="hint">Only staff with superlibrarian or suggestions_manage permissions are returned in the search results</div>
73 [% FOREACH letter IN alphabet.split(' ') %]
74 <a href="#" class="filterByLetter">[% letter | html %]</a>
78 <div id="info" class="dialog message"></div>
79 <div id="error" class="dialog alert"></div>
81 <input type="hidden" id="firstletter_filter" value="" />
82 <div id="searchresults">
83 <table id="memberresultst">
86 [% FOR column IN columns %]
88 [% CASE 'cardnumber' %]<th>Card</th>
89 [% CASE 'dateofbirth' %]<th>Date of birth</th>
90 [% CASE 'address' %]<th>Address</th>
91 [% CASE 'name' %]<th>Name</th>
92 [% CASE 'branch' %]<th data-filter="libraries">Library</th>
93 [% CASE 'category' %]<th data-filter="categories">Category</th>
94 [% CASE 'dateexpiry' %]<th>Expires on</td>
95 [% CASE 'borrowernotes' %]<th>Notes</th>
96 [% CASE 'action' %]<th> </th>
105 <div id="closewindow"><a href="#" class="btn btn-default btn-default close">Close</a></div>
107 <!-- Patron preview modal -->
108 <div class="modal" id="patronPreview" tabindex="-1" role="dialog" aria-labelledby="patronPreviewLabel">
109 <div class="modal-dialog" role="document">
110 <div class="modal-content">
111 <div class="modal-header">
112 <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
113 <h4 class="modal-title" id="patronPreviewLabel"></h4>
115 <div class="modal-body">
117 <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading
120 <div class="modal-footer">
121 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
130 [% MACRO jsinclude BLOCK %]
132 let categories = [% To.json(categories) | $raw %];
133 let categories_map = categories.reduce((map, c) => {
134 map[c.categorycode] = c;
137 let libraries = [% To.json(libraries) | $raw %];
138 let libraries_map = libraries.reduce((map, l) => {
139 map[l.branchcode] = l;
143 [% INCLUDE 'datatables.inc' %]
144 [% INCLUDE 'js-date-format.inc' %]
145 [% INCLUDE 'js-patron-get-age.inc' %]
146 [% INCLUDE 'js-patron-format.inc' %]
147 [% INCLUDE 'js-patron-format-address.inc' %]
152 $(document).ready(function(){
156 $("#searchresults").hide();
158 let additional_filters = {
160 let start_with = $("#firstletter_filter").val()
161 if (!start_with) return "";
162 return { "like": start_with + "%" }
165 patrons_table = $("#memberresultst").kohaTable({
168 [% CASE 'suggestions_managers' %]
169 "url": '/api/v1/suggestions/managers'
170 [% CASE 'baskets_managers' %]
171 "url": '/api/v1/acquisitions/baskets/managers'
172 [% CASE 'funds_owners' %]
173 "url": '/api/v1/acquisitions/funds/owners'
174 [% CASE 'funds_users' %]
175 "url": '/api/v1/acquisitions/funds/users'
177 "url": '/api/v1/patrons'
180 "order": [[ 1, "asc" ]],
183 [% FOR column IN columns %]
185 [% CASE 'cardnumber' %]
187 "data": "cardnumber",
191 [% CASE 'dateofbirth' %]
193 "data": "date_of_birth",
196 "render": function( data, type, row, meta ) {
197 return data ? escape_str($date(data) + " (" + _("%s years").format($get_age(data)) + ")") : "";
202 "data": "me.street_number:me.address:me.address2:me.city:me.state:me.postal_code:me.country",
205 "render": function( data, type, row, meta ) {
206 return escape_str($format_address(row) + " ") + escape_str(libraries_map[row.library_id].branchname);
211 "data": "me.firstname:me.surname",
214 "render": function( data, type, row, meta ) {
215 return $patron_to_html(row, { invert_name: 1 });
220 "data": "library_id",
223 "render": function( data, type, row, meta ) {
224 return escape_str(libraries_map[data].branchname);
227 [% CASE 'category' %]
229 "data": "category_id",
232 "render": function( data, type, row, meta ) {
233 return escape_str(categories_map[data].description);
236 [% CASE 'dateexpiry' %]
238 "data": "expiry_date",
241 "render": function( data, type, row, meta ) {
242 return data ? escape_str($date(data)) : "";
245 [% CASE 'borrowernotes' %]
247 "data": "staff_notes",
250 [%# We don't escape here, we allow html tag in staff notes %]
254 "data": function( row, type, val, meta ) {
256 let patron_id = encodeURIComponent(row.patron_id);
257 [% IF selection_type == 'select' %]
258 return '<a href="#" class="btn btn-default btn-xs select_user" data-borrowernumber="' + patron_id + '">Select</a><input type="hidden" id="borrower_data' + patron_id + '" name="borrower_data'+ patron_id + '" value=\''+JSON.stringify(row)+'\' />';
260 return '<a href="#" class="btn btn-default btn-xs add_user" data-borrowernumber="' + patron_id + '" data-firstname="' + encodeURIComponent(row.firstname) + '" data-surname="' + encodeURIComponent(row.surname) + '">Add</a><input type="hidden" id="borrower_data' + patron_id + '" name="borrower_data'+ patron_id + '" />';
267 [% UNLESS loop.last %],[% END %]
271 'sPaginationType': 'full_numbers',
272 "iDisplayLength": [% Koha.Preference('PatronsPerPage') | html %],
273 }, null, 1, additional_filters);
275 $("#searchform").on('submit', filter);
276 $(".filterByLetter").on("click",function(e){
278 filterByFirstLetterSurname($(this).text());
280 $("body").on("click",".add_user",function(e){
282 var borrowernumber = $(this).data("borrowernumber");
283 var firstname = $(this).data("firstname");
284 var surname = $(this).data("surname");
285 add_user( borrowernumber, firstname + " " + surname );
288 $("body").on("click",".select_user",function(e){
290 var borrowernumber = $(this).data("borrowernumber");
291 var borrower_data = $("#borrower_data"+borrowernumber).val();
292 select_user( borrowernumber, JSON.parse(borrower_data) );
295 $("body").on("click",".patron_preview", function( e ){
297 var borrowernumber = $(this).data("borrowernumber");
298 var page = "/cgi-bin/koha/members/moremember.pl?print=brief&borrowernumber=" + borrowernumber;
299 $("#patronPreview .modal-body").load( page + " div.container-fluid" );
300 $('#patronPreview').modal({show:true});
303 $("#patronPreview").on('hidden.bs.modal', function (e) {
304 $("#patronPreview .modal-body").html("<img src=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> Loading");
311 $("#firstletter_filter").val('');
312 $("#searchresults").show();
314 let table_dt = patrons_table.DataTable();
315 [% FOR c IN columns %]
318 let library_id = $("#branchcode_filter").val();
319 patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id);
320 table_dt.column([% loop.count - 1 %]).search(library_id);
321 [% CASE 'category' %]
322 let category_id = $("#categorycode_filter").val();
323 patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id);
324 table_dt.column([% loop.count - 1 %]).search(category_id);
327 table_dt.search($("#searchmember_filter").val());
332 // User has clicked on a letter
333 function filterByFirstLetterSurname(letter) {
334 $("#firstletter_filter").val(letter);
336 $("#searchresults").show();
337 patrons_table.fnDraw();
340 // modify parent window owner element
341 [% IF selection_type == 'add' %]
342 function add_user(borrowernumber, borrowername) {
343 var p = window.opener;
344 // In one place (serials/routing.tt), the page is reload on every add
345 // We have to wait for the page to be there
346 function wait_for_opener () {
347 if ( ! $(opener.document).find('body').size() ) {
348 setTimeout(wait_for_opener, 500);
350 [%# Note that add_user could sent data instead of borrowername too %]
353 if ( p.add_user(borrowernumber, borrowername) < 0 ) {
354 $("#error").html(_("Patron '%s' is already in the list.").format(borrowername));
357 $("#info").html(_("Patron '%s' added.").format(borrowername));
364 [% ELSIF selection_type == 'select' %]
365 function select_user(borrowernumber, data) {
366 var p = window.opener;
368 p.[% callback | html %](borrowernumber, data);
370 p.select_user(borrowernumber, data);
378 [% SET popup_window = 1 %]
379 [% INCLUDE 'intranet-bottom.inc' %]