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