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