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