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