Bug 34889: Convert PatronSelfRegistrationAdditionalInstructions system preference...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / patroncards / edit-batch.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% PROCESS 'i18n.inc' %]
4 [% SET footerjs = 1 %]
5     [% INCLUDE 'doc-head-open.inc' %]
6     <title>[% FILTER collapse %]
7         [% IF ( batch_id ) %]
8             [% t("Edit patron card batch") | html %] ([% batch_id | html %])
9         [% ELSE %]
10             [% t("New patron card batch") | html %]
11         [% END %] &rsaquo;
12         [% t("Batches") | html %] &rsaquo;
13         [% t("Patron card creator") | html %] &rsaquo;
14         [% t("Tools") | html %] &rsaquo;
15         [% t("Koha") | html %]
16     [% END %]</title>
17     [% INCLUDE 'doc-head-close.inc' %]
18 </head>
19
20 <body id="pcard_edit-batch" class="tools pcard">
21     [% WRAPPER 'header.inc' %]
22     [% INCLUDE 'cat-search.inc' %]
23 [% END %]
24
25     [% WRAPPER 'sub-header.inc' %]
26         [% WRAPPER breadcrumbs %]
27             [% WRAPPER breadcrumb_item %]
28                 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
29             [% END %]
30             [% WRAPPER breadcrumb_item %]
31                 <a href="/cgi-bin/koha/patroncards/home.pl">Patron card creator</a>
32             [% END %]
33             [% WRAPPER breadcrumb_item %]
34                 <a href="/cgi-bin/koha/patroncards/manage.pl?card_element=batch">Batches</a>
35             [% END %]
36             [% WRAPPER breadcrumb_item bc_active= 1 %]
37                 [% IF description %]
38                     <span>Edit [% description | html %]</span>
39                 [% ELSIF batch_id %]
40                     <span>Edit ([% batch_id | html %])</span>
41                 [% ELSE %]
42                     <span>New patron card batch</span>
43                 [% END %]
44             [% END %]
45         [% END #/ WRAPPER breadcrumbs %]
46     [% END #/ WRAPPER sub-header.inc %]
47
48     <div class="main container-fluid">
49         <div class="row">
50             <div class="col-sm-10 col-sm-push-2">
51                 <main>
52
53                     [% INCLUDE 'patroncards-toolbar.inc' %]
54
55                     <h1>[% IF description %]<span>Edit</span> [% description | html %]
56                         [% ELSIF batch_id %]<span>Edit patron card batch</span> [% batch_id | html %]
57                         [% ELSE %]<span>New patron card batch</span>[% END %]
58                     </h1>
59
60                 [% IF ( duplicate_message ) %]
61                     <div class="dialog message">
62                         <strong>Duplicate patrons removed from batch number [% batch_id | html %]: [% duplicate_count | html %]</strong>
63                     </div>
64                 [% END %]
65
66                     [% INCLUDE 'patroncards-errors.inc' %]
67                     <div id="manage-patroncard-batches">
68                             <form name="add_by_bor_num" action="/cgi-bin/koha/patroncards/edit-batch.pl" method="post">
69                                 <div>
70                                     <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
71                                     <ol><li id="description">
72                                         <input type="hidden" name="op" value="add" />
73                                         <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
74                                         <label for="description">Batch description: </label>
75                                         <input type="text" name="description" value="[% description | html %]"> <span id="change-status"></span>
76                                     </li><li>
77                                         <label for="bor_num_list">Add by borrowernumber(s):
78                                             <br /> <span class="hint">One borrowernumber per line.</span>
79                                         </label>
80                                         <textarea rows="5" id="bor_num_list" name="bor_num_list" tabindex="1" class="focus"></textarea>
81                                     </li></ol>
82                                     </fieldset>
83                                 </div>
84                             </form>
85                             <div id="batch-manage" class="action">
86                                 <a class="btn btn-default" id="additems" href="#"><i class="fa fa-plus"></i> Add patron(s)</a>[% IF ( table_loop ) %]
87                                 <a class="btn btn-default" id="savedesc" href="#" data-batch_id="[% batch_id | html %]"><i class="fa fa-save"></i> Save description</a>
88                                 <a class="btn btn-default" id="removeitems" href="#"><i class="fa fa-trash-can"></i> Remove selected patrons</a>
89                                 <a class="btn btn-default" id="deletebatch" href="#"><i class="fa fa-minus-square"></i> Delete batch</a>
90                                 <a class="btn btn-default" id="deduplicate" href="#"><i class="fa fa-minus"></i> Remove duplicates</a>
91                                 <a class="btn btn-default" id="exportitems" href="#"><i class="fa-solid fa-share-from-square"></i> Export selected card(s)</a>
92                                 <a class="btn btn-default" id="exportbatch" href="#"><i class="fa-solid fa-share-from-square"></i> Export card batch</a>[% END %]
93                             </div>
94                             [% IF ( table_loop ) %]
95                             <form name="items">
96                                 <h2>Patrons in batch number [% batch_id | html %]</h2>
97                                 <div class="page-section">
98                                     <table id="batcht">
99                                         [% FOREACH table_loo IN table_loop %]
100                                             [% IF ( table_loo.header_fields ) %]
101                                                 <thead>
102                                                     <tr>
103                                                         [% FOREACH header_field IN table_loo.header_fields %]
104                                                             [% SWITCH header_field.field_label -%]
105                                                                 [% CASE "Summary" -%]
106                                                                     <th>Patron name</th>
107                                                                 [% CASE "Borrower Number" %]
108                                                                     <th>Borrower number</th>
109                                                                 [% CASE "Actions " %]
110                                                                     <th class="noExport">Actions</th>
111                                                                 [% CASE "Select" -%]
112                                                                     <th>Select</th>
113                                                                 [% CASE %]
114                                                                     <th>[% header_field.field_label | html %]</th>
115                                                             [% END -%]
116                                                         [% END %]
117                                                     </tr>
118                                                 </thead>
119                                                 <tbody>
120                                             [% ELSE %]
121                                                 <tr>
122                                                     [% FOREACH text_field IN table_loo.text_fields %]
123                                                         [% IF ( text_field.select_field ) %]
124                                                             <td>
125                                                                 <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/patroncards/edit-batch.pl?op=remove&amp;batch_id=[% batch_id | html %]&amp;label_id=[% text_field.field_value | html %]"><i class="fa fa-trash-can"></i> Delete</a>
126                                                                 <a class="btn btn-default btn-xs export" href="#" data-batch-id="[% batch_id | html %]" data-label-id="[% text_field.field_value | html %]"><i class="fa-solid fa-share-from-square"></i> Export</a>
127                                                             </td>
128                                                             <td><input type="checkbox" name="action" value="[% text_field.field_value | html %]" /></td>
129                                                         [% ELSE %]
130                                                             <td>[% text_field.field_value | html %]</td>
131                                                         [% END %]
132                                                     [% END %]
133                                                 </tr>
134                                             [% END %]
135                                         [% END %]
136                                         </tbody>
137                                     </table>
138                                 </div>
139                             </form>
140                             [% ELSE %]
141                                 <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
142                                 <ol><li>
143                                     <div class="dialog message">
144                                         <h4>There are no patrons in this batch yet</h4>
145                                         <p>Add patrons by borrowernumber using the text area above or leave empty to add via patron search.</p>
146                                     </div>
147                                 </li></ol>
148                                 </fieldset>
149                             [% END %]
150                         </div>
151
152             </main>
153         </div> <!-- /.col-sm-10.col-sm-push-2 -->
154
155         <div class="col-sm-2 col-sm-pull-10">
156             <aside>
157                 [% INCLUDE 'tools-menu.inc' %]
158             </aside>
159         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
160      </div> <!-- /.row -->
161 [% MACRO jsinclude BLOCK %]
162     [% INCLUDE 'greybox.inc' %]
163     [% INCLUDE 'datatables.inc' %]
164     <script>
165         function DeleteConfirm() {
166             var msg = _("Are you sure you want to delete batch %s?").format("[% batch_id | html %]");
167             var answer = confirm(msg);
168             if (answer) {
169                 window.location = "/cgi-bin/koha/patroncards/manage.pl?op=delete&amp;card_element=batch&amp;element_id=[% batch_id | html %]";
170             } else {
171                 return; // abort delete
172             }
173         };
174         function Remove() {
175             items = new Array;
176
177             if(document.items.action.length > 0) {
178                 for (var i=0; i < document.items.action.length; i++) {
179                     if (document.items.action[i].checked) {
180                         items.push("label_id=" +  document.items.action[i].value);
181                     }
182                 }
183                 getstr = items.join("&");
184                 var msg = _("Are you sure you want to remove the selected patron(s) from this batch?");
185             } else if (document.items.action.checked) {
186                 alert(_("Deletion of patron from a batch with only one patron will delete the batch.") + "\n\n" + _("If this is what you want, select the 'Delete batch' option from the toolbar"));
187                 return; // no deletion for single item batch
188             } else {
189                 alert(_("Please select at least one patron to delete."));
190                 return;     // no item selected
191             }
192             var answer = confirm(msg);
193             if (answer) {
194                 window.location = "/cgi-bin/koha/patroncards/edit-batch.pl?op=remove&amp;batch_id=[% batch_id | html %]&amp;" + getstr;
195             } else {
196                 return; // abort delete
197             }
198         };
199         function Add() {
200             var bor_nums = document.getElementById("bor_num_list");
201             if (bor_nums.value == '') {
202                 window.open("/cgi-bin/koha/members/search.pl?columns=checkbox,cardnumber,name,category,branch,dateexpiry,borrowernotes,action&selection_type=add",
203                'PatronPopup',
204                'width=1024,height=768,location=yes,toolbar=no,'
205                + 'scrollbars=yes,resize=yes');
206             } else {
207                 document.forms["add_by_bor_num"].submit();
208             }
209         };
210
211         function add_user(borrowernumber) {
212             $("#bor_num_list").val($("#bor_num_list").val()+borrowernumber+"\r\n");
213         }
214
215         function DeDuplicate() {
216             window.location = "/cgi-bin/koha/patroncards/edit-batch.pl?op=de_duplicate&amp;batch_id=[% batch_id | html %]";
217         };
218         function Xport(mode) {
219             if (mode == 'label') {
220                 patroncards= new Array;
221                 if(document.items.action.length > 0) {
222                     for (var i=0; i < document.items.action.length; i++) {
223                         if (document.items.action[i].checked) {
224                             patroncards.push("label_id=" +  document.items.action[i].value);
225                         }
226                     }
227                     if (patroncards.length < 1) {
228                         alert(_("Please select at least one card to export."));
229                         return;     // no batch selected
230                     }
231                     getstr = patroncards.join("&");
232                 } else if (document.items.action.checked) {
233                     getstr = document.items.action.value;
234                 } else {
235                     alert(_("Please select at least one card to export."));
236                     return;     // no batch selected
237                 }
238                 return GB_showCenter(_("Export patron cards"), "/cgi-bin/koha/patroncards/print.pl?batch_id=[% batch_id | html %]&" + getstr, 400, 800);
239             } else if (mode == 'batch') {
240                 return GB_showCenter(_("Export patron cards"), "/cgi-bin/koha/patroncards/print.pl?batch_id=[% batch_id | html %]", 400, 800);
241             } else {
242                 // some pass-thru error trapping just in case...
243             }
244         };
245         function selected_layout() {
246             if (document.items.action.length) {
247             for (i=0;i<document.items.action.length;i++){
248                 if (document.items.action[i].checked==true){
249                     return(document.items.action[i].value);
250                 }
251             };
252             } else {
253                 if (document.items.action.checked){
254                     return(document.items.action.value);
255                 }
256             };
257             alert(_("Please select at least one item."));
258             return (-1);
259         };
260
261         $(document).ready(function() {
262             // Prepare DataTables settings
263             var aLengthMenu = [10, 20, 50, 100, -1];
264             var aLengthMenuLabel = [10, 20, 50, 100, _("All")];
265             var patronsPerPage = [% Koha.Preference('PatronsPerPage') | html %];
266             for ( var i = 0; i < aLengthMenu.length; i++ ) {
267                 if ( aLengthMenu[i] == patronsPerPage ) {
268                     break;
269                 }
270                 if ( aLengthMenu[i] > patronsPerPage || aLengthMenu[i] == -1 ) {
271                     aLengthMenu.splice(i, 0, patronsPerPage);
272                     aLengthMenuLabel.splice(i, 0, patronsPerPage);
273                     break;
274                 }
275             }
276
277             [% IF table_loop %]
278                 $("#description").show();
279             [% ELSE %]
280                 $("#description").hide();
281             [% END %]
282             $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
283                 "aoColumnDefs": [
284                     { "aTargets": [ -2, -1 ], "bSortable": false, "bSearchable": false }
285                 ],
286                 "aaSorting": [[ 0, "asc" ]],
287                 "sPaginationType": "full",
288                 "aLengthMenu": [aLengthMenu, aLengthMenuLabel],
289                 "pageLength": patronsPerPage,
290                 "autoWidth": false
291             }));
292             $("#additems").click(function(){
293                 Add();
294                 return false;
295             });
296             $("#removeitems").click(function(){
297                 Remove();
298                 return false;
299             });
300             $("#deletebatch").click(function(){
301                 DeleteConfirm();
302                 return false;
303             });
304             $("#deduplicate").click(function(){
305                 DeDuplicate();
306                 return false;
307             });
308             $("#exportitems").click(function(){
309                 Xport('label');
310                 return false;
311             });
312             $("#exportbatch").click(function(){
313                 Xport('batch');
314                 return false;
315             });
316             $(".delete").on("click", function(){
317                 return confirmDelete( _("Are you sure you want to delete this patron from the card batch?") );
318             });
319             $(".export").on("click", function(e){
320                 e.preventDefault();
321                 var label_id = $(this).data("label-id");
322                 var batch_id = $(this).data("batch-id");
323                 GB_showCenter( _("Export single card"),'/cgi-bin/koha/patroncards/print.pl?batch_id=' + batch_id + '&label_id=' + label_id, 400, 800);
324             });
325             $("#savedesc").click(function(event){
326                 var newdescription = $(this).siblings('input[name="description"]').val();
327                 var batch_id = $(this).data('batch_id');
328                 var ajaxData = {
329                     'newdescription': newdescription,
330                     'batch_id': batch_id,
331                     'card_element': "batch",
332                     'creator': "patroncard",
333                 };
334
335                 $.ajax({
336                     url: '/cgi-bin/koha/svc/creator_batches',
337                     type: 'POST',
338                     dataType: 'json',
339                     data: ajaxData,
340                 })
341
342                 .done(function(data){
343                     if (data.status == 'success') {
344                         $("input[name='description']").text(data.newdesc);
345                         $("#change-status").text(_("Saved"));
346                     } else {
347                         $("#change-status").text(_("Unable to save description"));
348                     }
349                 });
350             });
351             $("#savedesc").click(function(event){
352                 var newdescription = $('input[name="description"]').val();
353                 var batch_id = $(this).data('batch_id');
354                 var ajaxData = {
355                     'newdescription': newdescription,
356                     'batch_id': batch_id,
357                     'card_element': "batch",
358                     'creator': "patroncard",
359                 };
360
361                 $.ajax({
362                     url: '/cgi-bin/koha/svc/creator_batches',
363                     type: 'POST',
364                     dataType: 'json',
365                     data: ajaxData,
366                 })
367
368                 .done(function(data){
369                     if (data.status == 'success') {
370                         $("input[name='description']").text(data.newdesc);
371                         $("#change-status").text(_("Saved"));
372                     } else {
373                         $("#change-status").text(_("Unable to save description"));
374                     }
375                 });
376             });
377         });
378     </script>
379 [% END %]
380
381 [% INCLUDE 'intranet-bottom.inc' %]