Bug 26960: Move batch item modification template JavaScript to the footer
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / batchMod-edit.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% SET footerjs = 1 %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Tools &rsaquo; Batch item modification</title>
7 [% INCLUDE 'doc-head-close.inc' %]
8 <style>input[type=checkbox]{ margin : 0 .5em; }</style>
9 [% Asset.css("css/addbiblio.css") | $raw %]
10 [% Asset.css("css/humanmsg.css") | $raw %]
11 </head>
12
13 <body id="tools_batchMod-edit" class="tools">
14     [% INCLUDE 'header.inc' %]
15     [% INCLUDE 'cat-search.inc' %]
16
17     <div id="breadcrumbs">
18         <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
19         <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
20         <a href="/cgi-bin/koha/tools/batchMod.pl">Batch item modification</a>
21     </div>
22
23     <div class="main container-fluid">
24
25         [% IF ( show ) %]
26             <h1>Batch item modification</h1>
27         [% ELSE %]
28             <h1>Batch item modification results</h1>
29             <div class="dialog message">
30                 [% IF (modified_items) %]
31                     [% modified_items | html %] item(s) modified (with [% modified_fields | html %] field(s) modified).
32                 [% ELSE %]
33                     No items modified.
34                 [% END %]
35                 <fieldset class="action">
36                     [% IF src == 'CATALOGUING' # from catalogue/detail.pl > Edit items in a batch%]
37                         [% IF searchid %]
38                             <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]&searchid=[% searchid | uri %]">Return to the record</a>
39                         [% ELSE %]
40                             <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]">Return to the record</a>
41                         [% END %]
42                     [% ELSIF src %]
43                         <a href="[% src | url %]">Return to where you were</a>
44                     [% ELSE %]
45                         <a href="/cgi-bin/koha/tools/batchMod.pl">Return to batch item modification</a>
46                     [% END %]
47                 </fieldset>
48             </div> <!-- /.dialog.message -->
49         [% END # /IF show %]
50
51         [% IF ( barcode_not_unique ) %]
52             <div class="dialog alert">
53                 <strong>Error saving item</strong>: Barcode must be unique.
54             </div>
55         [% END %]
56         [% IF ( no_next_barcode ) %]
57             <div class="dialog alert">
58                 <strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.
59             </div>
60         [% END %]
61
62         [% IF ( notfoundbarcodes.size ) %]
63             <div class="dialog alert">
64                 <p>Warning, the following barcodes were not found:</p>
65             </div>
66
67             <table style="margin:auto;">
68                 <thead>
69                     <tr><th>Barcodes not found</th></tr>
70                 </thead>
71                 <tbody>
72                     [% FOREACH notfoundbarcode IN notfoundbarcodes %]
73                         <tr><td>[% notfoundbarcode |html %]</td></td>
74                     [% END %]
75                 </tbody>
76             </table>
77
78             [% IF ( item_loop ) %]
79                 [% UNLESS ( too_many_items_display ) %]
80                     <h4>The following barcodes were found: </h4>
81                 [% END %]
82             [% END %]
83         [% END # /IF notfoundbarcodes.size %]
84
85         [% IF ( notfounditemnumbers.size ) %]
86             <div class="dialog alert">
87                 <p>Warning, the following itemnumbers were not found:</p>
88             </div>
89
90             <table style="margin:auto;">
91                 <thead>
92                     <tr><th>Itemnumbers not found</th></tr>
93                 </thead>
94                 <tbody>
95                     [% FOREACH notfounditemnumber IN notfounditemnumbers %]
96                         <tr><td>[% notfounditemnumber |html %]</td></td>
97                     [% END %]
98                 </tbody>
99             </table>
100             [% IF ( item_loop ) %]
101                 [% UNLESS ( too_many_items_display ) %]
102                     <h4>The following itemnumbers were found: </h4>
103                 [% END %]
104             [% END %]
105         [% END # /IF notfounditemnumbers.size %]
106
107
108         <form name="f" action="batchMod.pl" method="post">
109             <input type="hidden" name="op" value="[% op | html %]" />
110             <input type="hidden" name="searchid" value="[% searchid | html %]" />
111             <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
112             <input type="hidden" name="runinbackground" id="runinbackground" value="" />
113             <input type="hidden" name="completedJobID" id="completedJobID" value="" />
114             <input type="hidden" name="src" id="src" value="[% src | html %]" />
115             [% IF biblionumber %]
116                 <input type="hidden" name="biblionumber" id="biblionumber" value="[% biblionumber | html %]" />
117             [% END %]
118
119             [% IF ( item_loop ) %]
120                 [% IF show %]
121                     <div id="toolbar">
122                         <a id="selectallbutton" href="#"><i class="fa fa-check"></i> Select all</a> | <a id="clearallbutton" href="#"><i class="fa fa-remove"></i> Clear all</a> | <a id="clearonloanbutton" href="#">Clear on loan</a>
123                     </div>
124                 [% END %]
125
126                 <div id="cataloguing_additem_itemlist">
127
128                     <p id="selections">
129                         <strong>Show/hide columns:</strong>
130                         <span class="selected">
131                             <input type="checkbox" checked="checked" id="showall" />
132                             <label for="showall">Show all columns</label>
133                         </span>
134                         <span>
135                             <input type="checkbox" id="hideall" />
136                             <label for="hideall">Hide all columns</label>
137                         </span>
138
139                         [% FOREACH item_header_loo IN item_header_loop %]
140                             <span class="selected">
141                                 <input id="checkheader[% loop.count | html %]" type="checkbox" checked="checked" />
142                                 <label for="checkheader[% loop.count | html %]">[% item_header_loo.header_value | html %]</label>
143                             </span>
144                         [% END %]
145                     </p> <!-- /#selections -->
146
147                     <table id="itemst">
148                         <thead>
149                             <tr>
150                                 <th>&nbsp;</th>
151                                 <th class="anti-the">Title</th>
152                                 <th class="holds_count" title="Item holds / Total holds">Holds</th>
153                                 [% FOREACH item_header_loo IN item_header_loop %]
154                                     <th> [% item_header_loo.header_value | html %] </th>
155                                 [% END %]
156                             </tr>
157                         </thead>
158                         <tbody>
159                             [% FOREACH item_loo IN item_loop %]
160                                 <tr>
161                                     [% IF show %]
162                                         [% IF item_loo.nomod %]
163                                             <td class="error">Cannot edit</td>
164                                         [% ELSE %]
165                                             <td>
166                                                 <input type="checkbox" name="itemnumber" value="[% item_loo.itemnumber | html %]" id="row[% item_loo.itemnumber | html %]" checked="checked" data-is-onloan="[% item_loo.onloan | html %]" />
167                                             </td>
168                                         [% END %]
169                                     [% ELSE %]
170                                         <td>&nbsp;</td>
171                                     [% END %]
172                                     <td>
173                                         <label for="row[% item_loo.itemnumber | html %]">
174                                             <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item_loo.biblionumber | uri %]">
175                                                 [% item_loo.title | html %]
176                                             </a>
177                                             [% IF ( item_loo.author ) %], by [% item_loo.author | html %][% END %]
178                                         </label>
179                                     </td>
180                                     <td class="holds_count">
181                                         [% IF item_loo.holds %]
182                                             [% IF item_loo.item_holds %]
183                                                 <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="Holds on this item: [% item_loo.item_holds | html %] / Total holds on this record: [% item_loo.holds | html -%]" >
184                                             [% ELSE %]
185                                                 <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="No holds on this item / Total holds on this record: [% item_loo.holds | html -%]" >
186                                             [% END %]
187                                         [% ELSE %]
188                                             [% IF item_loo.holds %]
189                                                 <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="Holds on this record: [% item_loo.holds | html -%]" >
190                                             [% ELSE %]
191                                                 <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% item_loo.biblionumber | uri %]" title="No holds on this record" >
192                                             [% END %]
193                                         [% END # /IF item_loo.holds %]
194                                         [% IF item_loo.holds %]
195                                             [% item_loo.item_holds | html %]/[% item_loo.holds | html %]
196                                         [% ELSE %]
197                                             [% item_loo.holds | html %]
198                                         [% END %]
199                                         </a>
200                                     </td>
201                                     [% FOREACH item_valu IN item_loo.item_value %]
202                                         <td>
203                                             [% item_valu.field | html %]
204                                         </td>
205                                     [% END %]
206                                 </tr>
207                             [% END # /FOREACH item_loo %]
208                         </tbody>
209                     </table> <!-- /#itemst -->
210                 </div> <!-- /#cataloguing_additem_itemlist -->
211             [% END # /IF item_loop %]
212
213             [% IF ( simple_items_display || job_completed ) %]
214                 [% IF ( too_many_items_display ) %]
215                     <p>Too many items ([% too_many_items_display | html %]): You have edited more than [% Koha.Preference('MaxItemsToDisplayForBatchMod') | html %] items in a batch, items will not be shown.</p>
216                 [% ELSE %]
217                     <p>The following items were modified:</p>
218                     <ul>
219                         [% FOREACH simple_items_displa IN simple_items_display %]
220                             <li>
221                                 [% IF ( CAN_user_editcatalogue_edit_items ) %]<a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&amp;biblionumber=[% simple_items_displa.biblionumber | uri %]&amp;itemnumber=[% simple_items_displa.itemnumber | uri %]">[% simple_items_displa.barcode | html %]</a>[% ELSE %][% simple_items_displa.barcode | html %][% END %]
222                             </li>
223                         [% END %]
224                     </ul>
225                 [% END # /IF too_many_items_display %]
226             [% END # /IF simple_items_display %]
227
228             [% IF ( show ) %]
229
230                 [% IF ( too_many_items_process ) %]
231                     <p>Too many items ([% too_many_items_process | html %]): You are not allowed to edit more than [% Koha.Preference('MaxItemsToProcessForBatchMod') | html %] items in a batch.</p>
232                 [% ELSIF ( too_many_items_display ) %]
233                     <p>Too many items ([% too_many_items_display | html %]): You are editing more than [% Koha.Preference('MaxItemsToDisplayForBatchMod') | html %] items in a batch, items will not be shown.</p>
234                     [% FOREACH itemnumber IN itemnumbers_array %]
235                         <input type="hidden" name="itemnumber" value="[% itemnumber | html %]" />
236                     [% END %]
237                 [% END # /IF too_many_items_process %]
238
239                 [% UNLESS (too_many_items_process) %]
240                     <div id="cataloguing_additem_newitem">
241                         <h2>Edit items</h2>
242                         <div class="hint">Checking the box right next to the subfield label will disable the entry and delete the subfield on all selected items. Leave fields blank to make no change.</div>
243                         <fieldset class="rows">
244                             <ol>
245                                 [% FOREACH ite IN item %]
246                                     <li>
247                                         <div class="subfield_line" style="[% ite.visibility | html %]" id="subfield[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]">
248                                             [% SET mv = ite.marc_value %]
249                                             [% IF ( ite.mandatory ) %]
250                                                 <label class="required" for="[%- mv.id | html -%]">
251                                             [% ELSE %]
252                                                 <label for="[%- mv.id | html -%]">
253                                             [% END %]
254                                                 [% ite.subfield | html %] - [% ite.marc_lib | $raw %]
255                                             </label>
256
257                                             [% IF ( mv.type == 'select' ) -%]
258                                                 <select name="[%- mv.name | html -%]" id="[%- mv.id | html -%]" size="1" tabindex="1" class="input_marceditor select2">
259                                                     [%- FOREACH aval IN mv.values %]
260                                                         [% ite.subfield | html %] -
261                                                         [% IF aval == mv.default %]
262                                                             <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
263                                                         [% ELSE %]
264                                                             <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
265                                                         [% END %]
266                                                     [%- END -%]
267                                                 </select>
268                                             [% ELSIF ( mv.type == 'text1' ) %]
269                                                 <input type="text" tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
270                                                 <a href="#" class="buttonDot" onclick="Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=[%- mv.authtypecode | uri -%]&index=[%- mv.id | uri -%]','[%- mv.id | uri -%]'); return false;" title="Tag editor">...</a>
271                                             [% ELSIF ( mv.type == 'text2' ) %]
272                                                 <input type="text" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
273                                                 [% IF mv.noclick %]
274                                                     <a href="#" class="buttonDot disabled" title="No popup">...</a>
275                                                 [% ELSE %]
276                                                     <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot" title="Tag editor">...</a>
277                                                 [% END %]
278                                             [% ELSIF ( mv.type == 'text' ) %]
279                                                 <input type="text" tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
280                                             [% ELSIF ( mv.type == 'hidden' ) %]
281                                                 <input type="hidden" tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255" value="[%- mv.value | html -%]" />
282                                             [% ELSIF ( mv.type == 'textarea' ) %]
283                                                 <textarea tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255">[%- mv.value | html -%]"</textarea>
284                                             [%- END # /IF mv.type == ... -%]
285
286                                             <span name="regex_fields" style="display: none;">
287                                                 s/<input type="text" id="[% mv.id | html %]" name="regex_search" placeholder="regex pattern" />/
288                                                 <input type="text" id="[% mv.id | html %]" name="regex_replace" placeholder="regex replacement" />/
289                                                 <input type="text" id="[% mv.id | html %]" name="regex_modifiers" placeholder="ig" size="3" />
290                                             </span>
291
292                                             [% UNLESS ( ite.mandatory ) %]
293                                                 <input type="checkbox" id="row[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]" title="Check to delete subfield [% ite.subfield | html %]" name="disable_input" value="[% ite.subfield | html %]" />
294                                             [% ELSE %]
295                                                 <span class="required">Required</span>
296                                             [% END %]
297
298                                             [% IF (mv.type == 'text' || mv.type == 'textarea' ) %]
299                                                 <a href="#" name="field_regex" id="[% ite.id | html %]" >RegEx</a>
300                                             [% END %]
301
302                                             <input type="hidden" name="tag" value="[% ite.tag | html %]" />
303                                             <input type="hidden" name="subfield" value="[% ite.subfield | html %]" />
304                                             <input type="hidden" name="mandatory" value="[% ite.mandatory | html %]" />
305                                             [% IF ( ite.repeatable ) %]
306                                                 <a href="#" class="buttonPlus" onclick="CloneItemSubfield(this.parentNode.parentNode); return false;">
307                                                     <img src="[% interface | html %]/[% theme | html %]/img/clone-subfield.png" alt="Clone" title="Clone this subfield" />
308                                                 </a>
309                                             [% END %]
310                                             <span class="hint" id="hint[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]"></span>
311                                         </div> <!-- /.subfield_line -->
312                                     </li>
313                                 [% END # /FOREACH ite %]
314                             </ol>
315                         </fieldset>
316
317                         <fieldset class="rows">
318                             <legend>Other attributes</legend>
319                             <ol>
320                                 <li>
321                                     <div class="subfield_line">
322                                         <label for="exclude_from_local_holds_priority">Exclude from local holds priority:</label>
323                                         <select id="exclude_from_local_holds_priority" name="exclude_from_local_holds_priority" class="input_marceditor select2" style="width: 50px">
324                                             <option selected></option>
325                                             <option value="1">Yes</option>
326                                             <option value="0">No</option>
327                                         </select>
328                                     </div>
329                                 </li>
330                             </ol>
331                         </fieldset>
332
333                         <fieldset class="action">
334                             <div id="jobpanel">
335                                 <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
336                                 <div id="jobfailed"></div>
337                             </div>
338                             <input type="submit" id="mainformsubmit" value="Save" />
339                             <a href="/cgi-bin/koha/tools/batchMod.pl" class="cancel">Cancel</a>
340                         </fieldset>
341                     </div> <!-- /#cataloguing_additem_newitem -->
342                 [% ELSE %]
343                     <p><a href="/cgi-bin/koha/tools/batchMod.pl">Return to batch item modification</a></p>
344                 [% END # /UNLESS too_many_items_process %]
345             [% ELSE # IF show %]
346                 <fieldset class="action">
347                     [% IF src == 'CATALOGUING' # from catalogue/detail.pl > Edit items in a batch%]
348                         [% IF searchid %]
349                             <a class="btn btn-default" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]&searchid=[% searchid | uri %]"><i class="fa fa-check-square-o"></i> Return to the record</a>
350                         [% ELSE %]
351                             <a class="btn btn-default" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]"><i class="fa fa-check-square-o"></i> Return to the record</a>
352                         [% END %]
353                     [% ELSIF src %]
354                         <a class="btn btn-default" href="[% src | url %]"><i class="fa fa-check-square-o"></i> Return to where you were</a>
355                     [% ELSE %]
356                         <a class="btn btn-default" href="/cgi-bin/koha/tools/batchMod.pl"><i class="fa fa-check-square-o"></i> Return to batch item modification</a>
357                     [% END %]
358                 </fieldset> <!-- /.action -->
359             [% END #/IF show %]
360         </form>
361
362     [% MACRO jsinclude BLOCK %]
363         [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
364         [% Asset.js("js/background-job-progressbar.js") | $raw %]
365         [% Asset.js("js/cataloging.js") | $raw %]
366         [% INCLUDE 'datatables.inc' %]
367         [% Asset.js("js/pages/batchMod.js") | $raw %]
368         [% INCLUDE 'select2.inc' %]
369         <script>
370             // Prepare array of all column headers, incrementing each index by
371             // two to accommodate control and title columns
372             var allColumns = new Array([% FOREACH item_header_loo IN item_header_loop %]'[% loop.count | html %]'[% UNLESS ( loop.last ) %],[% END %][% END %]);
373             for( x=0; x<allColumns.length; x++ ){
374                 allColumns[x] = Number(allColumns[x]) + 2;
375             }
376
377             $(document).ready(function(){
378                 $("input[name='disable_input']").click(function() {
379                     var row = $(this).attr("id");
380                     row = row.replace("row","hint");
381                     var todisable = $(this).parent().find("[name='field_value'],[name='tag'],[name='subfield'],[name='mandatory']");
382                     var regex_link = $(this).parent().find("[name='field_regex']");
383                     if ($(this).is(":checked")) {
384                         $(todisable).prop('disabled', true);
385                         $("#"+row).html(_("This subfield will be deleted"));
386                         $(regex_link).hide();
387                     } else {
388                         $(todisable).prop('disabled', false);
389                         $("#"+row).html("");
390                         $(regex_link).show();
391                     }
392                 });
393                 $("#mainformsubmit").on("click",function(){
394                     return submitBackgroundJob(this.form);
395                 });
396                 $('a[name="field_regex"]').click(function() {
397                     var id = $(this).attr('id');
398                     var editor = $(this).parent().find("[name='field_value']");
399                     var regex = $(this).parent().find("[name='regex_fields']");
400                     var disable_input = $(this).parent().find("[name='disable_input']");
401                     if ($(this).html() == 'RegEx') {
402                         $(editor).hide();
403                         $(regex).show();
404                         $(this).html('Text');
405                         $(disable_input).prop('disabled', true);
406                     } else {
407                         $(editor).show();
408                         $(regex).hide();
409                         $(this).html('RegEx');
410                         $(disable_input).prop('disabled', false);
411                     }
412                     return false;
413                 });
414             });
415         </script>
416         [% IF ( show ) %]
417             [%- # Loop over fields which may have plugin JavaScript -%]
418             [%- UNLESS (too_many_items_process) -%]
419                 [%- FOREACH ite IN item -%]
420                     [% SET mv = ite.marc_value %]
421                     [%- IF ( mv.type == 'text2' ) -%]
422                         <!-- subfield[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %] -->
423                         [% mv.javascript | $raw %]
424                     [%- END -%]
425                 [%- END -%]
426             [%- END -%]
427         [%- END -%]
428     [% END %]
429
430 [% INCLUDE 'intranet-bottom.inc' %]