Bug 7720: add options for controlling display of an item's home and/or holdings location
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / marc_modification_templates.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 <title>Koha &rsaquo; Tools &rsaquo; MARC modification templates</title>
3 [% INCLUDE 'doc-head-close.inc' %]
4
5 <script type="text/javascript">
6 //<![CDATA[
7 $(document).ready(function() {
8     $('#select_template').find("input:submit").hide();
9     $('#select_template').change(function() {
10         $('#select_template').submit();
11     });
12     $("span.match_regex_prefix" ).hide();
13     $("span.match_regex_suffix" ).hide();
14
15     $("#conditional_field,#from_field").change(function(){
16         updateWarnings(); // For 3.14.x branches only, if bug 11319 is not pushed into
17     });
18 });
19 //]]>
20 </script>
21
22 <script>
23
24 function updateWarnings(){
25     if ( $("#conditional_field").is(":visible") ) {
26         if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
27             $("#warning_multivalued").show();
28         } else {
29             $("#warning_multivalued").hide();
30         }
31     }
32 }
33
34 function onActionChange(selectObj) {
35     // get the index of the selected option
36     var idx = selectObj.selectedIndex;
37
38     // get the value of the selected option
39     var action = selectObj.options[idx].value;
40
41     switch( action ) {
42         case 'delete_field':
43             show('field_number_block');
44             hide('with_value_block');
45             hide('to_field_block');
46             break;
47
48         case 'update_field':
49             hide('field_number_block');
50             show('with_value_block');
51             hide('to_field_block');
52             break;
53
54         case 'move_field':
55             show('field_number_block');
56             hide('with_value_block');
57             show('to_field_block');
58             break;
59
60         case 'copy_field':
61             show('field_number_block');
62             hide('with_value_block');
63             show('to_field_block');
64             break;
65
66     }
67 }
68
69 function onConditionalChange(selectObj) {
70     // get the index of the selected option
71     var idx = selectObj.selectedIndex;
72
73     // get the value of the selected option
74     var action = selectObj.options[idx].value;
75
76     switch( action ) {
77         case '':
78             hide('conditional_block');
79             break;
80
81         case 'if':
82         case 'unless':
83             show('conditional_block');
84             break;
85     }
86 }
87
88 function onConditionalComparisonChange(selectObj) {
89     // get the index of the selected option
90     var idx = selectObj.selectedIndex;
91
92     // get the value of the selected option
93     var action = selectObj.options[idx].value;
94
95     switch( action ) {
96         case 'equals':
97         case 'not_equals':
98             show('conditional_comparison_block');
99             break;
100
101         default:
102             hide('conditional_comparison_block');
103             break;
104     }
105 }
106
107 function onToFieldRegexChange( checkboxObj ) {
108     if ( checkboxObj.checked ) {
109         show('to_field_regex_value_block');
110     } else {
111         hide('to_field_regex_value_block');
112     }
113 }
114
115 function onConditionalRegexChange( checkboxObj ) {
116     if ( checkboxObj.checked ) {
117         $("span.match_regex_prefix" ).show();
118         $("span.match_regex_suffix" ).show();
119     } else {
120         $("span.match_regex_prefix" ).hide();
121         $("span.match_regex_suffix" ).hide();
122     }
123 }
124
125 function show(eltId) {
126     elt = document.getElementById( eltId );
127     elt.style.display='inline';
128 }
129
130 function hide(eltId) {
131     clearFormElements( eltId );
132     elt = document.getElementById( eltId );
133     elt.style.display='none';
134 }
135
136 function clearFormElements(divId) {
137     myBlock = document.getElementById( divId );
138
139     var inputElements = myBlock.getElementsByTagName( "input" );
140     for (var i = 0; i < inputElements.length; i++) {
141         switch( inputElements[i].type ) {
142             case "text":
143                 inputElements[i].value = '';
144                 break;
145             case "checkbox":
146                 inputElements[i].checked = false;
147                 break;
148         }
149     }
150
151     var selectElements = myBlock.getElementsByTagName( "select" );
152     for (var i = 0; i < selectElements.length; i++) {
153         selectElements[i].selectedIndex = 0;
154     }
155
156 }
157
158 function confirmDelete() {
159     var agree = confirm(_("Are you sure you wish to delete this template?"));
160     return agree;
161 }
162
163 var modaction_legend_innerhtml;
164 var action_submit_value;
165
166 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
167     to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
168     conditional_comparison, conditional_value, conditional_regex, description
169 ) {
170     document.getElementById('mmta_id').value = mmta_id;
171
172     setSelectByValue( 'action', action );
173     document.getElementById('action').onchange();
174
175     setSelectByValue( 'field_number', field_number );
176
177     document.getElementById('from_field').value = from_field;
178     document.getElementById('from_subfield').value = from_subfield;
179     document.getElementById('field_value').value = field_value;
180     document.getElementById('to_field').value = to_field;
181     document.getElementById('to_subfield').value = to_subfield;
182     $("#to_regex_search").val(to_regex_search);
183     $("#to_regex_replace").val(to_regex_replace);
184     $("#to_regex_modifiers").val(to_regex_modifiers);
185
186     document.getElementById('to_field_regex').checked = conditional_regex.length;
187     document.getElementById('to_field_regex').onchange();
188
189     setSelectByValue( 'conditional', conditional );
190     document.getElementById('conditional').onchange();
191
192     document.getElementById('conditional_field').value = conditional_field;
193     document.getElementById('conditional_subfield').value = conditional_subfield;
194
195     setSelectByValue( 'conditional_comparison', conditional_comparison );
196     document.getElementById('conditional_comparison').onchange();
197
198     document.getElementById('conditional_value').value = conditional_value;
199
200     document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
201
202     document.getElementById('description').value = description;
203
204     window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerhtml;
205     document.getElementById('modaction_legend').innerhtml = _("Edit action") + ordering;
206
207     window.action_submit_value = document.getElementById('action_submit').value;
208     document.getElementById('action_submit').value = _("Update action");
209
210     show('cancel_edit');
211 }
212
213 function cancelEditAction() {
214     document.getElementById('mmta_id').value = '';
215
216     setSelectByValue( 'action', 'delete_field' );
217     document.getElementById('action').onchange();
218
219     document.getElementById('from_field').value = '';
220     document.getElementById('from_subfield').value = '';
221     document.getElementById('field_value').value = '';
222     document.getElementById('to_field').value = '';
223     document.getElementById('to_subfield').value = '';
224     $("#to_regex_search").val("");
225     $("#to_regex_replace").val("");
226     $("#to_regex_modifiers").val("");
227
228     document.getElementById('to_field_regex').checked = false;
229     document.getElementById('to_field_regex').onchange();
230
231     setSelectByValue( 'conditional', '' );
232     document.getElementById('conditional').onchange();
233
234     document.getElementById('conditional_field').value = '';
235     document.getElementById('conditional_subfield').value = '';
236
237     setSelectByValue( 'conditional_comparison', '' );
238     document.getElementById('conditional_comparison').onchange();
239
240     document.getElementById('conditional_value').value = '';
241
242     document.getElementById('conditional_regex').checked = false;
243
244     document.getElementById('modaction_legend').innerhtml = window.modaction_legend_innerhtml;
245     document.getElementById('action_submit').value = window.action_submit_value;
246
247     hide('cancel_edit');
248 }
249
250 function setSelectByValue( selectId, value ) {
251     s = document.getElementById( selectId );
252
253     for ( i = 0; i < s.options.length; i++ ) {
254         if ( s.options[i].value == value ) {
255             s.selectedIndex = i;
256         }
257     }
258 }
259
260 </script>
261
262 </head>
263
264 <body>
265 [% INCLUDE 'header.inc' %]
266 [% INCLUDE 'cat-search.inc' %]
267
268 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; MARC modification templates</div>
269
270 <div id="doc3" class="yui-t2">
271   <div id="bd">
272     <div id="yui-main">
273         <div class="yui-b">
274             <h2>MARC modification templates</h2>
275             
276             [% IF error %]
277                 [% IF error == 'no_from_field' %]
278                     <div class="dialog message">Error: no field value specified.</div>
279                 [% END %]
280             [% END %]
281
282             [% IF ( TemplatesLoop ) %]
283
284                 <form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="select_template">
285                     <label for="select_template">Template: </label>
286                     <select name="template_id" id="select_template" style="width:20em;">
287                         [% FOREACH TemplatesLoo IN TemplatesLoop %]
288                                                     [% IF ( TemplatesLoo.selected ) %]
289                             <option value="[% TemplatesLoo.template_id %]" selected="selected"> [% TemplatesLoo.name %]</option>
290                                                     [% ELSE %]
291                             <option value="[% TemplatesLoo.template_id %]"> [% TemplatesLoo.name %]</option>
292                                                     [% END %]
293                         [% END %]
294                     </select>
295                     <input type="hidden" name="op" value="select_template">
296                     <input type="submit" value="Go" />
297                 </form>
298
299                 <form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="delete_template">
300                     <input type="hidden" name="template_id" value="[% template_id %]" />
301                     <input type="hidden" name="op" value="delete_template">
302                     <input type="submit" value="Delete template" onClick="return confirmDelete()" />
303                 </form>
304
305
306                 [% IF ( ActionsLoop ) %]
307                     <table>
308                         <caption>Actions for this template</caption>
309
310                         <tr>
311                             <th>Change order</th>
312                             <th>Order</th>
313                             <th>Action</th>
314                             <th>Description</th>
315                             <th>&nbsp</th>
316                             <th>&nbsp</th>
317                         </tr>
318
319                         [% FOREACH ActionsLoo IN ActionsLoop %]
320                             <tr>
321                                 <td style="white-space:nowrap;">
322                                     <a title="Move action up" href="marc_modification_templates.pl?op=move_action&amp;where=up&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
323                                     <img src="[% interface %]/[% theme %]/img/go-up.png" border="0" alt="Go up" />
324                                         </a>
325
326                                 <a title="Move action to top" href="marc_modification_templates.pl?op=move_action&amp;where=top&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
327                                     <img src="[% interface %]/[% theme %]/img/go-top.png" border="0" alt="Go top" />
328                                         </a>
329
330                                         <a title="Move action to bottom" href="marc_modification_templates.pl?op=move_action&amp;where=bottom&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
331                                     <img src="[% interface %]/[% theme %]/img/go-bottom.png" border="0" alt="Go bottom" />
332                                         </a>
333
334                                         <a title="Move action down" href="marc_modification_templates.pl?op=move_action&amp;where=down&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
335                                     <img src="[% interface %]/[% theme %]/img/go-down.png" border="0" alt="Go down" />
336                                         </a>
337                                 </td>
338
339                                 <td>[% ActionsLoo.ordering %]</td>
340                                 <td>
341                                     [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
342                                     [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
343                                     [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
344                                     [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
345
346                                     [% UNLESS ( ActionsLoo.action_update_field ) %]
347                                         [% IF ( ActionsLoo.field_number ) %]
348                                             1st
349                                         [% END %]
350                                     [% END %]
351
352                                     field
353
354                                     [% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %]
355
356                                     [% IF ( ActionsLoo.field_value ) %]
357                                         with value <i>[% ActionsLoo.field_value %]</i>
358                                     [% END %]
359
360                                     [% IF ( ActionsLoo.to_field ) %]
361                                         to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
362
363                                         [% IF ( ActionsLoo.to_regex_search ) %]
364                                              using RegEx s<strong>/[% ActionsLoo.to_regex_search %]/[% ActionsLoo.to_regex_replace %]/[% ActionsLoo.to_regex_modifiers %]</strong>
365                                         [% END %]
366                                     [% END %]
367
368                                     [% IF ( ActionsLoo.conditional ) %]
369                                         [% IF ( ActionsLoo.conditional_if ) %] if [% END %]
370                                         [% IF ( ActionsLoo.conditional_unless ) %] unless [% END %]
371
372                                         [% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %]
373
374                                         [% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %]
375                                         [% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %]
376                                         [% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %]
377                                         [% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %]
378
379                                         [% IF ( ActionsLoo.conditional_regex ) %] RegEx m/[% END %]
380                                         <strong>[% ActionsLoo.conditional_value %]</strong>
381                                         [% IF ( ActionsLoo.conditional_regex ) %]/[% END %]
382                                     [% END %]
383                                 </td>
384                                 <td>[% ActionsLoo.description %]</td>
385                                 <td><a href="#modaction" onclick='editAction(
386                                                     "[% ActionsLoo.mmta_id |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
387                                                     "[% ActionsLoo.ordering |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
388                                                     "[% ActionsLoo.action |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
389                                                     "[% ActionsLoo.field_number |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
390                                                     "[% ActionsLoo.from_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
391                                                     "[% ActionsLoo.from_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
392                                                     "[% ActionsLoo.field_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
393                                                     "[% ActionsLoo.to_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
394                                                     "[% ActionsLoo.to_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
395                                                     "[% ActionsLoo.to_regex_search |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
396                                                     "[% ActionsLoo.to_regex_replace |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
397                                                     "[% ActionsLoo.to_regex_modifiers |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
398                                                     "[% ActionsLoo.conditional |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
399                                                     "[% ActionsLoo.conditional_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
400                                                     "[% ActionsLoo.conditional_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
401                                                     "[% ActionsLoo.conditional_comparison |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
402                                                     "[% ActionsLoo.conditional_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
403                                                     "[% ActionsLoo.conditional_regex |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
404                                                     "[% ActionsLoo.description |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
405                                                 )'>Edit</a></td>
406                                 <td><a href="marc_modification_templates.pl?template_id=[% ActionsLoo.template_id %]&op=delete_action&mmta_id=[% ActionsLoo.mmta_id %]">Delete</a></td>
407                             </tr>
408                         [% END %]
409                     </table>
410                 [% ELSE %]
411                     <div class="dialog message"><p>There are no defined actions for this template.</p></div>
412                 [% END %]
413
414                 <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_action" >
415                     <a name="modaction"></a>
416                     <fieldset>
417                         <legend id="modaction_legend">Add a new action</legend>
418                         <div id="warning_multivalued" style="color:red; display:none;">You have chosen a condition on the same field as the original field. If your records contain multivalued fields it is highly recommended not to do that.</div>
419
420                         <select name="action" id="action" onchange="onActionChange(this);">
421                             <option value="delete_field">Delete</option>
422                             <option value="update_field">Add/Update</option>
423                             <option value="move_field">Move</option>
424                             <option value="copy_field">Copy</option>
425                         </select>
426
427                         <span id="field_number_block">
428                             <select name="field_number" id="field_number">
429                                 <option value="0">All</option>
430                                 <option value="1">1st</option>
431                             </select>
432                         </span>
433
434                         field(s) <input type="text" name="from_field" id="from_field" size="3" maxlength="3" /> <input type="text" name="from_subfield" id="from_subfield" size="1" maxlength="1" />
435
436                         <span name="with_value_block" id="with_value_block" style="display:none;">
437                             with value <input type="text" name="field_value" id="field_value" />
438                         </span>
439
440                         <span name="to_field_block" id="to_field_block" style="display:none;">
441                             to field <input type="text" name="to_field" id="to_field" size="3" maxlength="3" /> <input type="text" name="to_subfield" id="to_subfield" size="1" maxlength="1" />
442
443                             <span name="to_field_regex_block" id="to_field_regex_block">
444                                 <sup>
445                                     <label for="to_field_regex">RegEx</label>
446                                     <input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
447
448                                     <span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
449                                         s/<input type="text" name="to_regex_search" id="to_regex_search" placeholder="regex pattern" />/<input type="text" name="to_regex_replace" id="to_regex_replace" placeholder="regex replacement" />/<input type="text" name="to_regex_modifiers" id="to_regex_modifiers" placeholder="ig" size="3" />
450                                     </span>
451                                 </sup>
452                             </span>
453                         </span>
454
455                         <p/>
456
457                         <select name="conditional" id="conditional" onchange="onConditionalChange(this);">
458                             <option value="" selected />
459                             <option value="if">if</option>
460                             <option value="unless">unless</option>
461                         </select>
462
463                         <span name="conditional_block" id="conditional_block" style="display:none;">
464                             field <input type="text" name="conditional_field" id="conditional_field" size="3" maxlength="3" /> <input type="text" name="conditional_subfield" id="conditional_subfield" size="1" maxlength="1" />
465
466                             <select name="conditional_comparison" id="conditional_comparison" onchange="onConditionalComparisonChange(this);">
467                                 <option value="" />
468                                 <option value="exists">exists</option>
469                                 <option value="not_exists">doesn't exist</option>
470                                 <option value="equals">matches</option>
471                                 <option value="not_equals">doesn't match</option>
472                             </select>
473
474                             <span name="conditional_comparison_block" id="conditional_comparison_block" style="display:none;">
475
476                                 <span class="match_regex_prefix">m/</span><input type="text" id="conditional_value" name="conditional_value" /><span class="match_regex_suffix">/</span>
477
478                                 <sup>
479                                     <label for="conditional_regex">RegEx</label>
480                                     <input type="checkbox" name="conditional_regex" id="conditional_regex" onchange="onConditionalRegexChange(this);" />
481                                 </sup>
482
483                             </span>
484                         </span>
485
486                         <input type="hidden" name="template_id" value="[% template_id %]" />
487                         <input type="hidden" name="mmta_id" id="mmta_id" />
488                         <input type="hidden" name="op" value="add_action" />
489
490                         <br/><br/>
491                         <label for="description">Description:</label>
492                         <input type="text" name="description" id="description" size="60" />
493
494                         <br/><br/>
495                         <input id="action_submit" type="submit" value="Add action" /> <a href="#modaction" id="cancel_edit" onclick="cancelEditAction();" style="display:none;">Cancel</a>
496
497                     </fieldset>
498                 </form>
499
500             [% ELSE %]
501                 <div class="dialog message"><p>There are no defined templates. Please create a template first.</p></div>
502             [% END %]
503
504             <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_template" >
505                 <fieldset>
506                     <legend>Create a new template</legend>
507
508                     <label for="template_name" class="required">Name: </label>
509                     <input name="template_name" id="template_name" type="text" size="30" required="required" />
510
511                     <input type="hidden" name="op" value="create_template" />
512                     <input type="submit" value="Create template" />
513
514                     [% IF ( template_id ) %]
515                         <input type="hidden" name="template_id" value="[% template_id %]" />
516                         <input type="checkbox" name="duplicate_current_template" id="duplicate_current_template" />
517                         <label for="duplicate_current_template">Duplicate current template</label>
518                     [% END %]
519                 </fieldset>
520             </form>
521         </div>
522     </div>
523
524     <div class="yui-b">
525         [% INCLUDE 'tools-menu.inc' %]
526     </div>
527   </div>
528 </div>
529 [% INCLUDE 'intranet-bottom.inc' %]