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