Bug 9811: Remove useless orderby management
[koha.git] / 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' },
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     }));
217     update_searched();
218 });
219
220 // Update the string "Results found ..."
221 function update_searched(){
222     var searched = "";
223     searched += "on " + $("#searchfieldstype_filter").find("option:selected").text().toLowerCase() + " fields";
224     if ( $("#searchmember_filter").val() ) {
225         if ( $("#searchtype_filter").val() == 'start_with' ) {
226             searched += _(" starting with ");
227         } else {
228             searched += _(" containing ");
229         }
230         searched += $("#searchmember_filter").val();
231     }
232     if ( $("#firstletter_filter").val() ) {
233         searched += _(" begin with ") + $("#firstletter_filter").val();
234     }
235     if ( $("#categorycode_filter").val() ) {
236         searched += _(" with category ") + $("#categorycode_filter").find("option:selected").text();
237     }
238     if ( $("#branchcode_filter").val() ) {
239         searched += _(" in library ") + $("#branchcode_filter").find("option:selected").text();
240     }
241     $("#searchpattern").text("for patron " + searched);
242 }
243
244 // Redraw the table
245 function filter() {
246     $("#firstletter_filter").val('');
247     update_searched();
248     search = 1;
249     $("#searchresults").show();
250     dtMemberResults.fnDraw();
251     return false;
252 }
253
254 // User has clicked on the Clear button
255 function clearFilters(redraw) {
256     $("#searchform select").val('');
257     $("#firstletter_filter").val('');
258     $("#searchmember_filter").val('');
259     if(redraw) {
260         search = 1;
261         $("#searchresults").show();
262         dtMemberResults.fnDraw();
263     }
264 }
265
266 // User has clicked on a letter
267 function filterByFirstLetterSurname(letter) {
268     clearFilters(false);
269     $("#firstletter_filter").val(letter);
270     update_searched();
271     search = 1;
272     $("#searchresults").show();
273     dtMemberResults.fnDraw();
274 }
275 //]]>
276 </script>
277 </head>
278 <body id="pat_member" class="pat">
279 [% INCLUDE 'header.inc' %]
280 [% INCLUDE 'patron-search.inc' %]
281
282 <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>
283
284 <div id="doc3" class="yui-t2">
285   <div id="bd">
286     <div id="yui-main">
287       <div class="yui-b">
288         <div class="yui-g">
289           [% IF CAN_user_tools_manage_patron_lists %]
290             <div id="patron_list_dialog" class="dialog alert">
291               Added <span class="patrons-length"></span> patrons to <a></a>.
292             </div>
293           [% END %]
294
295           [% INCLUDE 'patron-toolbar.inc' %]
296           [% IF ( no_add ) %]
297             <div class="dialog alert">
298               <h3>Cannot add patron</h3>
299               [% IF ( no_branches ) %]
300                 <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>
301               [% END %]
302               [% IF ( no_categories ) %]
303                 <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>
304               [% END %]
305             </div>
306           [% END %]
307           <div class="browse">
308             Browse by last name:
309             [% FOREACH letter IN alphabet.split(' ') %]
310               <a style="cursor:pointer" onclick="filterByFirstLetterSurname('[% letter %]');">[% letter %]</a>
311             [% END %]
312           </div>
313
314           [% IF ( CAN_user_borrowers && pending_borrower_modifications ) %]
315             <div class="pending-info" id="patron_updates_pending">
316               <a href="/cgi-bin/koha/members/members-update.pl">Patrons requesting modifications</a>:
317               <span class="holdcount"><a href="/cgi-bin/koha/members/members-update.pl">[% pending_borrower_modifications %]</a></span>
318             </div>
319           [% END %]
320
321           <div id="searchresults">
322             <div id="searchheader">
323               <h3>Results found <span id="searchpattern">[% IF searchmember %] for '[% searchmember %]'[% END %]</span></h3>
324             </div>
325             [% IF CAN_user_tools_manage_patron_lists %]
326               <div id="searchheader">
327                   <div>
328                       <a href="javascript:void(0)" onclick="$('.selection').prop('checked', true)">Select all</a>
329                       |
330                       <a href="javascript:void(0)" onclick="$('.selection').prop('checked', false)">Clear all</a>
331                       |
332                       <span>
333                           Add selected patrons
334                           <label for="add_to_patron_list">to:</label>
335                           <select id="add_to_patron_list" name="add_to_patron_list">
336                               <option value=""></option>
337                               [% IF patron_lists %]
338                                   <optgroup label="Patron lists:">
339                                       [% FOREACH pl IN patron_lists %]
340                                           <option value="[% pl.patron_list_id %]">[% pl.name %]</option>
341                                       [% END %]
342                                   </optgroup>
343                               [% END %]
344
345                               <option value="new">[ New list ]</option>
346                           </select>
347
348                           <input type="text" id="new_patron_list" name="new_patron_list" id="new_patron_list" />
349
350                           <input id="add_to_patron_list_submit" type="submit" class="submit" value="Save">
351                       </span>
352                   </div>
353               </div>
354             [% END %]
355
356             <table id="memberresultst">
357               <thead>
358                 <tr>
359                   <th>&nbsp;</th>
360                   <th>Card</th>
361                   <th>Name</th>
362                   <th>Category</th>
363                   <th>Library</th>
364                   <th>Expires on</th>
365                   <th>OD/Checkouts</th>
366                   <th>Fines</th>
367                   <th>Circ note</th>
368                   <th>&nbsp;</th>
369                 </tr>
370               </thead>
371               <tbody></tbody>
372             </table>
373           </div>
374         </div>
375       </div>
376     </div>
377     <div class="yui-b">
378       <form onsubmit="return filter();" id="searchform">
379         <input type="hidden" id="firstletter_filter" value="" />
380         <fieldset class="brief">
381           <h3>Filters</h3>
382           <ol>
383             <li>
384               <label for="searchmember_filter">Search:</label>
385               <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
386             </li>
387             <li>
388               <label for="searchfieldstype_filter">Search fields:</label>
389               <select name="searchfieldstype" id="searchfieldstype_filter">
390                 [% IF searchfieldstype == "standard" %]
391                   <option selected="selected" value='standard'>Standard</option>
392                 [% ELSE %]
393                   <option value='standard'>Standard</option>
394                 [% END %]
395                 [% IF searchfieldstype == "email" %]
396                   <option selected="selected" value='email'>Email</option>
397                 [% ELSE %]
398                   <option value='email'>Email</option>
399                 [% END %]
400                 [% IF searchfieldstype == "borrowernumber" %]
401                   <option selected="selected" value='borrowernumber'>Borrower number</option>
402                 [% ELSE %]
403                   <option value='borrowernumber'>Borrower number</option>
404                 [% END %]
405                 [% IF searchfieldstype == "phone" %]
406                   <option selected="selected" value='phone'>Phone number</option>
407                 [% ELSE %]
408                   <option value='phone'>Phone number</option>
409                 [% END %]
410                 [% IF searchfieldstype == "address" %]
411                   <option selected="selected" value='address'>Street address</option>
412                 [% ELSE %]
413                   <option value='address'>Street address</option>
414                 [% END %]
415                 [% IF searchfieldstype == "dateofbirth" %]
416                   <option selected="selected" value='dateofbirth'>Date of birth</option>
417                 [% ELSE %]
418                   <option value='dateofbirth'>Date of birth</option>
419                 [% END %]
420                 [% IF searchfieldstype == "sort1" %]
421                   <option selected="selected" value='sort1'>Sort field 1</option>
422                 [% ELSE %]
423                   <option value='sort1'>Sort field 1</option>
424                 [% END %]
425                 [% IF searchfieldstype == "sort2" %]
426                   <option selected="selected" value='sort2'>Sort field 2</option>
427                 [% ELSE %]
428                   <option value='sort2'>Sort field 2</option>
429                 [% END %]
430               </select>
431             </li>
432             <li>
433               <label for="searchtype_filter">Search type:</label>
434               <select name="searchtype" id="searchtype_filter">
435                 <option value='start_with'>Starts with</option>
436                 [% IF searchtype == "contain" %]
437                   <option value="contain" selected="selected">Contains</option>
438                 [% ELSE %]
439                   <option value="contain" selected="selected">Contains</option>
440                 [% END %]
441               </select>
442             </li>
443             <li>
444               <label for="categorycode_filter">Category:</label>
445               <select id="categorycode_filter">
446                 <option value="">Any</option>
447                 [% FOREACH cat IN categories %]
448                   [% IF cat.selected %]
449                     <option selected="selected" value="[% cat.categorycode %]">[% cat.description | html_entity %]</option>
450                   [% ELSE %]
451                     <option value="[% cat.categorycode %]">[% cat.description | html_entity %]</option>
452                   [% END %]
453                 [% END %]
454               </select>
455             </li>
456             <li>
457               <label for="branchcode_filter">Branch:</label>
458               <select id="branchcode_filter">
459                 [% IF branchloop.size != 1 %]
460                   <option value="">Any</option>
461                 [% END %]
462                 [% FOREACH b IN branchloop %]
463                   [% IF b.selected %]
464                     <option selected="selected" value="[% b.branchcode %]">[% b.branchname %]</option>
465                   [% ELSE %]
466                     <option value="[% b.branchcode %]">[% b.branchname %]</option>
467                   [% END %]
468                 [% END %]
469               </select>
470             </li>
471           </ol>
472           <fieldset class="action">
473             <input type="submit" value="Search" />
474             <input type="button" value="Clear" onclick="clearFilters(true);" />
475           </fieldset>
476         </fieldset>
477       </form>
478     </div>
479   </div>
480   <div class="yui-g">
481     [% INCLUDE 'members-menu.inc' %]
482   </div>
483 </div>
484 [% INCLUDE 'intranet-bottom.inc' %]