1 [% INCLUDE 'doc-head-open.inc' %]
2 <title>Koha › Tools › MARC modification templates</title>
3 [% INCLUDE 'doc-head-close.inc' %]
5 <script type="text/javascript">
7 $(document).ready(function() {
8 $('#select_template').find("input:submit").hide();
9 $('#select_template').change(function() {
10 $('#select_template').submit();
12 $("span.match_regex_prefix" ).hide();
13 $("span.match_regex_suffix" ).hide();
15 $("#add_action").submit(function(){
16 var action = $("#action").val();
17 if ( action == 'move_field' || action == 'copy_field' || action == 'copy_and_replace_field') {
18 if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) {
19 alert(_("Both subfield values should be filled or empty."));
22 if ( $("#to_field").val().length <= 0 ) {
23 alert(_("The destination should be filled."));
26 if ( ( $("#to_field").val() < 10 && $("#to_subfield").val().length > 0 ) ||
27 ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) {
28 alert(_("If the field is a control field, the subfield should be empty"));
31 if ( ( $("#from_field").val() < 10 && $("#to_subfield").val().length == 0 ) ||
32 ( $("#to_field").val() < 10 && $("#from_subfield").val().length == 0 ) ) {
33 alert(_("A control field cannot be used with a regular field."));
37 if ( action == 'update_field' ) {
38 if ( $("#from_subfield").val().length <= 0 ) {
39 alert(_("The source subfield should be filled for update."));
43 if ( $("#from_field").val().length <= 0 ) {
44 alert(_("The source field should be filled."));
49 $("#conditional_field,#from_field").change(function(){
57 function updateAllEvery(){
58 if ( $("#conditional_field").is(":visible") ) {
59 if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
60 $("#field_number option[value='0']").html(_("Every"));
62 $("#field_number option[value='0']").html(_("All"));
67 function onActionChange(selectObj) {
68 // get the index of the selected option
69 var idx = selectObj.selectedIndex;
71 // get the value of the selected option
72 var action = selectObj.options[idx].value;
76 show('field_number_block');
77 hide('with_value_block');
78 hide('to_field_block');
82 hide('field_number_block');
83 show('with_value_block');
84 hide('to_field_block');
88 show('field_number_block');
89 hide('with_value_block');
90 show('to_field_block');
94 show('field_number_block');
95 hide('with_value_block');
96 show('to_field_block');
99 case 'copy_and_replace_field':
100 show('field_number_block');
101 hide('with_value_block');
102 show('to_field_block');
108 function onConditionalChange(selectObj) {
109 // get the index of the selected option
110 var idx = selectObj.selectedIndex;
112 // get the value of the selected option
113 var action = selectObj.options[idx].value;
117 hide('conditional_block');
122 show('conditional_block');
127 function onConditionalComparisonChange(selectObj) {
128 // get the index of the selected option
129 var idx = selectObj.selectedIndex;
131 // get the value of the selected option
132 var action = selectObj.options[idx].value;
137 show('conditional_comparison_block');
141 hide('conditional_comparison_block');
146 function onToFieldRegexChange( checkboxObj ) {
147 if ( checkboxObj.checked ) {
148 show('to_field_regex_value_block');
150 hide('to_field_regex_value_block');
154 function onConditionalRegexChange( checkboxObj ) {
155 if ( checkboxObj.checked ) {
156 $("span.match_regex_prefix" ).show();
157 $("span.match_regex_suffix" ).show();
159 $("span.match_regex_prefix" ).hide();
160 $("span.match_regex_suffix" ).hide();
164 function show(eltId) {
165 elt = document.getElementById( eltId );
166 elt.style.display='inline';
169 function hide(eltId) {
170 clearFormElements( eltId );
171 elt = document.getElementById( eltId );
172 elt.style.display='none';
175 function clearFormElements(divId) {
176 myBlock = document.getElementById( divId );
178 var inputElements = myBlock.getElementsByTagName( "input" );
179 for (var i = 0; i < inputElements.length; i++) {
180 switch( inputElements[i].type ) {
182 inputElements[i].value = '';
185 inputElements[i].checked = false;
190 var selectElements = myBlock.getElementsByTagName( "select" );
191 for (var i = 0; i < selectElements.length; i++) {
192 selectElements[i].selectedIndex = 0;
197 function confirmDelete() {
198 var agree = confirm(_("Are you sure you wish to delete this template?"));
202 var modaction_legend_innerhtml;
203 var action_submit_value;
205 function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
206 to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
207 conditional_comparison, conditional_value, conditional_regex, description
209 document.getElementById('mmta_id').value = mmta_id;
211 setSelectByValue( 'action', action );
212 document.getElementById('action').onchange();
214 setSelectByValue( 'field_number', field_number );
216 document.getElementById('from_field').value = from_field;
217 document.getElementById('from_subfield').value = from_subfield;
218 document.getElementById('field_value').value = field_value;
219 document.getElementById('to_field').value = to_field;
220 document.getElementById('to_subfield').value = to_subfield;
221 $("#to_regex_search").val(to_regex_search);
222 $("#to_regex_replace").val(to_regex_replace);
223 $("#to_regex_modifiers").val(to_regex_modifiers);
225 document.getElementById('to_field_regex').checked = conditional_regex.length;
226 document.getElementById('to_field_regex').onchange();
228 setSelectByValue( 'conditional', conditional );
229 document.getElementById('conditional').onchange();
231 document.getElementById('conditional_field').value = conditional_field;
232 document.getElementById('conditional_subfield').value = conditional_subfield;
234 setSelectByValue( 'conditional_comparison', conditional_comparison );
235 document.getElementById('conditional_comparison').onchange();
237 document.getElementById('conditional_value').value = conditional_value;
239 document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
241 document.getElementById('description').value = description;
243 window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
244 document.getElementById('modaction_legend').innerHTML = _("Edit action %s").format(ordering);
246 window.action_submit_value = document.getElementById('action_submit').value;
247 document.getElementById('action_submit').value = _("Update action");
252 function cancelEditAction() {
253 document.getElementById('mmta_id').value = '';
255 setSelectByValue( 'action', 'delete_field' );
256 document.getElementById('action').onchange();
258 document.getElementById('from_field').value = '';
259 document.getElementById('from_subfield').value = '';
260 document.getElementById('field_value').value = '';
261 document.getElementById('to_field').value = '';
262 document.getElementById('to_subfield').value = '';
263 $("#to_regex_search").val("");
264 $("#to_regex_replace").val("");
265 $("#to_regex_modifiers").val("");
267 document.getElementById('to_field_regex').checked = false;
268 document.getElementById('to_field_regex').onchange();
270 setSelectByValue( 'conditional', '' );
271 document.getElementById('conditional').onchange();
273 document.getElementById('conditional_field').value = '';
274 document.getElementById('conditional_subfield').value = '';
276 setSelectByValue( 'conditional_comparison', '' );
277 document.getElementById('conditional_comparison').onchange();
279 document.getElementById('conditional_value').value = '';
281 document.getElementById('conditional_regex').checked = false;
283 document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
284 document.getElementById('action_submit').value = window.action_submit_value;
289 function setSelectByValue( selectId, value ) {
290 s = document.getElementById( selectId );
292 for ( i = 0; i < s.options.length; i++ ) {
293 if ( s.options[i].value == value ) {
303 <body id="tools_marc_modification_templates" class="tools">
304 [% INCLUDE 'header.inc' %]
305 [% INCLUDE 'cat-search.inc' %]
307 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › MARC modification templates</div>
309 <div id="doc3" class="yui-t2">
313 <h2>MARC modification templates</h2>
316 [% IF error == 'no_from_field' %]
317 <div class="dialog message">Error: no field value specified.</div>
321 [% IF ( TemplatesLoop ) %]
323 <form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="select_template">
324 <label for="select_template">Template: </label>
325 <select name="template_id" id="select_template" style="width:20em;">
326 [% FOREACH TemplatesLoo IN TemplatesLoop %]
327 [% IF ( TemplatesLoo.selected ) %]
328 <option value="[% TemplatesLoo.template_id %]" selected="selected"> [% TemplatesLoo.name %]</option>
330 <option value="[% TemplatesLoo.template_id %]"> [% TemplatesLoo.name %]</option>
334 <input type="hidden" name="op" value="select_template">
335 <input type="submit" value="Go" />
338 <form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="delete_template">
339 <input type="hidden" name="template_id" value="[% template_id %]" />
340 <input type="hidden" name="op" value="delete_template">
341 <input type="submit" value="Delete template" onClick="return confirmDelete()" />
345 [% IF ( ActionsLoop ) %]
347 <caption>Actions for this template</caption>
350 <th>Change order</th>
358 [% FOREACH ActionsLoo IN ActionsLoop %]
360 <td style="white-space:nowrap;">
361 <a title="Move action up" href="marc_modification_templates.pl?op=move_action&where=up&template_id=[% ActionsLoo.template_id %]&mmta_id=[% ActionsLoo.mmta_id %]">
362 <img src="[% interface %]/[% theme %]/img/go-up.png" border="0" alt="Go up" />
365 <a title="Move action to top" href="marc_modification_templates.pl?op=move_action&where=top&template_id=[% ActionsLoo.template_id %]&mmta_id=[% ActionsLoo.mmta_id %]">
366 <img src="[% interface %]/[% theme %]/img/go-top.png" border="0" alt="Go top" />
369 <a title="Move action to bottom" href="marc_modification_templates.pl?op=move_action&where=bottom&template_id=[% ActionsLoo.template_id %]&mmta_id=[% ActionsLoo.mmta_id %]">
370 <img src="[% interface %]/[% theme %]/img/go-bottom.png" border="0" alt="Go bottom" />
373 <a title="Move action down" href="marc_modification_templates.pl?op=move_action&where=down&template_id=[% ActionsLoo.template_id %]&mmta_id=[% ActionsLoo.mmta_id %]">
374 <img src="[% interface %]/[% theme %]/img/go-down.png" border="0" alt="Go down" />
378 <td>[% ActionsLoo.ordering %]</td>
380 [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
381 [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
382 [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
383 [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
384 [% IF ( ActionsLoo.action_copy_and_replace_field ) %] Copy and replace [% END %]
386 [% UNLESS ( ActionsLoo.action_update_field ) %]
387 [% IF ( ActionsLoo.field_number ) %]
394 [% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %]
396 [% IF ( ActionsLoo.field_value ) %]
397 with value <i>[% ActionsLoo.field_value %]</i>
400 [% IF ( ActionsLoo.to_field ) %]
401 to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
403 [% IF ( ActionsLoo.to_regex_search ) %]
404 using RegEx s<strong>/[% ActionsLoo.to_regex_search %]/[% ActionsLoo.to_regex_replace %]/[% ActionsLoo.to_regex_modifiers %]</strong>
408 [% IF ( ActionsLoo.conditional ) %]
409 [% IF ( ActionsLoo.conditional_if ) %] if [% END %]
410 [% IF ( ActionsLoo.conditional_unless ) %] unless [% END %]
412 [% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %]
414 [% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %]
415 [% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %]
416 [% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %]
417 [% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %]
419 [% IF ( ActionsLoo.conditional_regex ) %] RegEx m/[% END %]
420 <strong>[% ActionsLoo.conditional_value %]</strong>
421 [% IF ( ActionsLoo.conditional_regex ) %]/[% END %]
424 <td>[% ActionsLoo.description %]</td>
425 <td><a href="#modaction" onclick='editAction(
426 "[% ActionsLoo.mmta_id |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
427 "[% ActionsLoo.ordering |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
428 "[% ActionsLoo.action |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
429 "[% ActionsLoo.field_number |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
430 "[% ActionsLoo.from_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
431 "[% ActionsLoo.from_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
432 "[% ActionsLoo.field_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
433 "[% ActionsLoo.to_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
434 "[% ActionsLoo.to_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
435 "[% ActionsLoo.to_regex_search |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
436 "[% ActionsLoo.to_regex_replace |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
437 "[% ActionsLoo.to_regex_modifiers |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
438 "[% ActionsLoo.conditional |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
439 "[% ActionsLoo.conditional_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
440 "[% ActionsLoo.conditional_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
441 "[% ActionsLoo.conditional_comparison |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
442 "[% ActionsLoo.conditional_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
443 "[% ActionsLoo.conditional_regex |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
444 "[% ActionsLoo.description |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
446 <td><a href="marc_modification_templates.pl?template_id=[% ActionsLoo.template_id %]&op=delete_action&mmta_id=[% ActionsLoo.mmta_id %]">Delete</a></td>
451 <div class="dialog message"><p>There are no defined actions for this template.</p></div>
454 <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_action" >
455 <a name="modaction"></a>
457 <legend id="modaction_legend">Add a new action</legend>
458 <div id="warning_multivalued" style="color:red; display:none;">You have chosen a condition on the same field as the original field. If your records contain multivalued fields it is highly recommended not to do that.</div>
460 <select name="action" id="action" onchange="onActionChange(this);">
461 <option value="delete_field">Delete</option>
462 <option value="update_field">Add/Update</option>
463 <option value="move_field">Move</option>
464 <option value="copy_field">Copy</option>
465 <option value="copy_and_replace_field">Copy and replace</option>
468 <span id="field_number_block">
469 <select name="field_number" id="field_number">
470 <option value="0">All</option>
471 <option value="1">1st</option>
475 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" title="let blank for the entire field" />
477 <span name="with_value_block" id="with_value_block" style="display:none;">
478 with value <input type="text" name="field_value" id="field_value" />
481 <span name="to_field_block" id="to_field_block" style="display:none;">
482 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" title="let blank for the entire field" />
484 <span name="to_field_regex_block" id="to_field_regex_block">
486 <label for="to_field_regex">RegEx</label>
487 <input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
489 <span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
490 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" />
498 <select name="conditional" id="conditional" onchange="onConditionalChange(this);">
499 <option value="" selected="selected" />
500 <option value="if">if</option>
501 <option value="unless">unless</option>
504 <span name="conditional_block" id="conditional_block" style="display:none;">
505 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" />
507 <select name="conditional_comparison" id="conditional_comparison" onchange="onConditionalComparisonChange(this);">
509 <option value="exists">exists</option>
510 <option value="not_exists">doesn't exist</option>
511 <option value="equals">matches</option>
512 <option value="not_equals">doesn't match</option>
515 <span name="conditional_comparison_block" id="conditional_comparison_block" style="display:none;">
517 <span class="match_regex_prefix">m/</span><input type="text" id="conditional_value" name="conditional_value" /><span class="match_regex_suffix">/</span>
520 <label for="conditional_regex">RegEx</label>
521 <input type="checkbox" name="conditional_regex" id="conditional_regex" onchange="onConditionalRegexChange(this);" />
527 <input type="hidden" name="template_id" value="[% template_id %]" />
528 <input type="hidden" name="mmta_id" id="mmta_id" />
529 <input type="hidden" name="op" value="add_action" />
532 <label for="description">Description:</label>
533 <input type="text" name="description" id="description" size="60" />
536 <input id="action_submit" type="submit" value="Add action" /> <a href="#modaction" id="cancel_edit" onclick="cancelEditAction();" style="display:none;">Cancel</a>
542 <div class="dialog message"><p>There are no defined templates. Please create a template first.</p></div>
545 <form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_template" class="validated">
547 <legend>Create a new template</legend>
549 <label for="template_name" class="required">Name: </label>
550 <input name="template_name" id="template_name" type="text" size="30" required="required" class="required" />
551 <span class="required">Required</span>
553 <input type="hidden" name="op" value="create_template" />
554 <input type="submit" value="Create template" />
556 [% IF ( template_id ) %]
557 <input type="hidden" name="template_id" value="[% template_id %]" />
558 <input type="checkbox" name="duplicate_current_template" id="duplicate_current_template" />
559 <label for="duplicate_current_template">Duplicate current template</label>
567 [% INCLUDE 'tools-menu.inc' %]
571 [% INCLUDE 'intranet-bottom.inc' %]