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