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