Bug 10902: Highlight patrons from logged-in library in patron searches
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE TablesSettings %]
5 [% USE Branches %]
6 [% USE Categories %]
7 [% SET footerjs = 1 %]
8 [% PROCESS 'patronfields.inc' %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Patrons[% IF ( searching ) %] &rsaquo; Search results[% END %] &rsaquo; Koha</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 </head>
13
14 <body id="pat_member" class="pat">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'patron-search.inc' %]
17
18 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
19     <ol>
20         <li>
21             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
22         </li>
23         [% IF ( searching ) %]
24             <li>
25                 <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>
26             </li>
27             <li>
28                 <a href="#" aria-current="page">
29                     Search results
30                 </a>
31             </li>
32         [% ELSE %]
33             <li>
34                 <a href="#" aria-current="page">
35                     Patrons
36                 </a>
37             </li>
38         [% END %]
39     </ol>
40 </nav>
41
42 <div class="main container-fluid">
43     <div class="row">
44         <div class="col-sm-10 col-sm-push-2">
45             <main>
46
47           [% IF CAN_user_tools_manage_patron_lists %]
48             <div id="patron_list_dialog" class="dialog alert">
49               Added <span class="patrons-length"></span> patrons to <a></a>.
50             </div>
51           [% END %]
52
53           [% INCLUDE 'patron-toolbar.inc' %]
54           [% INCLUDE 'noadd-warnings.inc' %]
55
56           <div class="browse">
57             Browse by last name:
58             [% FOREACH letter IN alphabet.split(' ') %]
59                 <a href="#" class="filterByLetter">[% letter | html %]</a>
60             [% END %]
61           </div>
62
63           [% IF CAN_user_borrowers_edit_borrowers && pending_borrower_modifications %]
64             <div class="pending-info" id="patron_updates_pending">
65               <a href="/cgi-bin/koha/members/members-update.pl">Patrons requesting modifications</a>:
66               <span class="number_box"><a href="/cgi-bin/koha/members/members-update.pl">[% pending_borrower_modifications | html %]</a></span>
67             </div>
68           [% END %]
69
70           <div id="searchresults">
71             <h3>Patrons found for: <span id="searchpattern">[% IF searchmember %] for '[% searchmember | html %]'[% END %]</span></h3>
72             [% IF CAN_user_tools_manage_patron_lists || CAN_user_borrowers_edit_borrowers %]
73               <div class="searchheader fh-fixedHeader" id="searchheader">
74                   <div>
75                       <a href="#" id="select_all"><i class="fa fa-check"></i> Select all</a>
76                       |
77                       <a href="#" id="clear_all"><i class="fa fa-remove"></i> Clear all</a>
78                     [% IF CAN_user_tools_manage_patron_lists %]
79                       |
80                       <span>
81                           <label for="add_to_patron_list">Add selected patrons to:</label>
82                           <select id="add_to_patron_list" name="add_to_patron_list">
83                               <option value=""></option>
84                               [% IF patron_lists %]
85                                   <optgroup label="Patron lists:">
86                                       [% FOREACH pl IN patron_lists %]
87                                           <option value="[% pl.patron_list_id | html %]">[% pl.name | html %]</option>
88                                       [% END %]
89                                   </optgroup>
90                               [% END %]
91
92                               <option value="new">[ New list ]</option>
93                           </select>
94
95                           <input type="text" id="new_patron_list" name="new_patron_list" id="new_patron_list" />
96
97                           <input id="add_to_patron_list_submit" type="submit" class="submit" value="Save">
98                       </span>
99                     [% END %]
100
101                     [% IF CAN_user_tools_manage_patron_lists && CAN_user_borrowers_edit_borrowers %]
102                         |
103                     [% END %]
104
105                     [% IF CAN_user_borrowers_edit_borrowers %]
106                           <button id="merge-patrons" type="submit">Merge selected patrons</button>
107                     [% END %]
108                   </div>
109                 </div>
110             [% END %]
111
112             <table id="memberresultst">
113               <thead>
114                 <tr>
115                 [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
116                   <th>&nbsp;</th>
117                 [% END %]
118                   <th>Card</th>
119                   <th>Name</th>
120                   <th>Date of birth</th>
121                   <th>Category</th>
122                   <th>Library</th>
123                   <th>Expires on</th>
124                   <th>OD/Checkouts</th>
125                   <th>Fines</th>
126                   <th>Circ note</th>
127                   <th>&nbsp;</th>
128                 </tr>
129               </thead>
130               <tbody></tbody>
131             </table>
132           </div>
133
134             </main>
135         </div> <!-- /.col-sm-10.col-sm-push-2 -->
136
137         <div class="col-sm-2 col-sm-pull-10">
138             <aside>
139                 <form method="get" id="searchform">
140                   <input type="hidden" id="firstletter_filter" value="" />
141                   <fieldset class="brief">
142                     <h3>Search patrons</h3>
143                     <ol>
144                       <li>
145                         <label for="searchmember_filter">Search for:</label>
146                         <input type="text" id="searchmember_filter" value="[% searchmember | html %]"/>
147                       </li>
148                       <li>
149                         <label for="searchfieldstype_filter">Search field:</label>
150                         <select name="searchfieldstype" id="searchfieldstype_filter">
151                             [% pref_fields = Koha.Preference('DefaultPatronSearchFields').split(',') %]
152                             [% default_fields = [ 'standard', 'surname', 'cardnumber', 'email', 'borrowernumber', 'userid', 'phone', 'address', 'dateofbirth', 'sort1', 'sort2' ] %]
153                             [% search_options = default_fields.merge(pref_fields).unique %]
154                             [% FOREACH s_o IN search_options %]
155                                 [% display_name = PROCESS patron_fields name=s_o %]
156                                 [% NEXT IF !display_name %]
157                                 [% IF searchfieldstype == s_o %]
158                                     <option selected="selected" value=[% s_o | html %]>[% display_name | $raw %]</option>
159                                 [% ELSE %]
160                                     <option value=[% s_o | html %]>[% display_name | $raw %]</option>
161                                 [% END %]
162                             [% END %]
163                         </select>
164                       </li>
165                       <li>
166                         <label for="searchtype_filter">Search type:</label>
167                         <select name="searchtype" id="searchtype_filter">
168                           [% IF searchtype == "start_with" %]
169                             <option value='start_with' selected="selected">Starts with</option>
170                             <option value="contain">Contains</option>
171                           [% ELSE %]
172                             <option value='start_with'>Starts with</option>
173                             <option value="contain" selected="selected">Contains</option>
174                           [% END %]
175                         </select>
176                       </li>
177                       <li>
178                         <label for="categorycode_filter">Patron category:</label>
179                         [% SET categories = Categories.all() %]
180                         <select id="categorycode_filter">
181                           <option value="">Any</option>
182                           [% FOREACH cat IN categories %]
183                             [% IF cat.categorycode == categorycode_filter %]
184                     <option selected="selected" value="[% cat.categorycode | html %]">[% cat.description | html %]</option>
185                             [% ELSE %]
186                     <option value="[% cat.categorycode | html %]">[% cat.description | html %]</option>
187
188                             [% END %]
189                           [% END %]
190                         </select>
191                       </li>
192                       <li>
193                         <label for="branchcode_filter">Library:</label>
194                         [% SET branches = Branches.all( selected => branchcode_filter, only_from_group => 1 ) %]
195                         <select id="branchcode_filter">
196                           [% IF branches.size != 1 %]
197                             <option value="">Any</option>
198                           [% END %]
199                           [% PROCESS options_for_libraries libraries => branches %]
200                         </select>
201                       </li>
202                     </ol>
203                     <fieldset class="action">
204                       <input type="submit" value="Search" />
205                       <input type="button" value="Clear" id="clear_search" />
206                     </fieldset>
207                   </fieldset>
208                 </form>
209             </aside>
210         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
211     </div> <!-- /.row -->
212
213 [% MACRO jsinclude BLOCK %]
214     [% INCLUDE 'datatables.inc' %]
215     [% INCLUDE 'columns_settings.inc' %]
216     [% INCLUDE 'str/members-menu.inc' %]
217     [% Asset.js("lib/hc-sticky.js") | $raw %]
218     [% Asset.js("js/members-menu.js") | $raw %]
219     <script>
220         $(document).ready(function() {
221             $('#merge-patrons').prop('disabled', true);
222             $('#memberresultst').on('change', 'input.selection', function() {
223                 if ( $('.selection:checked').length > 1 ) {
224                     $('#merge-patrons').prop('disabled', false);
225                 } else {
226                     $('#merge-patrons').prop('disabled', true);
227                 }
228             });
229             $('#merge-patrons').on('click', function() {
230                 var merge_patrons_url = 'merge-patrons.pl?' + $('.selection:checked')
231                     .map(function() {
232                        return "id=" + $(this).val()
233                     }).get().join('&');
234
235                 window.location.href = merge_patrons_url;
236             });
237
238             $('#add_to_patron_list_submit').prop('disabled', true);
239             $('#new_patron_list').hide();
240
241             $('#add_to_patron_list').change(function() {
242                 var value = $('#add_to_patron_list').val();
243                 if ( value == 'new' ) {
244                     $('#new_patron_list').val('')
245                     $('#new_patron_list').show();
246                     $('#new_patron_list').focus();
247                 } else if ( value ) {
248                     $('#new_patron_list').hide();
249                     $('#add_to_patron_list_submit').prop('disabled', false);
250                 } else {
251                     $('#new_patron_list').hide();
252                     $('#add_to_patron_list_submit').prop('disabled', true);
253                 }
254             });
255
256             $('#new_patron_list').on('input', function() {
257                 if ( $('#new_patron_list').val() ) {
258                     $('#add_to_patron_list_submit').prop('disabled', false);
259                 } else {
260                     $('#add_to_patron_list_submit').prop('disabled', true);
261                 }
262             });
263
264             $("#add_to_patron_list_submit").on('click', function(e){
265                 if ( $('#add_to_patron_list').val() == 'new' ) {
266                     if ( $('#new_patron_list').val() ) {
267                         $("#add_to_patron_list option").each(function() {
268                             if ( $(this).text() == $('#new_patron_list').val() ) {
269                                 alert( _("You already have a list with that name!") );
270                                 return false;
271                             }
272                         });
273                     } else {
274                         alert( _("You must give your new patron list a name!") );
275                         return false;
276                     }
277                 }
278
279                 if ( $("#memberresultst input:checkbox:checked").length == 0 ) {
280                     alert( _("You have not selected any patrons to add to a list!") );
281                     return false;
282                 }
283
284                 var borrowernumbers = [];
285                 $("#memberresultst").find("input:checkbox:checked").each(function(){
286                     borrowernumbers.push($(this).val());
287                 });
288                 var data = {
289                     add_to_patron_list: $("#add_to_patron_list").val(),
290                     new_patron_list: $("#new_patron_list").val(),
291                     borrowernumbers: borrowernumbers
292                 };
293                 $.ajax({
294                     data: data,
295                     type: 'POST',
296                     url: '/cgi-bin/koha/svc/members/add_to_list',
297                     success: function(data) {
298                         $("#patron_list_dialog").show();
299                         $("#patron_list_dialog > span.patrons-length").html(data.patrons_added_to_list);
300                         $("#patron_list_dialog > a").attr("href", "/cgi-bin/koha/patron_lists/list.pl?patron_list_id=" + data.patron_list.patron_list_id);
301                         $("#patron_list_dialog > a").html(data.patron_list.name);
302                         if ( $('#add_to_patron_list').val() == 'new' ) {
303                             var new_patron_list_added = $("<option>", {
304                                 value: data.patron_list.patron_list_id,
305                                 text: data.patron_list.name
306                             });
307                             $("#add_to_patron_list optgroup").append(new_patron_list_added);
308                             $("#add_to_patron_list").val(data.patron_list.patron_list_id);
309                             $("#new_patron_list").val('');
310                             $('#add_to_patron_list').change();
311                         }
312                     },
313                     error: function() {
314                         alert("an error occurred");
315                     }
316                 });
317                 return true;
318             });
319             $(".filterByLetter").on("click",function(e){
320                 e.preventDefault();
321                 filterByFirstLetterSurname($(this).text());
322             });
323             $("#select_all").on("click",function(e){
324                 e.preventDefault();
325                 $(".selection").prop("checked", true).change();
326             });
327             $("#clear_all").on("click",function(e){
328                 e.preventDefault();
329                 $(".selection").prop("checked", false).change();
330             });
331             $("#clear_search").on("click",function(e){
332                 e.preventDefault();
333                 clearFilters(true);
334             });
335             $("#searchform").on("submit", filter);
336
337         });
338
339         var dtMemberResults;
340         var search = 1;
341         $(document).ready(function() {
342             [% IF searchmember %]
343                 $("#searchmember_filter").val("[% searchmember | html %]");
344             [% END %]
345             [% IF searchfieldstype %]
346                 $("searchfieldstype_filter").val("[% searchfieldstype | html %]");
347             [% END %]
348             [% IF searchtype %]
349                 $("#searchtype_filter").val("[% searchtype | html %]");
350             [% END %]
351             [% IF categorycode %]
352                 $("#categorycode_filter").val("[% categorycode_filter | html %]");
353             [% END %]
354             [% IF branchcode %]
355                 $("#branchcode_filter").val("[% branchcode_filter | html %]");
356             [% END %]
357
358             [% IF view != "show_results" %]
359                 search = 0;
360             [% ELSE %]
361                 $("#searchresults").show();
362             [% END %]
363
364             // Build the aLengthMenu
365             var aLengthMenu = [
366                 [% PatronsPerPage | html %], 10, 20, 50, 100, -1
367             ];
368             jQuery.unique(aLengthMenu);
369             aLengthMenu.sort(function( a, b ){
370                 // Put "All" at the end
371                 if ( a == -1 ) {
372                     return 1;
373                 } else if ( b == -1 ) {
374                     return -1;
375                 }
376                 return parseInt(a) < parseInt(b) ? -1 : 1;}
377             );
378             var aLengthMenuLabel = [];
379             $(aLengthMenu).each(function(){
380                 if ( this == -1 ) {
381                     // Label for -1 is "All"
382                     aLengthMenuLabel.push(_("All"));
383                 } else {
384                     aLengthMenuLabel.push(this);
385                 }
386             });
387
388             // Apply DataTables on the results table
389             var columns_settings = [% TablesSettings.GetColumns( 'members', 'member', 'memberresultst', 'json' ) | $raw %];
390             [% UNLESS CAN_user_borrowers_edit_borrowers OR CAN_user_tools_manage_patron_lists %]
391                 [%# Remove the first column if we do not display the checkbox %]
392                 columns_settings.splice(0, 1);
393             [% END %]
394             dtMemberResults = KohaTable("memberresultst", {
395                 'bServerSide': true,
396                 'sAjaxSource': "/cgi-bin/koha/svc/members/search",
397                 'fnServerData': function(sSource, aoData, fnCallback) {
398                     if ( ! search ) {
399                         return;
400                     }
401                     aoData.push({
402                         'name': 'searchmember',
403                         'value': $("#searchmember_filter").val()
404                     },{
405                         'name': 'firstletter',
406                         'value': $("#firstletter_filter").val()
407                     },{
408                         'name': 'searchfieldstype',
409                         'value': $("#searchfieldstype_filter").val()
410                     },{
411                         'name': 'searchtype',
412                         'value': $("#searchtype_filter").val()
413                     },{
414                         'name': 'categorycode',
415                         'value': $("#categorycode_filter").val()
416                     },{
417                         'name': 'branchcode',
418                         'value': $("#branchcode_filter").val()
419                     },{
420                         'name': 'name_sorton',
421                         'value': 'borrowers.surname borrowers.firstname'
422                     },{
423                         'name': 'cardnumber_sorton',
424                         'value': 'borrowers.cardnumber',
425                     },{
426                         'name': 'dateofbirth_sorton',
427                         'value': 'borrowers.dateofbirth',
428                     },{
429                         'name': 'dateexpiry_sorton',
430                         'value': 'borrowers.dateexpiry',
431                     },{
432                         'name': 'category_sorton',
433                         'value': 'categories.description',
434                     },{
435                         'name': 'branch_sorton',
436                         'value': 'branches.branchname'
437                     },{
438                         'name': 'borrowernotes_sorton',
439                         'value': 'borrowers.borrowernotes'
440                     },{
441                         'name': 'template_path',
442                         'value': 'members/tables/members_results.tt',
443                     });
444                     $.ajax({
445                         'dataType': 'json',
446                         'type': 'POST',
447                         'url': sSource,
448                         'data': aoData,
449                         'success': function(json){
450                             // redirect if there is only 1 result.
451                             if ( json.aaData.length == 1 ) {
452                                 var borrowernumber = json.aaData[0].borrowernumber;
453                                 document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
454                                 return false;
455                             }
456                             fnCallback(json);
457                         }
458                     });
459                 },
460                 'aoColumns':[
461                     [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
462                       { 'mDataProp': 'dt_borrowernumber', 'bSortable': false },
463                     [% END %]
464                     { 'mDataProp': 'dt_cardnumber' },
465                     { 'mDataProp': 'dt_name' },
466                     { 'mDataProp': 'dt_dateofbirth' },
467                     { 'mDataProp': 'dt_category' },
468                     {
469                         'mDataProp': function ( oObj ) {
470                             if( oObj.dt_branch == "[% Branches.GetLoggedInBranchname | html %]" ){
471                                 return "<span class=\"currentlibrary\">" + oObj.dt_branch + "</span>";
472                             } else {
473                                 return oObj.dt_branch;
474                             }
475                         }
476                     },
477                     { 'mDataProp': 'dt_dateexpiry' },
478                     { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
479                     { 'mDataProp': 'dt_fines', 'bSortable': false },
480                     { 'mDataProp': 'dt_borrowernotes' },
481                     { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
482                 ],
483                 'bFilter': false,
484                 'bAutoWidth': false,
485                 [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
486                     'aaSorting': [[2, 'asc']],
487                 [% ELSE %]
488                     'aaSorting': [[1, 'asc']],
489                 [% END %]
490                 "aLengthMenu": [aLengthMenu, aLengthMenuLabel],
491                 'sPaginationType': 'full_numbers',
492                 "iDisplayLength": [% PatronsPerPage | html %],
493                 "bProcessing": true,
494                 "initComplete": function(settings, json) {
495                     Sticky = $("#searchheader");
496                     Sticky.hcSticky({
497                         stickTo: "#searchresults",
498                         stickyClass: "floating"
499                     });
500                 }
501             }, columns_settings);
502             update_searched();
503         });
504
505         // Update the string "Results found ..."
506         function update_searched(){
507             var searched = $("#searchfieldstype_filter").find("option:selected").text();
508             if ( $("#searchmember_filter").val() ) {
509                 if ( $("#searchtype_filter").val() == 'start_with' ) {
510                     searched += _(" starting with ");
511                 } else {
512                     searched += _(" containing ");
513                 }
514                 searched += "'" + $("#searchmember_filter").val() + "'";
515             }
516             if ( $("#firstletter_filter").val() ) {
517                 searched += _(" begins with ") + "'" + $("#firstletter_filter").val() +"'";
518             }
519             if ( $("#categorycode_filter").val() ) {
520                 searched += _(" with category ") + "'" + $("#categorycode_filter").find("option:selected").text() + "'";
521             }
522             if ( $("#branchcode_filter").val() ) {
523                 searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
524             }
525             $("#searchpattern").text(searched);
526         }
527
528         // Redraw the table
529         function filter() {
530             $("#firstletter_filter").val('');
531             update_searched();
532             search = 1;
533             $("#searchresults").show();
534             dtMemberResults.fnDraw();
535             return false;
536         }
537
538         // User has clicked on the Clear button
539         function clearFilters(redraw) {
540             $("#searchform select").val('');
541             $("#firstletter_filter").val('');
542             $("#searchmember_filter").val('');
543             if(redraw) {
544                 search = 1;
545                 $("#searchresults").show();
546                 dtMemberResults.fnDraw();
547             }
548         }
549
550         // User has clicked on a letter
551         function filterByFirstLetterSurname(letter) {
552             clearFilters(false);
553             $("#firstletter_filter").val(letter);
554             update_searched();
555             search = 1;
556             $("#searchresults").show();
557             dtMemberResults.fnDraw();
558         }
559     </script>
560 [% END %]
561
562 [% INCLUDE 'intranet-bottom.inc' %]