Bug 28745: (bug 28158 follow-up) Restore the items table once the job is done
[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                     { 'mDataProp': 'dt_branch' },
469                     { 'mDataProp': 'dt_dateexpiry' },
470                     { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
471                     { 'mDataProp': 'dt_fines', 'bSortable': false },
472                     { 'mDataProp': 'dt_borrowernotes' },
473                     { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
474                 ],
475                 'bFilter': false,
476                 'bAutoWidth': false,
477                 [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
478                     'aaSorting': [[2, 'asc']],
479                 [% ELSE %]
480                     'aaSorting': [[1, 'asc']],
481                 [% END %]
482                 "aLengthMenu": [aLengthMenu, aLengthMenuLabel],
483                 'sPaginationType': 'full_numbers',
484                 "iDisplayLength": [% PatronsPerPage | html %],
485                 "bProcessing": true,
486                 "initComplete": function(settings, json) {
487                     Sticky = $("#searchheader");
488                     Sticky.hcSticky({
489                         stickTo: "#searchresults",
490                         stickyClass: "floating"
491                     });
492                 }
493             }, columns_settings);
494             update_searched();
495         });
496
497         // Update the string "Results found ..."
498         function update_searched(){
499             var searched = $("#searchfieldstype_filter").find("option:selected").text();
500             if ( $("#searchmember_filter").val() ) {
501                 if ( $("#searchtype_filter").val() == 'start_with' ) {
502                     searched += _(" starting with ");
503                 } else {
504                     searched += _(" containing ");
505                 }
506                 searched += "'" + $("#searchmember_filter").val() + "'";
507             }
508             if ( $("#firstletter_filter").val() ) {
509                 searched += _(" begins with ") + "'" + $("#firstletter_filter").val() +"'";
510             }
511             if ( $("#categorycode_filter").val() ) {
512                 searched += _(" with category ") + "'" + $("#categorycode_filter").find("option:selected").text() + "'";
513             }
514             if ( $("#branchcode_filter").val() ) {
515                 searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
516             }
517             $("#searchpattern").text(searched);
518         }
519
520         // Redraw the table
521         function filter() {
522             $("#firstletter_filter").val('');
523             update_searched();
524             search = 1;
525             $("#searchresults").show();
526             dtMemberResults.fnDraw();
527             return false;
528         }
529
530         // User has clicked on the Clear button
531         function clearFilters(redraw) {
532             $("#searchform select").val('');
533             $("#firstletter_filter").val('');
534             $("#searchmember_filter").val('');
535             if(redraw) {
536                 search = 1;
537                 $("#searchresults").show();
538                 dtMemberResults.fnDraw();
539             }
540         }
541
542         // User has clicked on a letter
543         function filterByFirstLetterSurname(letter) {
544             clearFilters(false);
545             $("#firstletter_filter").val(letter);
546             update_searched();
547             search = 1;
548             $("#searchresults").show();
549             dtMemberResults.fnDraw();
550         }
551     </script>
552 [% END %]
553
554 [% INCLUDE 'intranet-bottom.inc' %]