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