Bug 34094: Use DefaultPatronSearchMethod consistently
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE TablesSettings %]
5 [% USE Branches %]
6 [% USE Categories %]
7 [% SET footerjs = 1 %]
8 [% PROCESS 'patronfields.inc' %]
9 [% SET libraries = Branches.all %]
10 [% SET categories = Categories.all.unblessed %]
11 [% SET columns = ['cardnumber', 'name-address', 'dateofbirth', 'branch', 'category', 'dateexpiry', 'checkouts', 'account_balance', 'borrowernotes', 'action'] %]
12 [% SET searchtype = Koha.Preference('DefaultPatronSearchMethod') %]
13 [% PROCESS 'patron-search.inc' %]
14 [% INCLUDE 'doc-head-open.inc' %]
15 <title>Patrons[% IF ( searching ) %] &rsaquo; Search results[% END %] &rsaquo; Koha</title>
16 [% INCLUDE 'doc-head-close.inc' %]
17 </head>
18
19 <body id="pat_member" class="pat">
20 [% WRAPPER 'header.inc' %]
21     [% INCLUDE 'patron-search-header.inc' %]
22 [% END %]
23
24 [% WRAPPER 'sub-header.inc' %]
25     [% WRAPPER breadcrumbs %]
26         [% WRAPPER breadcrumb_item bc_active= 1 %]
27             Patrons
28         [% END %]
29     [% END #/ WRAPPER breadcrumbs %]
30 [% END #/ WRAPPER sub-header.inc %]
31
32 <div class="main container-fluid">
33     <div class="row">
34         <div class="col-sm-10 col-sm-push-2">
35             <main>
36
37           [% IF CAN_user_tools_manage_patron_lists %]
38             <div id="patron_list_dialog" class="dialog message">
39               Added <span class="patrons-length"></span> patrons to <a></a>.
40             </div>
41           [% END %]
42
43           [% INCLUDE 'patron-toolbar.inc' %]
44           [% INCLUDE 'noadd-warnings.inc' %]
45
46           [% IF CAN_user_borrowers_edit_borrowers && pending_borrower_modifications %]
47             <div class="pending-info" id="patron_updates_pending">
48               <a href="/cgi-bin/koha/members/members-update.pl">Patrons requesting modifications</a>:
49               <span class="number_box"><a href="/cgi-bin/koha/members/members-update.pl">[% pending_borrower_modifications | html %]</a></span>
50             </div>
51           [% END %]
52
53           <div id="searchresults">
54             [% IF CAN_user_tools_manage_patron_lists || CAN_user_borrowers_edit_borrowers %]
55               <div class="searchheader fh-fixedHeader" id="searchheader" style="display:none;">
56                   <div>
57                       <a href="#" class="btn btn-link" id="select_all"><i class="fa fa-check"></i> Select all</a>
58                       |
59                       <a href="#" class="btn btn-link" id="clear_all"><i class="fa fa-times"></i> Clear all</a>
60                     [% IF CAN_user_tools_manage_patron_lists %]
61
62                     [% END %]
63
64                     [% IF CAN_user_tools_manage_patron_lists %]
65                         <div id="patronlist-dropdown" class="btn-group">
66                             <button id="patronlist-menu" type="button" class="btn btn-sm btn-default dropdown-toggle patron-edits disabled" disabled="disabled" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
67                                 Add to patron list <span class="caret"></span>
68                             </button>
69                             <ul class="dropdown-menu">
70                                 [% IF patron_lists %]
71                                     [% FOREACH pl IN patron_lists %]
72                                         <li><a href="#" class="patron-list-add" data-listid="[% pl.patron_list_id | html %]">[% pl.name | html %]</a></li>
73                                     [% END %]
74                                 [% END %]
75                                 <li role="separator" class="divider"></li>
76                                 <li><a href="#" class="patron-list-add" data-listid="new">New list</a></li>
77                             </ul>
78                         </div>
79                     [% END %]
80
81                     [% IF CAN_user_borrowers_edit_borrowers %]
82                         <div class="btn-group">
83                             <button id="merge-patrons" class="btn btn-sm btn-default disabled" disabled="disabled" type="submit"><i class="fa fa-compress" aria-hidden="true"></i> Merge selected patrons</button>
84                         </div>
85                     [% END %]
86
87                     [% IF CAN_user_tools_edit_patrons %]
88                         <div class="btn-group">
89                             <button id="batch-mod-patrons" class="btn btn-default btn-sm" type="button"><i class="fa fa-pencil" aria-hidden="true"></i> Batch patron modification</button>
90                         </div>
91                     [% END %]
92
93                     <div id="patron_search_selected" class="btn-group" style="display:none;">
94                         <span></span>
95                         <a href="#" id="clear-patron-selection"><i class="fa fa-times"></i> Clear</a>
96                     </div>
97                   </div>
98                 </div>
99             [% END %]
100
101             [% IF CAN_user_borrowers_edit_borrowers || CAN_user_tools_manage_patron_lists %]
102                 [% columns.unshift('checkbox') | html %]
103             [% END %]
104             [% PROCESS patron_search_table table_id => 'memberresultst' columns => columns %]
105           </div>
106         [% IF CAN_user_tools_edit_patrons %]
107             <form id="patron_batchmod_form" method="post" action="/cgi-bin/koha/tools/modborrowers.pl">
108                 <input type="hidden" name="op" value="show" />
109                 <textarea style="display:none" id="borrowernumberlist" name="borrowernumberlist"></textarea>
110             </form>
111         [% END %]
112
113             </main>
114         </div> <!-- /.col-sm-10.col-sm-push-2 -->
115
116         <div class="col-sm-2 col-sm-pull-10">
117             <aside>
118                 [% PROCESS patron_search_filters categories => categories, libraries => libraries, filters => ['search_field', 'search_type', 'category', 'branch'], search_filter => searchmember %]
119             </aside>
120         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
121     </div> <!-- /.row -->
122
123     <!-- New Patron List Modal -->
124     <div class="modal" id="new-patron-list" tabindex="-1" role="dialog" aria-labelledby="new-patron-listLabel">
125         <div class="modal-dialog" role="document">
126             <div class="modal-content">
127                 <div class="modal-header">
128                     <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
129                     <h4 class="modal-title" id="new-patron-listLabel">Add patrons to a new patron list</h4>
130                 </div>
131                 <form id="new-patron-list_form">
132                     <div class="modal-body">
133                         <div class="form-group">
134                             <label for="new_patron_list" class="required">Patron list name: </label>
135                             <input class="form-control required" type="text" name="new_patron_list" id="new_patron_list" required="required" />
136                             <input type="hidden" name="add_to_patron_list" id="add_to_patron_list" />
137                             <span class="required">Required</span>
138                         </div>
139                     </div> <!-- /.modal-body -->
140                     <div class="modal-footer">
141                         <button type="submit" id="add_to_patron_list_submit" class="btn btn-default approve">Submit</button>
142                         <button type="button" class="btn btn-default deny" data-dismiss="modal">Cancel</button>
143                     </div> <!-- /.modal-footer -->
144                 </form> <!-- /#new-patron-list_form -->
145             </div> <!-- /.modal-content -->
146         </div> <!-- /.modal-dialog -->
147     </div> <!-- /#new-patron-list -->
148
149 [% MACRO jsinclude BLOCK %]
150     [% INCLUDE 'datatables.inc' %]
151     [% INCLUDE 'columns_settings.inc' %]
152     [% INCLUDE 'str/members-menu.inc' %]
153     [% Asset.js("js/members-menu.js") | $raw %]
154     <script>
155         function showPatronSelections( number ){
156             $("#patron_search_selected").show().find("span").text(_("Patrons selected: " + number ) );
157         }
158
159         $(document).ready(function() {
160             $('#merge-patrons, #batch-mod-patrons').prop('disabled', true);
161             $('#memberresultst').on('change', 'input.selection', function() {
162                 var patron_search_selections = JSON.parse( localStorage.getItem("patron_search_selections") ) || [];
163                 var borrowernumber = $(this).val();
164                 if( $(this).prop("checked") ){
165                     patron_search_selections.push( $(this).val() );
166                     localStorage.setItem('patron_search_selections', JSON.stringify( patron_search_selections ));
167                     showPatronSelections( patron_search_selections.length );
168                 } else {
169                     var filtered = patron_search_selections.filter(function( value ){
170                         return value !== borrowernumber;
171                     });
172                     if( filtered.length > 0 ){
173                         localStorage.setItem('patron_search_selections', JSON.stringify( filtered ));
174                         patron_search_selections = filtered;
175                         showPatronSelections( filtered.length );
176                     } else {
177                         patron_search_selections = [];
178                         localStorage.removeItem('patron_search_selections');
179                         $("#patron_search_selected").hide();
180                     }
181                 }
182                 if ( patron_search_selections.length > 1 ) {
183                     /* More than one checkbox has been checked. All batch options enabled */
184                     $("#batch-mod-patrons, #merge-patrons, #patronlist-menu").removeClass("disabled").prop("disabled", false);
185                 } else if ( patron_search_selections.length == 1 ) {
186                     /* Only one checkbox has been checked */
187                     $("#batch-mod-patrons, #patronlist-menu").removeClass("disabled").prop("disabled", false);
188                     /* Merge requires more than one selection */
189                     $('#merge-patrons').prop('disabled', true).addClass("disabled");
190                 } else {
191                     /* No checkbox has been checked. No batch options enabled */
192                     $("#batch-mod-patrons, #merge-patrons, #patronlist-menu").addClass("disabled").prop("disabled", true);
193                 }
194             });
195
196             $('#merge-patrons').on('click', function() {
197                 var patron_search_selections = JSON.parse( localStorage.getItem("patron_search_selections") ) || [];
198                 var merge_patrons_url = 'merge-patrons.pl?id=' + patron_search_selections.join("&id=");
199                 window.location.href = merge_patrons_url;
200             });
201
202             $("#clear-patron-selection").on("click", function(e){
203                 e.preventDefault();
204                 $("input.selection").prop("checked", false).change();
205                 localStorage.removeItem("patron_search_selections");
206                 $("#patron_search_selected").hide();
207                 $('#merge-patrons, #patronlist-menu, #batch-mod-patrons').prop('disabled', true).addClass("disabled");
208                 $("#borrowernumberlist").val("");
209             });
210
211             $("#patronlist-dropdown").on("click", ".patron-list-add", function(e){
212                 e.preventDefault();
213                 var patron_search_selections = JSON.parse( localStorage.getItem("patron_search_selections") ) || [];
214                 if ( patron_search_selections.length == 0 ) {
215                     alert( _("You have not selected any patrons to add to a list!") );
216                     $(".btn-group").removeClass("open"); /* Close button menu */
217                     return false;
218                 }
219
220                 var listid = $(this).data("listid");
221                 $("#add_to_patron_list").val( listid );
222                 if( listid == "new" ){
223                     /* #add_to_patron_list value "new" in the modal form will tell API to create a new list */
224                     $("#new-patron-list").modal("show");
225                 } else {
226                     /* Ajax submit the patrons to list */
227
228                     patronListAdd();
229                 }
230             });
231
232             $("#batch-mod-patrons").on("click", function(e) {
233                 e.preventDefault();
234                 var patron_search_selections = JSON.parse( localStorage.getItem("patron_search_selections") ) || [];
235                 if( patron_search_selections.length > 0 ){
236                     $("#borrowernumberlist").html( patron_search_selections.join('\n') );
237                     $("#patron_batchmod_form").submit();
238                 }
239             });
240
241             /* Submit selected patrons to a list via AJAX */
242             $("#new-patron-list_form").on('submit', function(e){
243                 e.preventDefault();
244                 /* Upon submitting modal patron list add form... */
245                 if ( $('#new_patron_list').val() ) {
246                     $(".patron-list-add").each(function() {
247                         /* Check each list name in the menu of patron lists */
248                         /* If submitted list name matches... */
249                         if ( $(this).text() == $('#new_patron_list').val() ) {
250                             alert( _("You already have a list with that name!") );
251                             return false;
252                         }
253                     });
254                 } else {
255                     alert( _("You must give your new patron list a name!") );
256                     return false;
257                 }
258                 $("#new-patron-list").modal("hide");
259                 patronListAdd();
260             });
261
262             $("#select_all").on("click",function(e){
263                 e.preventDefault();
264                 $("input.selection").each(function(){
265                     if( $(this).prop("checked") == false ){
266                         $(this).prop( "checked", true ).change();
267                     }
268                 });
269             });
270             $("#clear_all").on("click",function(e){
271                 e.preventDefault();
272                 $("input.selection").each(function(){
273                     if( $(this).prop("checked") ){
274                         $(this).prop("checked", false ).change();
275                     }
276                 });
277             });
278
279             [% IF searchmember %]
280                 $("#searchmember_filter").val("[% searchmember | html %]");
281             [% END %]
282             [% IF searchfieldstype %]
283                 $("searchfieldstype_filter").val("[% searchfieldstype | html %]");
284             [% END %]
285             [% IF searchtype %]
286                 $("#searchtype_filter option[value='[% searchtype | html %]']").prop("selected", true);
287             [% END %]
288             [% IF categorycode_filter %]
289                 $("#categorycode_filter").val("[% categorycode_filter | html %]");
290             [% END %]
291             [% IF branchcode_filter %]
292                 $("#branchcode_filter").val("[% branchcode_filter | html %]");
293             [% END %]
294
295             $("#searchheader").hide();
296             $("#patron_search_form").on('submit', function(){$("#searchheader").show();});
297             $("#clear_search").on("click",function(e){$("#searchheader").hide();});
298         });
299
300         function patronListAdd(){
301             var borrowernumbers = JSON.parse( localStorage.getItem("patron_search_selections") ) || [];
302             if ( borrowernumbers.length > 0 ){
303                 var data = {
304                     add_to_patron_list: $("#add_to_patron_list").val(),
305                     new_patron_list: $("#new_patron_list").val(),
306                     borrowernumbers: borrowernumbers
307                 };
308                 $.ajax({
309                     data: data,
310                     type: 'POST',
311                     url: '/cgi-bin/koha/svc/members/add_to_list',
312                     success: function(data) {
313                         $("#patron_list_dialog").show();
314                         $("#patron_list_dialog > span.patrons-length").html(data.patrons_added_to_list);
315                         $("#patron_list_dialog > a").attr("href", "/cgi-bin/koha/patron_lists/list.pl?patron_list_id=" + data.patron_list.patron_list_id);
316                         $("#patron_list_dialog > a").html(data.patron_list.name);
317
318                         if ( $('#add_to_patron_list').val() == 'new' ) {
319                             /* Add a new entry to the menu */
320                             $("#patronlist-dropdown .divider").before('<li><a class="patron-list-add" href="#" data-listid="' + data.patron_list.patron_list_id + '">' + data.patron_list.name + '</li>');
321                         }
322                     },
323                     error: function() {
324                         alert( _("An error occurred. Patron list could not be updated.") );
325                     }
326                 });
327                 return true;
328             } else {
329                 alert( _("You have not selected any patrons to add to a list!") );
330                 return false;
331             }
332         }
333
334         function prepSelections(){
335             var selected_patrons = JSON.parse( localStorage.getItem("patron_search_selections") );
336             if( selected_patrons && selected_patrons.length > 0 ){
337                 showPatronSelections( selected_patrons.length );
338
339                 $('#merge-patrons').prop('disabled', true);
340                 $("input.selection").each(function(){
341                     var cardnumber = $(this).val();
342                     if( selected_patrons.indexOf( cardnumber ) >= 0 ){
343                         $(this).prop("checked", true );
344                     }
345                 });
346
347                 if( selected_patrons.length > 1 ){
348                     $('#batch-mod-patrons, #merge-patrons, #patronlist-menu').removeClass("disabled").prop('disabled', false);
349                 }
350             }
351         }
352
353         $('#memberresultst tbody').on('click','td',function(e){
354             var $checkbox = $(this).find("input[type=checkbox]");
355             if (e.target.type != "checkbox") {
356                 $checkbox.prop('checked', !$checkbox.prop("checked"));
357                 $checkbox.change();
358             }
359         });
360
361     </script>
362
363     <script>
364         // Apply DataTables on the results table
365         var table_settings = [% TablesSettings.GetTableSettings( 'members', 'member', 'memberresultst', 'json' ) | $raw %];
366         [% UNLESS CAN_user_borrowers_edit_borrowers OR CAN_user_tools_manage_patron_lists %]
367             [%# Remove the first column if we do not display the checkbox %]
368             table_settings['columns'].splice(0, 1);
369         [% END %]
370     </script>
371
372     [% IF circsearch == 1 %]
373         [% SET redirect_url = '/cgi-bin/koha/circ/circulation.pl' %]
374     [% ELSE %]
375         [% SET redirect_url = '/cgi-bin/koha/members/moremember.pl' %]
376     [% END %]
377     [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns,actions => ['edit', 'checkout'], redirect_if_one_result => 1, redirect_url => redirect_url, sticky_header => "searchheader", sticky_to => "searchresults", default_sort_column => 'name-address', display_search_description => 1, remember_selections => 1 %]
378
379 [% END %]
380
381 [% INCLUDE 'intranet-bottom.inc' %]