Bug 10902: (follow-up) Account for singleBranchMode
[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         var singleBranchMode = '[% singleBranchMode | html %]';
221         $(document).ready(function() {
222             $('#merge-patrons').prop('disabled', true);
223             $('#memberresultst').on('change', 'input.selection', function() {
224                 if ( $('.selection:checked').length > 1 ) {
225                     $('#merge-patrons').prop('disabled', false);
226                 } else {
227                     $('#merge-patrons').prop('disabled', true);
228                 }
229             });
230             $('#merge-patrons').on('click', function() {
231                 var merge_patrons_url = 'merge-patrons.pl?' + $('.selection:checked')
232                     .map(function() {
233                        return "id=" + $(this).val()
234                     }).get().join('&');
235
236                 window.location.href = merge_patrons_url;
237             });
238
239             $('#add_to_patron_list_submit').prop('disabled', true);
240             $('#new_patron_list').hide();
241
242             $('#add_to_patron_list').change(function() {
243                 var value = $('#add_to_patron_list').val();
244                 if ( value == 'new' ) {
245                     $('#new_patron_list').val('')
246                     $('#new_patron_list').show();
247                     $('#new_patron_list').focus();
248                 } else if ( value ) {
249                     $('#new_patron_list').hide();
250                     $('#add_to_patron_list_submit').prop('disabled', false);
251                 } else {
252                     $('#new_patron_list').hide();
253                     $('#add_to_patron_list_submit').prop('disabled', true);
254                 }
255             });
256
257             $('#new_patron_list').on('input', function() {
258                 if ( $('#new_patron_list').val() ) {
259                     $('#add_to_patron_list_submit').prop('disabled', false);
260                 } else {
261                     $('#add_to_patron_list_submit').prop('disabled', true);
262                 }
263             });
264
265             $("#add_to_patron_list_submit").on('click', function(e){
266                 if ( $('#add_to_patron_list').val() == 'new' ) {
267                     if ( $('#new_patron_list').val() ) {
268                         $("#add_to_patron_list option").each(function() {
269                             if ( $(this).text() == $('#new_patron_list').val() ) {
270                                 alert( _("You already have a list with that name!") );
271                                 return false;
272                             }
273                         });
274                     } else {
275                         alert( _("You must give your new patron list a name!") );
276                         return false;
277                     }
278                 }
279
280                 if ( $("#memberresultst input:checkbox:checked").length == 0 ) {
281                     alert( _("You have not selected any patrons to add to a list!") );
282                     return false;
283                 }
284
285                 var borrowernumbers = [];
286                 $("#memberresultst").find("input:checkbox:checked").each(function(){
287                     borrowernumbers.push($(this).val());
288                 });
289                 var data = {
290                     add_to_patron_list: $("#add_to_patron_list").val(),
291                     new_patron_list: $("#new_patron_list").val(),
292                     borrowernumbers: borrowernumbers
293                 };
294                 $.ajax({
295                     data: data,
296                     type: 'POST',
297                     url: '/cgi-bin/koha/svc/members/add_to_list',
298                     success: function(data) {
299                         $("#patron_list_dialog").show();
300                         $("#patron_list_dialog > span.patrons-length").html(data.patrons_added_to_list);
301                         $("#patron_list_dialog > a").attr("href", "/cgi-bin/koha/patron_lists/list.pl?patron_list_id=" + data.patron_list.patron_list_id);
302                         $("#patron_list_dialog > a").html(data.patron_list.name);
303                         if ( $('#add_to_patron_list').val() == 'new' ) {
304                             var new_patron_list_added = $("<option>", {
305                                 value: data.patron_list.patron_list_id,
306                                 text: data.patron_list.name
307                             });
308                             $("#add_to_patron_list optgroup").append(new_patron_list_added);
309                             $("#add_to_patron_list").val(data.patron_list.patron_list_id);
310                             $("#new_patron_list").val('');
311                             $('#add_to_patron_list').change();
312                         }
313                     },
314                     error: function() {
315                         alert("an error occurred");
316                     }
317                 });
318                 return true;
319             });
320             $(".filterByLetter").on("click",function(e){
321                 e.preventDefault();
322                 filterByFirstLetterSurname($(this).text());
323             });
324             $("#select_all").on("click",function(e){
325                 e.preventDefault();
326                 $(".selection").prop("checked", true).change();
327             });
328             $("#clear_all").on("click",function(e){
329                 e.preventDefault();
330                 $(".selection").prop("checked", false).change();
331             });
332             $("#clear_search").on("click",function(e){
333                 e.preventDefault();
334                 clearFilters(true);
335             });
336             $("#searchform").on("submit", filter);
337
338         });
339
340         var dtMemberResults;
341         var search = 1;
342         $(document).ready(function() {
343             [% IF searchmember %]
344                 $("#searchmember_filter").val("[% searchmember | html %]");
345             [% END %]
346             [% IF searchfieldstype %]
347                 $("searchfieldstype_filter").val("[% searchfieldstype | html %]");
348             [% END %]
349             [% IF searchtype %]
350                 $("#searchtype_filter").val("[% searchtype | html %]");
351             [% END %]
352             [% IF categorycode %]
353                 $("#categorycode_filter").val("[% categorycode_filter | html %]");
354             [% END %]
355             [% IF branchcode %]
356                 $("#branchcode_filter").val("[% branchcode_filter | html %]");
357             [% END %]
358
359             [% IF view != "show_results" %]
360                 search = 0;
361             [% ELSE %]
362                 $("#searchresults").show();
363             [% END %]
364
365             // Build the aLengthMenu
366             var aLengthMenu = [
367                 [% PatronsPerPage | html %], 10, 20, 50, 100, -1
368             ];
369             jQuery.unique(aLengthMenu);
370             aLengthMenu.sort(function( a, b ){
371                 // Put "All" at the end
372                 if ( a == -1 ) {
373                     return 1;
374                 } else if ( b == -1 ) {
375                     return -1;
376                 }
377                 return parseInt(a) < parseInt(b) ? -1 : 1;}
378             );
379             var aLengthMenuLabel = [];
380             $(aLengthMenu).each(function(){
381                 if ( this == -1 ) {
382                     // Label for -1 is "All"
383                     aLengthMenuLabel.push(_("All"));
384                 } else {
385                     aLengthMenuLabel.push(this);
386                 }
387             });
388
389             // Apply DataTables on the results table
390             var columns_settings = [% TablesSettings.GetColumns( 'members', 'member', 'memberresultst', 'json' ) | $raw %];
391             [% UNLESS CAN_user_borrowers_edit_borrowers OR CAN_user_tools_manage_patron_lists %]
392                 [%# Remove the first column if we do not display the checkbox %]
393                 columns_settings.splice(0, 1);
394             [% END %]
395             dtMemberResults = KohaTable("memberresultst", {
396                 'bServerSide': true,
397                 'sAjaxSource': "/cgi-bin/koha/svc/members/search",
398                 'fnServerData': function(sSource, aoData, fnCallback) {
399                     if ( ! search ) {
400                         return;
401                     }
402                     aoData.push({
403                         'name': 'searchmember',
404                         'value': $("#searchmember_filter").val()
405                     },{
406                         'name': 'firstletter',
407                         'value': $("#firstletter_filter").val()
408                     },{
409                         'name': 'searchfieldstype',
410                         'value': $("#searchfieldstype_filter").val()
411                     },{
412                         'name': 'searchtype',
413                         'value': $("#searchtype_filter").val()
414                     },{
415                         'name': 'categorycode',
416                         'value': $("#categorycode_filter").val()
417                     },{
418                         'name': 'branchcode',
419                         'value': $("#branchcode_filter").val()
420                     },{
421                         'name': 'name_sorton',
422                         'value': 'borrowers.surname borrowers.firstname'
423                     },{
424                         'name': 'cardnumber_sorton',
425                         'value': 'borrowers.cardnumber',
426                     },{
427                         'name': 'dateofbirth_sorton',
428                         'value': 'borrowers.dateofbirth',
429                     },{
430                         'name': 'dateexpiry_sorton',
431                         'value': 'borrowers.dateexpiry',
432                     },{
433                         'name': 'category_sorton',
434                         'value': 'categories.description',
435                     },{
436                         'name': 'branch_sorton',
437                         'value': 'branches.branchname'
438                     },{
439                         'name': 'borrowernotes_sorton',
440                         'value': 'borrowers.borrowernotes'
441                     },{
442                         'name': 'template_path',
443                         'value': 'members/tables/members_results.tt',
444                     });
445                     $.ajax({
446                         'dataType': 'json',
447                         'type': 'POST',
448                         'url': sSource,
449                         'data': aoData,
450                         'success': function(json){
451                             // redirect if there is only 1 result.
452                             if ( json.aaData.length == 1 ) {
453                                 var borrowernumber = json.aaData[0].borrowernumber;
454                                 document.location.href="/cgi-bin/koha/members/moremember.pl?borrowernumber="+borrowernumber;
455                                 return false;
456                             }
457                             fnCallback(json);
458                         }
459                     });
460                 },
461                 'aoColumns':[
462                     [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
463                       { 'mDataProp': 'dt_borrowernumber', 'bSortable': false },
464                     [% END %]
465                     { 'mDataProp': 'dt_cardnumber' },
466                     { 'mDataProp': 'dt_name' },
467                     { 'mDataProp': 'dt_dateofbirth' },
468                     { 'mDataProp': 'dt_category' },
469                     {
470                         'mDataProp': function ( oObj ) {
471                             if( !singleBranchMode &&  oObj.dt_branch == "[% Branches.GetLoggedInBranchname | html %]" ){
472                                 return "<span class=\"currentlibrary\">" + oObj.dt_branch + "</span>";
473                             } else {
474                                 return oObj.dt_branch;
475                             }
476                         }
477                     },
478                     { 'mDataProp': 'dt_dateexpiry' },
479                     { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
480                     { 'mDataProp': 'dt_fines', 'bSortable': false },
481                     { 'mDataProp': 'dt_borrowernotes' },
482                     { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
483                 ],
484                 'bFilter': false,
485                 'bAutoWidth': false,
486                 [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
487                     'aaSorting': [[2, 'asc']],
488                 [% ELSE %]
489                     'aaSorting': [[1, 'asc']],
490                 [% END %]
491                 "aLengthMenu": [aLengthMenu, aLengthMenuLabel],
492                 'sPaginationType': 'full_numbers',
493                 "iDisplayLength": [% PatronsPerPage | html %],
494                 "bProcessing": true,
495                 "initComplete": function(settings, json) {
496                     Sticky = $("#searchheader");
497                     Sticky.hcSticky({
498                         stickTo: "#searchresults",
499                         stickyClass: "floating"
500                     });
501                 }
502             }, columns_settings);
503             update_searched();
504         });
505
506         // Update the string "Results found ..."
507         function update_searched(){
508             var searched = $("#searchfieldstype_filter").find("option:selected").text();
509             if ( $("#searchmember_filter").val() ) {
510                 if ( $("#searchtype_filter").val() == 'start_with' ) {
511                     searched += _(" starting with ");
512                 } else {
513                     searched += _(" containing ");
514                 }
515                 searched += "'" + $("#searchmember_filter").val() + "'";
516             }
517             if ( $("#firstletter_filter").val() ) {
518                 searched += _(" begins with ") + "'" + $("#firstletter_filter").val() +"'";
519             }
520             if ( $("#categorycode_filter").val() ) {
521                 searched += _(" with category ") + "'" + $("#categorycode_filter").find("option:selected").text() + "'";
522             }
523             if ( $("#branchcode_filter").val() ) {
524                 searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
525             }
526             $("#searchpattern").text(searched);
527         }
528
529         // Redraw the table
530         function filter() {
531             $("#firstletter_filter").val('');
532             update_searched();
533             search = 1;
534             $("#searchresults").show();
535             dtMemberResults.fnDraw();
536             return false;
537         }
538
539         // User has clicked on the Clear button
540         function clearFilters(redraw) {
541             $("#searchform select").val('');
542             $("#firstletter_filter").val('');
543             $("#searchmember_filter").val('');
544             if(redraw) {
545                 search = 1;
546                 $("#searchresults").show();
547                 dtMemberResults.fnDraw();
548             }
549         }
550
551         // User has clicked on a letter
552         function filterByFirstLetterSurname(letter) {
553             clearFilters(false);
554             $("#firstletter_filter").val(letter);
555             update_searched();
556             search = 1;
557             $("#searchresults").show();
558             dtMemberResults.fnDraw();
559         }
560     </script>
561 [% END %]
562
563 [% INCLUDE 'intranet-bottom.inc' %]