Bug 22015: Move DataTables CSS to global include
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / labels / label-edit-batch.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE ItemTypes %]
4 [% SET footerjs = 1 %]
5     [% INCLUDE 'doc-head-open.inc' %]
6     <title>Koha &rsaquo; Tools &rsaquo; Label creator &rsaquo; Batches &rsaquo; [% IF batch_id %]Edit ([% batch_id | html %])[% ELSE %]New[% END %]</title>
7     [% INCLUDE 'doc-head-close.inc' %]
8 </head>
9
10 <body id="labels_label-edit-batch" class="tools labels" onload="dofocus();">
11     [% INCLUDE 'header.inc' %]
12     [% INCLUDE 'cat-search.inc' %]
13     <div id="breadcrumbs">
14         <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
15         <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
16         <a href="/cgi-bin/koha/labels/label-home.pl">Label creator</a> &rsaquo;
17         <a href="/cgi-bin/koha/labels/label-manage.pl?label_element=batch">Batches</a> &rsaquo;
18         [% IF description %]
19             Edit <a href="/cgi-bin/koha/labels/label-edit-batch.pl?op=edit&element_id=[% batch_id | uri %]">[% description | html %]</a>
20         [% ELSIF batch_id %]
21             Edit <a href="/cgi-bin/koha/labels/label-edit-batch.pl?op=edit&element_id=[% batch_id | uri %]">([% batch_id | html %])</a>
22         [% ELSE %]
23             New
24         [% END %]
25     </div>
26
27     <div class="main container-fluid">
28         <div class="row">
29             <div class="col-sm-10 col-sm-push-2">
30                 <main>
31
32                         [% INCLUDE 'labels-toolbar.inc' %]
33                         [% IF ( err ) %]
34                             [% BLOCK xlate_errtype %]
35                             [%    SWITCH errtype %]
36                             [%       CASE 'ITEM_NOT_REMOVED' %]
37                             <span>Item(s) not removed from batch [% batch_id | html %].</span>
38                             [%       CASE 'BATCH_NOT_DELETED' %]
39                             <span>Batch [% batch_id | html %] was not deleted.</span>
40                             [%       CASE 'ITEM_NOT_ADDED' %]
41                             <span>Item(s) not added to batch [% batch_id | html %].</span>
42                             [%       CASE 'BRANCH_NOT_SET' %]
43                             <span>Library is not set, please set your library before adding items to a batch.</span>
44                             [%       CASE 'BATCH_NOT_DEDUP' %]
45                             <span>Batch [% batch_id | html %] not fully de-duplicated.</span>
46                             [%       CASE %]
47                             <span>Unknown error type [% errtype | html %].</span>
48                             [%    END %]
49                             [% END %]
50                             <div class="dialog alert">
51                                 <strong>WARNING:</strong> An error was encountered: [% PROCESS xlate_errtype %] Please have your system administrator check the error log for details.
52                             </div>
53                         [% ELSIF ( duplicate_message ) %]
54                             <div class="dialog message">
55                                 <strong>Duplicate item(s) removed from batch number [% batch_id | html %]: [% duplicate_count | html %]</strong>
56                             </div>
57                         [% END %]
58
59                         <div id="manage-label-batches">
60                             <div class="hint">Current library: [% LoginBranchname | html %]</div>
61                             <form name="add_by_number" action="/cgi-bin/koha/labels/label-edit-batch.pl" method="post">
62                                 <div>
63                                     <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
64                                     <ol><li id="description">
65                                         <input type="hidden" name="op" value="add" />
66                                         <input type="hidden" name="batch_id" value="[% batch_id | html %]" />
67                                         <label for="description">Batch description: </label>
68                                         <input type="text" name="description" value="[% description | html %]"> <span id="change-status"></span>
69                                     </li>
70                                     <li>
71                                         <input type="radio" name="number_type" id="barcode_enter" value="barcode" checked />
72                                         <label for="barcode_enter">Enter by barcode:</label><br/>
73                                         <input type="radio" name="number_type" id="itemnum_enter" value="itemnumber" />
74                                         <label for="itemnum_enter">Enter by itemnumber:</label>
75                                     </li>
76                                     <li>
77                                         <label for="number_list">Add by barcode(s) or itemnumbers(s):
78                                             <br /> <span class="hint">One number per line.</span>
79                                             <br /> <span class="hint">Leave empty to add via item search (itemnumber).</span>
80                                         </label>
81                                         <textarea rows="5" id="number_list" name="number_list" tabindex="1" class="focus"></textarea>
82                                     </li></ol>
83                                     </fieldset>
84                                 </div>
85                             </form>
86                             <div id="batch-manage" class="btn-toolbar">
87                                 <a class="btn btn-default btn-sm" id="additems" href="#"><i class="fa fa-plus"></i> Add item(s)</a>[% IF ( table_loop ) %]
88                                 <a class="btn btn-default btn-sm" id="savedesc" href="#" data-batch_id="[% batch_id | html %]"><i class="fa fa-save"></i> Save description</a>
89                                 <a class="btn btn-default btn-sm" id="removeitems" href="#"><i class="fa fa-trash"></i> Remove selected items</a>
90                                 <a class="btn btn-default btn-sm" id="deletebatch" href="#"><i class="fa fa-minus-square"></i> Delete batch</a>
91                                 <a class="btn btn-default btn-sm" id="deduplicate" href="#"><i class="fa fa-minus"></i> Remove duplicates</a>
92                                 <a class="btn btn-default btn-sm" id="exportitems" href="#"><i class="fa fa-share-square-o"></i> Export selected items</a>
93                                 <a class="btn btn-default btn-sm" id="exportbatch" href="#"><i class="fa fa-share-square-o"></i> Export full batch</a>[% END %]
94                             </div>
95                             [% IF ( table_loop ) %]
96                                 <form name="items" class="checkboxed">
97                                     <h2>Items in batch number [% batch_id | html %]</h2>
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 "Label number" -%]
106                                                                     <th>Label number</th>
107                                                                 [% CASE "Summary" -%]
108                                                                     <th class="anti-the">Summary</th>
109                                                                 [% CASE "Item type" %]
110                                                                     <th>Item type</th>
111                                                                 [% CASE "Call number" %]
112                                                                     <th>Call number</th>
113                                                                 [% CASE "Barcode" %]
114                                                                     <th>Barcode</th>
115                                                                 [% CASE "Select" -%]
116                                                                     <th>Select</th>
117                                                                 [% CASE %]
118                                                                     <th>[% header_field.field_label | html %]</th>
119                                                             [% END -%]
120                                                         [% END %]
121                                                     </tr>
122                                                 </thead>
123                                                 <tbody>
124                                             [% ELSE %]
125                                                     <tr>
126                                                         [% FOREACH text_field IN table_loo.text_fields %]
127                                                             [% IF ( text_field.select_field ) %]
128                                                                 <td>
129                                                                     <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/labels/label-edit-batch.pl?op=remove&amp;batch_id=[% batch_id |url %]&amp;label_id=[% text_field.field_value |url %]"><i class="fa fa-trash"></i> Delete</a>
130                                                                     <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>
131                                                                 </td>
132                                                                 <td><input type="checkbox" name="action" value="[% text_field.field_value | html %]"></td>
133                                                             [% ELSE %]
134                                                                 <td>
135                                                                     [% IF ( text_field.field_name == '_item_type_tbl' ) %]
136                                                                         [% ItemTypes.GetDescription( text_field.field_value ) | html %]
137                                                                     [% ELSE %]
138                                                                         [% text_field.field_value | $raw %]
139                                                                     [% END %]
140                                                                 </td>
141                                                             [% END %]
142                                                         [% END %]
143                                                     </tr>
144                                             [% END %]
145                                         [% END %]
146                                         </tbody>
147                                     </table>
148                                 </form>
149                                 [% ELSE %]
150                                     <div class="dialog message">
151                                         <h4>There are no items in this batch yet</h4>
152                                         <p>Add items by using the text area above or leave empty to add via item search.</p>
153                                     </div>
154                                 [% END %]
155                             </div>
156             </main>
157         </div> <!-- /.col-sm-10.col-sm-push-2 -->
158
159         <div class="col-sm-2 col-sm-pull-10">
160             <aside>
161                 [% INCLUDE 'tools-menu.inc' %]
162             </aside>
163         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
164      </div> <!-- /.row -->
165
166 [% MACRO jsinclude BLOCK %]
167     [% Asset.js("js/tools-menu.js") | $raw %]
168     [% INCLUDE 'greybox.inc' %]
169     [% INCLUDE 'datatables.inc' %]
170     <script>
171         function DeleteConfirm() {
172             var msg = _("Are you sure you want to delete batch %s?").format("[% batch_id | html %]");
173             var answer = confirm(msg);
174             if (answer) {
175                 window.location = "/cgi-bin/koha/labels/label-manage.pl?op=delete&amp;label_element=batch&amp;element_id=[% batch_id | html %]";
176             }
177             else {
178                 return; // abort delete
179             }
180         }
181         function dofocus() {    // named function req'd for body onload event by some FF and IE7 security models
182             $(".focus:last").select();
183         }
184         function verifyBarcodes(barcodes) {
185             if (barcodes.value == '') {
186                 alert(_("Please add barcodes using either the direct entry text area or the item search."));
187                 return false;   // not ok
188             }
189             else {
190                 return true;    // ok
191             }
192         }
193         function Remove() {
194             items = new Array;
195             item_num = new Array;
196             if(document.items.action.length > 0) {
197                 for (var i=0; i < document.items.action.length; i++) {
198                     if (document.items.action[i].checked) {
199                         items.push("label_id=" +  document.items.action[i].value);
200                         item_num.push(i+1);
201                     }
202                 }
203                 getstr = items.join("&");
204                 item_msg = item_num.join(", ");
205                 var msg = _("Are you sure you want to remove label number(s): %s from this batch?").format(item_msg);
206             } else if (document.items.action.checked) {
207                 alert(_("Deletion of label from a batch with only one label will delete the batch.") + "\n\n" + _("If this is what you want, select the 'Delete batch' option from the toolbar"));
208                     return; // no deletion for single item batch
209             } else {
210                 alert(_("Please select at least one label to delete."));
211                 return;     // no item selected
212             }
213             var answer = confirm(msg);
214             if (answer) {
215                 window.location = "/cgi-bin/koha/labels/label-edit-batch.pl?op=remove&amp;batch_id=[% batch_id | html %]&amp;" + getstr;
216             } else {
217                 return; // abort delete
218             }
219         }
220         function Add() {
221             var number_list = document.getElementById("number_list");
222             if (number_list.value == '') {
223                 window.open("/cgi-bin/koha/labels/label-item-search.pl?batch_id=[% batch_id | html %]&amp;type=labels",'FindABibIndex','width=875,height=400,toolbar=no,scrollbars=yes');
224             } else {
225                 document.forms["add_by_number"].submit();
226             }
227         }
228
229         function add_item(item_number) {
230             $("#itemnum_enter").prop("checked",true);
231             $("#number_list").val($("#number_list").val()+item_number+"\r\n");
232         }
233
234         function DeDuplicate() {
235             window.location = "/cgi-bin/koha/labels/label-edit-batch.pl?op=de_duplicate&amp;batch_id=[% batch_id | html %]";
236         }
237
238         function Xport(mode) {
239             if (mode == 'label') {
240                 labels= new Array;
241                 if(document.items.action.length > 0) {
242                     for (var i=0; i < document.items.action.length; i++) {
243                         if (document.items.action[i].checked) {
244                             labels.push("label_id=" +  document.items.action[i].value);
245                         }
246                     }
247                     if (labels.length < 1) {
248                         alert(_("Please select at least one label to export."));
249                         return;     // no batch selected
250                     }
251                     getstr = labels.join("&");
252                 }
253                 else if (document.items.action.checked) {
254                     getstr = document.items.action.value;
255                 } else {
256                     alert(_("Please select at least one label to export."));
257                     return;     // no batch selected
258                 }
259                 return GB_showCenter(_("Export labels"), "/cgi-bin/koha/labels/label-print.pl?batch_id=[% batch_id | html %]&" + getstr, 400, 800);
260             } else if (mode == 'batch') {
261                 return GB_showCenter(_("Export labels"), "/cgi-bin/koha/labels/label-print.pl?batch_id=[% batch_id | html %]", 400, 800);
262             } else {
263                 // some pass-thru error trapping just in case...
264             }
265         }
266
267         function selected_layout() {
268             if (document.items.action.length) {
269                 for (i=0;i<document.items.action.length;i++){
270                     if (document.items.action[i].checked==true){
271                         return(document.items.action[i].value);
272                     }
273                 }
274             } else {
275                 if (document.items.action.checked){
276                     return(document.items.action.value);
277                 }
278             }
279             alert(_("Please select at least one item."));
280             return (-1);
281         }
282
283          $(document).ready(function() {
284             [% IF table_loop %]
285                 $("#description").show();
286             [% ELSE %]
287                 $("#description").hide();
288             [% END %]
289             $("#batcht").dataTable($.extend(true, {}, dataTablesDefaults, {
290                 "autoWidth": false,
291                 "aoColumnDefs": [
292                     { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
293                     { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
294                 ],
295                 "aaSorting": [[ 0, "asc" ]],
296                 "sPaginationType": "four_button"
297             }));
298             $("#additems").click(function(){
299                 Add();
300                 return false;
301             });
302             $("#removeitems").click(function(){
303                 Remove();
304                 return false;
305             });
306             $("#deletebatch").click(function(){
307                 DeleteConfirm();
308                 return false;
309             });
310             $("#deduplicate").click(function(){
311                 DeDuplicate();
312                 return false;
313             });
314             $("#exportitems").click(function(){
315                 Xport('label');
316                 return false;
317             });
318             $("#exportbatch").click(function(){
319                 Xport('batch');
320                 return false;
321             });
322             $(".delete").on("click", function(){
323                 return confirmDelete( _("Are you sure you want to delete this?") );
324             });
325             $(".export").on("click", function(e){
326                 e.preventDefault();
327                 var label_id = $(this).data("label-id");
328                 var batch_id = $(this).data("batch-id");
329                 GB_showCenter(_("Export labels"),"/cgi-bin/koha/labels/label-print.pl?batch_id=" + batch_id + "&label_id=" + label_id, 400, 800);
330             });
331             $("#savedesc").click(function(event){
332                 event.preventDefault(); // prevent form submission
333                 var newdescription = $('input[name="description"]').val();
334                 var batch_id = $(this).data('batch_id');
335                 var ajaxData = {
336                     'newdescription': newdescription,
337                     'batch_id': batch_id,
338                     'card_element': "batch",
339                     'creator': "label",
340                 };
341
342                 $.ajax({
343                     url: '/cgi-bin/koha/svc/creator_batches',
344                     type: 'POST',
345                     dataType: 'json',
346                     data: ajaxData,
347                 })
348
349                 .done(function(data){
350                     if (data.status == 'success') {
351                         $("input[name='description']").text(data.newdesc);
352                         $("#change-status").text(_("Saved"));
353                     } else {
354                         $("#change-status").text(_("Unable to save description"));
355                     }
356                 });
357             });
358          });
359     </script>
360 [% END %]
361
362 [% INCLUDE 'intranet-bottom.inc' %]