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