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