Bug 28961: Use Flatpickr on tools pages
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / modborrowers.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% USE Categories %]
7 [% USE TablesSettings %]
8 [% SET footerjs = 1 %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Batch patron modification &rsaquo; Tools &rsaquo; Koha</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 </head>
13
14 <body id="tools_modborrowers" class="tools">
15 [% INCLUDE 'header.inc' %]
16 [% INCLUDE 'cat-search.inc' %]
17
18 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
19     <ol>
20         <li>
21             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
22         </li>
23         <li>
24             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
25         </li>
26         <li>
27             <a href="#" aria-current="page">Batch patron modification</a>
28         </li>
29     </ol>
30 </nav>
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 ( op == 'show_form' ) %]
38                 <h1>Batch patron modification</h1>
39                 <form id="patron_batchmod_form" method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/modborrowers.pl">
40                     <input type="hidden" name="op" value="show" />
41                     <div id="batch_patron_options" class="toptabs">
42                         <ul>
43                             <li>
44                                 <a href="#usecardnumber">By card number</a>
45                             </li>
46                             <li>
47                                 <a href="#useborrowernumber">By borrowernumber</a>
48                             </li>
49                             [% IF patron_lists %]
50                                 <li>
51                                     <a href="#uselist">By patron list</a>
52                                 </li>
53                             [% END %]
54                         </ul>
55                         <div id="usecardnumber">
56                             <fieldset class="rows">
57                                 <legend>Use a file of card numbers</legend>
58                                 <ol>
59                                     <li>
60                                         <label for="cardnumberuploadfile">File: </label> <input type="file" id="cardnumberuploadfile" name="cardnumberuploadfile" />
61                                         <div class="hint">File must contain one card number per line.</div>
62                                     </li>
63                                 </ol>
64                             </fieldset>
65                             <fieldset class="rows">
66                                 <legend>Or list card numbers one by one</legend>
67                                 <ol>
68                                     <li>
69                                     <label for="cardnumberlist">Card number list (one card number per line): </label>
70                                     <textarea rows="10" cols="30" id="cardnumberlist" name="cardnumberlist">[% cardnumberlist | html %]</textarea>
71                                     </li>
72                                 </ol>
73                             </fieldset>
74                     <fieldset class="action">
75                         <input type="submit" value="Continue" class="button" />
76                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
77                     </fieldset>
78                         </div>
79                         <div id="useborrowernumber">
80                             <fieldset class="rows">
81                                 <legend>Use a file of borrowernumbers</legend>
82                                 <ol>
83                                     <li>
84                                         <label for="borrowernumberuploadfile">File: </label> <input type="file" id="borrowernumberuploadfile" name="borrowernumberuploadfile" />
85                                         <div class="hint">File must contain one borrowernumber per line.</div>
86                                     </li>
87                                 </ol>
88                             </fieldset>
89                             <fieldset class="rows">
90                                 <legend>List borrowernumbers one by one</legend>
91                                 <ol>
92                                     <li>
93                                     <label for="borrowernumberlist">Borrowernumber list (one number per line): </label>
94                                     <textarea rows="10" cols="30" id="borrowernumberlist" name="borrowernumberlist">[% borrowernumberlist | html %]</textarea>
95                                     </li>
96                                 </ol>
97                             </fieldset>
98                     <fieldset class="action">
99                         <input type="submit" value="Continue" class="button" />
100                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
101                     </fieldset>
102                         </div>
103                         [% IF patron_lists %]
104                             <div id="uselist">
105                                 <fieldset class="rows">
106                                     <legend>Use a patron list</legend>
107                                     <ol>
108                                         <li>
109                                             <label for="patron_list_id">Patron list: </label>
110                                             <select id="patron_list_id" name="patron_list_id">
111                                                 <option value=""> -- Choose a patron list -- </option>
112                                                 [% FOREACH pl IN patron_lists %]
113                                                     <option value="[% pl.patron_list_id | html %]">[% pl.name | html %]</option>
114                                                 [% END %]
115                                             </select>
116                                         </li>
117                                     </ol>
118                                 </fieldset>
119                     <fieldset class="action">
120                         <input type="submit" value="Continue" class="button" />
121                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
122                     </fieldset>
123                             </div>
124                         [% END %]
125                     </div><!-- /#batch_patron_options -->
126                 </form>
127                 [% END %]
128
129                 [% IF ( op == 'show') && (!borrowers) && (!notfoundcardnumbers) # Alert if no patrons given%]
130                     [% op = 'noshow' # Change op to prevent display in code below %]
131                     <h1>Batch patrons modification</h1>
132                     <div class="dialog alert">
133                         <p>No patron card numbers or borrowernumbers given.</p>
134                         <form action="/cgi-bin/koha/tools/modborrowers.pl" method="get">
135                          <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> OK</button>
136                         </form>
137                     </div>
138                 [% END #Alert if no patrons %]
139
140                 [% IF ( op == 'show' or op == 'show_results' ) %]
141                     [% IF ( op == 'show' ) %]
142                         <h1>Batch patrons modification</h1>
143                     [% ELSE %]
144                         <h1>Batch patrons results</h1>
145                     [% END %]
146                     [% IF ( notfoundcardnumbers ) %]
147                         [% IF ( useborrowernumbers ) -%]
148                             <div class="dialog alert"><p>Warning, the following borrowernumbers were not found:</p></div>
149                         [% ELSE -%]
150                             <div class="dialog alert"><p>Warning, the following card numbers were not found:</p></div>
151                         [% END %]
152
153                         <table style="margin:auto;">
154                             <thead>
155                                 [% IF ( useborrowernumbers ) -%]
156                                     <tr><th>Borrowernumbers not found</th></tr>
157                                 [% ELSE -%]
158                                     <tr><th>Card numbers not found</th></tr>
159                                 [% END %]
160                             </thead>
161                             <tbody>
162                                 [% FOREACH notfoundcardnumber IN notfoundcardnumbers %]
163                                     <tr><td>[% notfoundcardnumber.cardnumber | html %]</td></tr>
164                                 [% END %]
165                             </tbody>
166                         </table>
167                     [% END %]
168
169                     [% IF ( op == 'show_results' ) %]
170                         [% IF ( errors ) %]
171                             <div class="dialog alert">
172                             <h4>Errors occurred:</h4>
173                             <ul class="warnings">
174                             [% FOREACH error IN errors %]
175                                 [% IF ( error.error == 'can_not_update' ) %]
176                                     <li>Can not update patron.
177                                     [% IF ( error.cardnumber ) %] Card number:  [% error.cardnumber | html %] [% END %]
178                                     (Borrowernumber: [% error.borrowernumber | html %])
179                                     </li>
180                                 [% ELSE %]
181                                     <li>[% error.error | html %]</li>
182                                 [% END %]
183                             [% END %]
184                             </ul>
185                             </div>
186                         [% END %]
187                     [% END %]
188
189                     [% IF ( op == 'show' ) %]
190                     <form name="f" action="modborrowers.pl" method="post">
191                         <input type="hidden" name="op" value="do" />
192                         [% IF ( borrowers ) %]
193                             <div id="toolbar"><a id="selectallbutton" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="clearallbutton" href="#"><i class="fa fa-remove"></i> Clear all</a></div>
194                         [% END %]
195                     [% END %]
196                         [% IF borrowers %]
197                             <div id="cataloguing_additem_itemlist">
198                                 <div style="overflow:auto">
199                                     <table id="borrowerst">
200                                         <thead>
201                                             <tr>
202                                                 [% IF ( op == 'show' ) %]
203                                                     <th class="NoSort">&nbsp;</th>
204                                                 [% ELSE %]
205                                                     <th class="hidden">&nbsp;</th>
206                                                 [% END %]
207                                                 <th>Card number</th>
208                                                 <th>Surname</th>
209                                                 <th>First name</th>
210                                                 <th>Library</th>
211                                                 <th>Patron category</th>
212                                                 <th>Street number</th>
213                                                 <th>Address</th>
214                                                 <th>Address 2</th>
215                                                 <th>City</th>
216                                                 <th>State</th>
217                                                 <th>ZIP/Postal code</th>
218                                                 <th>Country</th>
219                                                 <th>Primary email</th>
220                                                 <th>Phone</th>
221                                                 <th>Mobile</th>
222                                                 <th>Registration date</th>
223                                                 <th>Expiry date</th>
224                                                 <th>Circulation note</th>
225                                                 <th>OPAC note</th>
226                                                 <th>Restriction expiration</th>
227                                                 <th>Restriction comment</th>
228                                                 [% FOREACH attrh IN attributes_header %]
229                                                     <th>[% attrh.attribute | html %]</th>
230                                                 [% END %]
231                                             </tr>
232                                         </thead>
233                                         <tbody>
234                                             [% FOREACH borrower IN borrowers %]
235                                                 <tr>
236                                                     [% IF ( op == 'show' ) %]
237                                                         <td>
238                                                     [% ELSE %]
239                                                         <td class="hidden">
240                                                     [% END %]
241                                                         <input type="checkbox" name="borrowernumber" value="[% borrower.borrowernumber | html %]" checked="checked" />
242                                                     </td>
243                                                     <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber | uri %]">[% borrower.cardnumber | html %]</a></td>
244                                                     <td>[% borrower.surname | html %]</td>
245                                                     <td>[% borrower.firstname | html %]</td>
246                                                     <td>[% Branches.GetName( borrower.branchcode ) | html %]</td>
247                                                     <td>[% Categories.GetName(borrower.categorycode) | html %]</td>
248                                                     <td>[% borrower.streetnumber | html %]</td>
249                                                     <td>[% borrower.address | html %]</td>
250                                                     <td>[% borrower.address2 | html %]</td>
251                                                     <td>[% borrower.city | html %]</td>
252                                                     <td>[% borrower.state | html %]</td>
253                                                     <td>[% borrower.zipcode | html %]</td>
254                                                     <td>[% borrower.country | html %]</td>
255                                                     <td>[% borrower.email | html %]</td>
256                                                     <td>[% borrower.phone | html %]</td>
257                                                     <td>[% borrower.mobile | html %]</td>
258                                                     <td data-order="[% borrower.dateenrolled | html %]">[% borrower.dateenrolled | $KohaDates %]</td>
259                                                     <td data-order="[% borrower.dateexpiry | html %]">[% borrower.dateexpiry | $KohaDates %]</td>
260                                                     <td>[% borrower.borrowernotes | html %]</td>
261                                                     <td>[% borrower.opacnote | html %]</td>
262                                                     <td data-order="[% borrower.debarred | html %]">[% borrower.debarred | $KohaDates %]</td>
263                                                     <td>[% borrower.debarredcomment | html %]</td>
264                                                     [% FOREACH pa IN borrower.patron_attributes %]
265                                                         [% IF ( pa.code ) %]
266                                                         [%# Replace pa.attribute with pa.description if we prefer to display the description %]
267                                                             <td>[% pa.code | html %]=[% pa.attribute | html %]</td>
268                                                         [% ELSE %]
269                                                             <td></td>
270                                                         [% END %]
271                                                     [% END %]
272                                                 </tr>
273                                             [% END %]
274                                         </tbody>
275                                     </table>
276                                 </div>
277                             </div>
278
279                             [% IF ( op == 'show' ) %]
280                             <div id="cataloguing_additem_newitem">
281                                 <h2>Edit patrons</h2>
282                                 <div class="hint">Checking the box right next to the label will disable the entry and delete the values of that field on all selected patrons</div>
283                                 <fieldset class="rows" id="fields_list">
284                                     <ol>
285                                         [% FOREACH field IN fields %]
286                                         <li>
287                                             [% IF ( field.mandatory ) %]
288                                             <label for="[% field.name | html %]" class="required">
289                                             [% ELSE %]
290                                             <label for="[% field.name | html %]">
291                                             [% END %]
292                                             [% SWITCH ( field.name ) %]
293                                                 [% CASE 'surname' %]
294                                                 Surname:
295                                                 [% CASE 'firstname' %]
296                                                 First name:
297                                                 [% CASE 'branchcode' %]
298                                                 Library:
299                                                 [% CASE 'categorycode' %]
300                                                 Patron category:
301                                                 [% CASE 'streetnumber' %]
302                                                 Street number:
303                                                 [% CASE 'address' %]
304                                                 Address:
305                                                 [% CASE 'address2' %]
306                                                 Address 2:
307                                                 [% CASE 'city' %]
308                                                 City:
309                                                 [% CASE 'state' %]
310                                                 State:
311                                                 [% CASE 'zipcode' %]
312                                                 ZIP/Postal code:
313                                                 [% CASE 'country' %]
314                                                 Country:
315                                                 [% CASE 'email' %]
316                                                 Primary email:
317                                                 [% CASE 'phone' %]
318                                                 Phone:
319                                                 [% CASE 'mobile' %]
320                                                 Mobile:
321                                                 [% CASE 'sort1' %]
322                                                 Sort 1:
323                                                 [% CASE 'sort2' %]
324                                                 Sort 2:
325                                                 [% CASE 'dateenrolled' %]
326                                                 Registration date:
327                                                 [% CASE 'dateexpiry' %]
328                                                 Expiry date:
329                                                 [% CASE 'borrowernotes' %]
330                                                 Circulation note:
331                                                 [% CASE 'opacnote' %]
332                                                 OPAC note:
333                                                 [% CASE 'debarred' %]
334                                                 Restriction expiration:
335                                                 [% CASE 'debarredcomment' %]
336                                                 Restriction comment:
337                                             [% END %]
338                                             </label>
339                                             [% IF ( field.type == 'text' ) %]
340                                                 <input type="text" name="[% field.name | html %]" value="" />
341                                             [% END %]
342                                             [% IF ( field.type == 'select' ) %]
343                                                 [% IF field.option.size %]
344                                                     <select name="[% field.name | html %]" >
345                                                         [% FOREACH opt IN field.option %]
346                                                             <option value="[% opt.value | html %]">[% opt.lib | html %]</option>
347                                                         [% END %]
348                                                     </select>
349                                                 [% ELSE %]
350                                                     There is no value defined for [% field.name | html %]
351                                                 [% END %]
352                                             [% END %]
353                                             [% IF ( field.type == 'date' ) %]
354                                                 <input type="text" name="[% field.name | html %]" id="[% field.name | html %]" value="" size="10" maxlength="10" class="flatpickr" />
355                                                 <a href="#"  class="clear-date" id="clear-date-[% field.name | html %]" ><i class="fa fa-fw fa-trash"></i> Clear</a>
356                                             [% END %]
357                                             [% IF field.mandatory %]
358                                                 <input type="checkbox" title="This field is mandatory" name="disable_input" value="[% field.name | html %]" disabled="disabled" readonly="readonly" />
359                                                 <span class="required">Required fields cannot be cleared</span>
360                                             [% ELSE %]
361                                                 <input type="checkbox" title="Check to delete this field" name="disable_input" value="[% field.name | html %]" />
362                                             [% END %]
363                                         </li>
364                                         [% END %]
365                                         [% IF ( patron_attributes_codes ) %]
366                                             <li class="attributes">
367                                                 <label style="width:auto;">Patron attribute:
368                                                     <select name="patron_attributes">
369                                                         <option value=""></option>
370                                                         [% FOREACH pac IN patron_attributes_codes %]
371                                                             <option value="[% pac.attribute_code | html %]" data-type="[% pac.type | html %]" data-category="[% pac.category_lib | html %]">[% pac.attribute_lib | html %]</option>
372                                                         [% END %]
373                                                     </select>
374                                                 </label>
375                                                 <input type="checkbox" title="check to delete this field" name="disable_input" value="attr0_value" />
376                                                 <span class="patron_attributes_value"><input type"hidden" name="patron_attributes_value" /></span>
377                                                 <a href="#" class="add_attributes" title="Add an attribute"><i class="fa fa-fw fa-plus"></i> New</a>
378                                                 <span class="information_category hint" style="width:25%;float:right;"></span>
379                                             </li>
380                                         [% END %]
381                                     </ol>
382                                 </fieldset>
383                                 <fieldset class="action">
384                                     <input type="submit" name="mainformsubmit" value="Save" />
385                                     <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a>
386                                 </fieldset>
387                             </div>
388                         </form>
389                         [% END %]
390                     [% END %]
391                 [% END %]
392                 [% IF ( op == 'show_results' ) %]
393                 <p>
394                     <a href="/cgi-bin/koha/tools/modborrowers.pl" title="New batch patrons modification">New batch patron modification</a>
395                 </p>
396                 [% END %]
397
398             </main>
399         </div> <!-- /.col-sm-10.col-sm-push-2 -->
400
401         <div class="col-sm-2 col-sm-pull-10">
402             <aside>
403                 [% INCLUDE 'tools-menu.inc' %]
404             </aside>
405         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
406      </div> <!-- /.row -->
407
408 [% MACRO jsinclude BLOCK %]
409     [% INCLUDE 'calendar.inc' %]
410     [% INCLUDE 'datatables.inc' %]
411     [% INCLUDE 'columns_settings.inc' %]
412     [% Asset.js("js/tools-menu.js") | $raw %]
413     <script>
414         var patron_attributes_lib = new Array();
415         var patron_attributes_values = new Array();
416         var table_settings = [% TablesSettings.GetColumns( 'tools', 'batch_patron_modification', 'borrowerst', 'json' ) | $raw %];
417         [% FOREACH attrh IN attributes_header %]
418             table_settings.push({
419                 columname: "[% attrh.attribute | html %]",
420                 cannot_be_modified: 0,
421                 cannot_be_toggled: 0,
422                 is_hidden: 0
423             });
424         [% END %]
425         $(document).ready(function() {
426             [% IF borrowers %]
427                 KohaTable("borrowerst", {
428                     "order": [[ 1, "asc" ]],
429                     "autoWidth": false,
430                     "columnDefs": [
431                         { "visible": false, "targets" : [ "hidden" ] }
432                     ]
433                 }, table_settings);
434
435                 $("#selectallbutton").click(function() {
436                     $("#borrowerst").find("input:checkbox").each(function() {
437                         $(this).prop("checked", true);
438                     });
439                     return false;
440                 });
441                 $("#clearallbutton").click(function() {
442                     $("#borrowerst").find("input:checkbox").each(function() {
443                         $(this).prop("checked", false);
444                     });
445                     return false;
446                 });
447             [% ELSE %]
448                 $("#batch_patron_options").tabs();
449             [% END %]
450
451             var values = new Array();
452             var lib = new Array();
453             [% FOREACH pav IN patron_attributes_values %]
454                 values = new Array();
455                 lib = new Array();
456                 [% FOREACH option IN pav.options %]
457                     values.push("[% option.lib | html %]");
458                     lib.push("[% option.authorised_value | html %]");
459                 [% END %]
460                 patron_attributes_lib["[% pav.attribute_code | html %]"] = values;
461                 patron_attributes_values["[% pav.attribute_code | html %]"] = lib;
462             [% END %]
463
464             $('select[name="patron_attributes"]').change(function() {
465                 updateAttrValues(this);
466             } );
467
468             $('select[name="patron_attributes"]').change();
469
470             $(".clear-date").on("click",function(e){
471                 e.preventDefault();
472                 var fieldID = this.id.replace("clear-date-","");
473                 $("#" + fieldID).val("");
474             });
475             $("#cataloguing_additem_newitem").on("click",".add_attributes",function(e){
476                 e.preventDefault();
477                 add_attributes();
478             });
479             $("#cataloguing_additem_newitem").on("click",".del_attributes",function(e){
480                 e.preventDefault();
481                 del_attributes(this);
482             });
483             $("#patron_batchmod_form").on("submit", function(){
484                 /* Reset form fields on inactive tabs */
485                 var tab = $(this).find('.ui-tabs-active:first a').attr('href');
486                 if ( tab == '#usecardnumber' ) {
487                     $("#borrowernumberuploadfile, #patron_list_id, #borrowernumberlist").val("");
488                 } else if ( tab == '#useborrowernumber' ) {
489                     $("#cardnumberuploadfile, #cardnumberlist, #patron_list_id").val("");
490                 } else { // uselist
491                     $("#borrowernumberuploadfile, #cardnumberuploadfile, #borrowernumberlist, #cardnumberlist").val("");
492                 }
493             });
494         });
495
496         function updateAttrValues (select_attr) {
497             var attr_code = $(select_attr).val();
498             var selected_option = $(select_attr).find("option:selected");
499             var type = $(selected_option).attr('data-type');
500             var category = $(selected_option).attr('data-category');
501             var li_node = $(select_attr).parent().parent();
502             var span = $(li_node).find('span.patron_attributes_value');
503             var information_category_node = $(li_node).find('span.information_category');
504             information_category_node.html("");
505
506             if ( category && category.length > 0 ) {
507                 information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
508             }
509             var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
510             if ( type == 'select' ) {
511                 var options = '<option value = ""></option>';
512                 for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
513                     options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
514                 }
515                 span.html('<select name="patron_attributes_value">' + options + '</select>');
516                 $(disable_input_node).show();
517             } else if ( $(selected_option).val() != "" ) {
518                 span.html('<input type="text" name="patron_attributes_value"/>');
519                 $(disable_input_node).show();
520             } else {
521                 span.html('<input type="hidden" name="patron_attributes_value" />');
522                 $(disable_input_node).hide();
523             }
524         }
525
526         function add_attributes() {
527             var li_node = $("li.attributes:last");
528             var li_clone = $(li_node).clone();
529             if ( $(li_clone).find("a.del_attributes").length == 0 ) {
530                 $(li_clone).append('<a href="#" title="' + _("Delete") + '" class="del_attributes"><i class="fa fa-fw fa-trash"></i> ' + _("Delete") + '</a>');
531             }
532             $(li_clone).find('select[name="patron_attributes"]').change(function() {
533                 updateAttrValues(this);
534             } );
535
536             $(li_clone).find('select[name="patron_attributes"]').change();
537
538             $("#fields_list>ol").append(li_clone);
539             update_attr_values();
540         }
541
542         function del_attributes(a_node) {
543             $(a_node).parent('li').remove();
544             update_attr_values();
545         }
546
547         function update_attr_values() {
548             $("li.attributes").each(function(i) {
549                 $(this).find("input:checkbox").val("attr"+i+"_value");
550             });
551         }
552         function clearDate(nodeid) {
553             $("#"+nodeid).val("");
554         }
555     </script>
556 [% END %]
557
558 [% INCLUDE 'intranet-bottom.inc' %]