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