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