Bug 8015: QA Followup 2
[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 error %]
262                 [% IF error == 'no_from_field' %]
263                     <div class="dialog message">Error: no field value specified.</div>
264                 [% END %]
265             [% END %]
266
267             [% IF ( TemplatesLoop ) %]
268
269                 <form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="select_template">
270                     <label for="select_template">Template: </label>
271                     <select name="template_id" id="select_template" style="width:20em;">
272                         [% FOREACH TemplatesLoo IN TemplatesLoop %]
273                                                     [% IF ( TemplatesLoo.selected ) %]
274                             <option value="[% TemplatesLoo.template_id %]" selected="selected"> [% TemplatesLoo.name %]</option>
275                                                     [% ELSE %]
276                             <option value="[% TemplatesLoo.template_id %]"> [% TemplatesLoo.name %]</option>
277                                                     [% END %]
278                         [% END %]
279                     </select>
280                     <input type="hidden" name="op" value="select_template">
281                     <input type="submit" value="Go" />
282                 </form>
283
284                 <form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="delete_template">
285                     <input type="hidden" name="template_id" value="[% template_id %]" />
286                     <input type="hidden" name="op" value="delete_template">
287                     <input type="submit" value="Delete template" onClick="return confirmDelete()" />
288                 </form>
289
290
291                 [% IF ( ActionsLoop ) %]
292                     <table>
293                         <caption>Actions for this template</caption>
294
295                         <tr>
296                             <th>Change order</th>
297                             <th>Order</th>
298                             <th>Action</th>
299                             <th>Description</th>
300                             <th>&nbsp</th>
301                             <th>&nbsp</th>
302                         </tr>
303
304                         [% FOREACH ActionsLoo IN ActionsLoop %]
305                             <tr>
306                                 <td style="white-space:nowrap;">
307                                     <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 %]">
308                                     <img src="[% interface %]/[% theme %]/img/go-up.png" border="0" alt="Go up" />
309                                         </a>
310
311                                 <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 %]">
312                                     <img src="[% interface %]/[% theme %]/img/go-top.png" border="0" alt="Go top" />
313                                         </a>
314
315                                         <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 %]">
316                                     <img src="[% interface %]/[% theme %]/img/go-bottom.png" border="0" alt="Go bottom" />
317                                         </a>
318
319                                         <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 %]">
320                                     <img src="[% interface %]/[% theme %]/img/go-down.png" border="0" alt="Go down" />
321                                         </a>
322                                 </td>
323
324                                 <td>[% ActionsLoo.ordering %]</td>
325                                 <td>
326                                     [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
327                                     [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
328                                     [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
329                                     [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
330
331                                     [% UNLESS ( ActionsLoo.action_update_field ) %]
332                                         [% IF ( ActionsLoo.field_number ) %]
333                                             1st
334                                         [% END %]
335                                     [% END %]
336
337                                     field
338
339                                     [% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %]
340
341                                     [% IF ( ActionsLoo.field_value ) %]
342                                         with value <i>[% ActionsLoo.field_value %]</i>
343                                     [% END %]
344
345                                     [% IF ( ActionsLoo.to_field ) %]
346                                         to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
347
348                                         [% IF ( ActionsLoo.to_regex_search ) %]
349                                              using RegEx s<strong>/[% ActionsLoo.to_regex_search %]/[% ActionsLoo.to_regex_replace %]/[% ActionsLoo.to_regex_modifiers %]</strong>
350                                         [% END %]
351                                     [% END %]
352
353                                     [% IF ( ActionsLoo.conditional ) %]
354                                         [% IF ( ActionsLoo.conditional_if ) %] if [% END %]
355                                         [% IF ( ActionsLoo.conditional_unless ) %] unless [% END %]
356
357                                         [% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %]
358
359                                         [% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %]
360                                         [% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %]
361                                         [% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %]
362                                         [% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %]
363
364                                         [% IF ( ActionsLoo.conditional_regex ) %] RegEx m/[% END %]
365                                         <strong>[% ActionsLoo.conditional_value %]</strong>
366                                         [% IF ( ActionsLoo.conditional_regex ) %]/[% END %]
367                                     [% END %]
368                                 </td>
369                                 <td>[% ActionsLoo.description %]</td>
370                                 <td><a href="#modaction" onclick='editAction(
371                                                     "[% ActionsLoo.mmta_id |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
372                                                     "[% ActionsLoo.ordering |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
373                                                     "[% ActionsLoo.action |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
374                                                     "[% ActionsLoo.field_number |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
375                                                     "[% ActionsLoo.from_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
376                                                     "[% ActionsLoo.from_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
377                                                     "[% ActionsLoo.field_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
378                                                     "[% ActionsLoo.to_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
379                                                     "[% ActionsLoo.to_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
380                                                     "[% ActionsLoo.to_regex_search |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
381                                                     "[% ActionsLoo.to_regex_replace |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
382                                                     "[% ActionsLoo.to_regex_modifiers |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
383                                                     "[% ActionsLoo.conditional |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
384                                                     "[% ActionsLoo.conditional_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
385                                                     "[% ActionsLoo.conditional_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
386                                                     "[% ActionsLoo.conditional_comparison |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
387                                                     "[% ActionsLoo.conditional_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
388                                                     "[% ActionsLoo.conditional_regex |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
389                                                     "[% ActionsLoo.description |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
390                                                 )'>Edit</a></td>
391                                 <td><a href="marc_modification_templates.pl?template_id=[% ActionsLoo.template_id %]&op=delete_action&mmta_id=[% ActionsLoo.mmta_id %]">Delete</a></td>
392                             </tr>
393                         [% END %]
394                     </table>
395                 [% ELSE %]
396                     <div class="dialog message"><p>There are no defined actions for this template.</p></div>
397                 [% END %]
398
399                 <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_action" >
400                     <a name="modaction"></a>
401                     <fieldset>
402                         <legend id="modaction_legend">Add a new action</legend>
403
404                         <select name="action" id="action" onchange="onActionChange(this);">
405                             <option value="delete_field">Delete</option>
406                             <option value="update_field">Add/Update</option>
407                             <option value="move_field">Move</option>
408                             <option value="copy_field">Copy</option>
409                         </select>
410
411                         <span id="field_number_block">
412                             <select name="field_number" id="field_number">
413                                 <option value="0">All</option>
414                                 <option value="1">1st</option>
415                             </select>
416                         </span>
417
418                         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" />
419
420                         <span name="with_value_block" id="with_value_block" style="display:none;">
421                             with value <input type="text" name="field_value" id="field_value" />
422                         </span>
423
424                         <span name="to_field_block" id="to_field_block" style="display:none;">
425                             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" />
426
427                             <span name="to_field_regex_block" id="to_field_regex_block">
428                                 <sup>
429                                     <label for="to_field_regex">RegEx</label>
430                                     <input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
431
432                                     <span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
433                                         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" />
434                                     </span>
435                                 </sup>
436                             </span>
437                         </span>
438
439                         <p/>
440
441                         <select name="conditional" id="conditional" onchange="onConditionalChange(this);">
442                             <option value="" selected />
443                             <option value="if">if</option>
444                             <option value="unless">unless</option>
445                         </select>
446
447                         <span name="conditional_block" id="conditional_block" style="display:none;">
448                             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" />
449
450                             <select name="conditional_comparison" id="conditional_comparison" onchange="onConditionalComparisonChange(this);">
451                                 <option value="" />
452                                 <option value="exists">exists</option>
453                                 <option value="not_exists">doesn't exist</option>
454                                 <option value="equals">matches</option>
455                                 <option value="not_equals">doesn't match</option>
456                             </select>
457
458                             <span name="conditional_comparison_block" id="conditional_comparison_block" style="display:none;">
459
460                                 <span class="match_regex_prefix">m/</span><input type="text" id="conditional_value" name="conditional_value" /><span class="match_regex_suffix">/</span>
461
462                                 <sup>
463                                     <label for="conditional_regex">RegEx</label>
464                                     <input type="checkbox" name="conditional_regex" id="conditional_regex" onchange="onConditionalRegexChange(this);" />
465                                 </sup>
466
467                             </span>
468                         </span>
469
470                         <input type="hidden" name="template_id" value="[% template_id %]" />
471                         <input type="hidden" name="mmta_id" id="mmta_id" />
472                         <input type="hidden" name="op" value="add_action" />
473
474                         <br/><br/>
475                         <label for="description">Description:</label>
476                         <input type="text" name="description" id="description" size="60" />
477
478                         <br/><br/>
479                         <input id="action_submit" type="submit" value="Add action" /> <a href="#modaction" id="cancel_edit" onclick="cancelEditAction();" style="display:none;">Cancel</a>
480
481                     </fieldset>
482                 </form>
483
484             [% ELSE %]
485                 <div class="dialog message"><p>There are no defined templates. Please create a template first.</p></div>
486             [% END %]
487
488             <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_template" >
489                 <fieldset>
490                     <legend>Create a new template</legend>
491
492                     <label for="template_name" class="required">Name: </label>
493                     <input name="template_name" id="template_name" type="text" size="30" required="required" />
494
495                     <input type="hidden" name="op" value="create_template" />
496                     <input type="submit" value="Create template" />
497
498                     [% IF ( template_id ) %]
499                         <input type="hidden" name="template_id" value="[% template_id %]" />
500                         <input type="checkbox" name="duplicate_current_template" id="duplicate_current_template" />
501                         <label for="duplicate_current_template">Duplicate current template</label>
502                     [% END %]
503                 </fieldset>
504             </form>
505         </div>
506     </div>
507
508     <div class="yui-b">
509         [% INCLUDE 'tools-menu.inc' %]
510     </div>
511   </div>
512 </div>
513 [% INCLUDE 'intranet-bottom.inc' %]