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