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