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