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