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