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