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