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