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