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