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