Koha/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt
Jonathan Druart a5dda66f64 Bug 11319: Template modifications
This patch add template modifications for the restrictions:
- the source field is always mandatory
- on move and copy, the source and destination subfield should be both
  filled or blank.
- on move and copy, the destination subfield should be filled.
- on update, the subfield value should be filled.

Test plan:
Verify you are not able to create/modify template actions according to
these restrictions.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2014-11-12 12:04:19 -03:00

550 lines
27 KiB
Text

[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Tools &rsaquo; MARC modification templates</title>
[% INCLUDE 'doc-head-close.inc' %]
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$('#select_template').find("input:submit").hide();
$('#select_template').change(function() {
$('#select_template').submit();
});
$("span.match_regex_prefix" ).hide();
$("span.match_regex_suffix" ).hide();
$("#add_action").submit(function(){
var action = $("#action").val();
if ( action == 'move_field' || action == 'copy_field' ) {
if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) {
alert(_("Both subfield values should be filled or empty."));
return false;
}
if ( $("#to_field").val().length <= 0 ) {
alert(_("The destination should be filled."));
return false;
}
}
if ( action == 'update_field' ) {
if ( $("#from_subfield").val().length <= 0 ) {
alert(_("The source subfield should be filled for update."));
return false;
}
}
if ( $("#from_field").val().length <= 0 ) {
alert(_("The source field should be filled."));
return false;
}
});
});
//]]>
</script>
<script>
function updateWarnings(){
if ( $("#conditional_field").is(":visible") ) {
if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
$("#warning_multivalued").show();
} else {
$("#warning_multivalued").hide();
}
}
}
function onActionChange(selectObj) {
// get the index of the selected option
var idx = selectObj.selectedIndex;
// get the value of the selected option
var action = selectObj.options[idx].value;
switch( action ) {
case 'delete_field':
show('field_number_block');
hide('with_value_block');
hide('to_field_block');
break;
case 'update_field':
hide('field_number_block');
show('with_value_block');
hide('to_field_block');
break;
case 'move_field':
show('field_number_block');
hide('with_value_block');
show('to_field_block');
break;
case 'copy_field':
show('field_number_block');
hide('with_value_block');
show('to_field_block');
break;
}
}
function onConditionalChange(selectObj) {
// get the index of the selected option
var idx = selectObj.selectedIndex;
// get the value of the selected option
var action = selectObj.options[idx].value;
switch( action ) {
case '':
hide('conditional_block');
break;
case 'if':
case 'unless':
show('conditional_block');
break;
}
}
function onConditionalComparisonChange(selectObj) {
// get the index of the selected option
var idx = selectObj.selectedIndex;
// get the value of the selected option
var action = selectObj.options[idx].value;
switch( action ) {
case 'equals':
case 'not_equals':
show('conditional_comparison_block');
break;
default:
hide('conditional_comparison_block');
break;
}
}
function onToFieldRegexChange( checkboxObj ) {
if ( checkboxObj.checked ) {
show('to_field_regex_value_block');
} else {
hide('to_field_regex_value_block');
}
}
function onConditionalRegexChange( checkboxObj ) {
if ( checkboxObj.checked ) {
$("span.match_regex_prefix" ).show();
$("span.match_regex_suffix" ).show();
} else {
$("span.match_regex_prefix" ).hide();
$("span.match_regex_suffix" ).hide();
}
}
function show(eltId) {
elt = document.getElementById( eltId );
elt.style.display='inline';
}
function hide(eltId) {
clearFormElements( eltId );
elt = document.getElementById( eltId );
elt.style.display='none';
}
function clearFormElements(divId) {
myBlock = document.getElementById( divId );
var inputElements = myBlock.getElementsByTagName( "input" );
for (var i = 0; i < inputElements.length; i++) {
switch( inputElements[i].type ) {
case "text":
inputElements[i].value = '';
break;
case "checkbox":
inputElements[i].checked = false;
break;
}
}
var selectElements = myBlock.getElementsByTagName( "select" );
for (var i = 0; i < selectElements.length; i++) {
selectElements[i].selectedIndex = 0;
}
}
function confirmDelete() {
var agree = confirm(_("Are you sure you wish to delete this template?"));
return agree;
}
var modaction_legend_innerhtml;
var action_submit_value;
function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
conditional_comparison, conditional_value, conditional_regex, description
) {
document.getElementById('mmta_id').value = mmta_id;
setSelectByValue( 'action', action );
document.getElementById('action').onchange();
setSelectByValue( 'field_number', field_number );
document.getElementById('from_field').value = from_field;
document.getElementById('from_subfield').value = from_subfield;
document.getElementById('field_value').value = field_value;
document.getElementById('to_field').value = to_field;
document.getElementById('to_subfield').value = to_subfield;
$("#to_regex_search").val(to_regex_search);
$("#to_regex_replace").val(to_regex_replace);
$("#to_regex_modifiers").val(to_regex_modifiers);
document.getElementById('to_field_regex').checked = conditional_regex.length;
document.getElementById('to_field_regex').onchange();
setSelectByValue( 'conditional', conditional );
document.getElementById('conditional').onchange();
document.getElementById('conditional_field').value = conditional_field;
document.getElementById('conditional_subfield').value = conditional_subfield;
setSelectByValue( 'conditional_comparison', conditional_comparison );
document.getElementById('conditional_comparison').onchange();
document.getElementById('conditional_value').value = conditional_value;
document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
document.getElementById('description').value = description;
window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
document.getElementById('modaction_legend').innerHTML = _("Edit action %s").format(ordering);
window.action_submit_value = document.getElementById('action_submit').value;
document.getElementById('action_submit').value = _("Update action");
show('cancel_edit');
}
function cancelEditAction() {
document.getElementById('mmta_id').value = '';
setSelectByValue( 'action', 'delete_field' );
document.getElementById('action').onchange();
document.getElementById('from_field').value = '';
document.getElementById('from_subfield').value = '';
document.getElementById('field_value').value = '';
document.getElementById('to_field').value = '';
document.getElementById('to_subfield').value = '';
$("#to_regex_search").val("");
$("#to_regex_replace").val("");
$("#to_regex_modifiers").val("");
document.getElementById('to_field_regex').checked = false;
document.getElementById('to_field_regex').onchange();
setSelectByValue( 'conditional', '' );
document.getElementById('conditional').onchange();
document.getElementById('conditional_field').value = '';
document.getElementById('conditional_subfield').value = '';
setSelectByValue( 'conditional_comparison', '' );
document.getElementById('conditional_comparison').onchange();
document.getElementById('conditional_value').value = '';
document.getElementById('conditional_regex').checked = false;
document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml;
document.getElementById('action_submit').value = window.action_submit_value;
hide('cancel_edit');
}
function setSelectByValue( selectId, value ) {
s = document.getElementById( selectId );
for ( i = 0; i < s.options.length; i++ ) {
if ( s.options[i].value == value ) {
s.selectedIndex = i;
}
}
}
</script>
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<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>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<h2>MARC modification templates</h2>
[% IF error %]
[% IF error == 'no_from_field' %]
<div class="dialog message">Error: no field value specified.</div>
[% END %]
[% END %]
[% IF ( TemplatesLoop ) %]
<form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="select_template">
<label for="select_template">Template: </label>
<select name="template_id" id="select_template" style="width:20em;">
[% FOREACH TemplatesLoo IN TemplatesLoop %]
[% IF ( TemplatesLoo.selected ) %]
<option value="[% TemplatesLoo.template_id %]" selected="selected"> [% TemplatesLoo.name %]</option>
[% ELSE %]
<option value="[% TemplatesLoo.template_id %]"> [% TemplatesLoo.name %]</option>
[% END %]
[% END %]
</select>
<input type="hidden" name="op" value="select_template">
<input type="submit" value="Go" />
</form>
<form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="delete_template">
<input type="hidden" name="template_id" value="[% template_id %]" />
<input type="hidden" name="op" value="delete_template">
<input type="submit" value="Delete template" onClick="return confirmDelete()" />
</form>
[% IF ( ActionsLoop ) %]
<table>
<caption>Actions for this template</caption>
<tr>
<th>Change order</th>
<th>Order</th>
<th>Action</th>
<th>Description</th>
<th>&nbsp</th>
<th>&nbsp</th>
</tr>
[% FOREACH ActionsLoo IN ActionsLoop %]
<tr>
<td style="white-space:nowrap;">
<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 %]">
<img src="[% interface %]/[% theme %]/img/go-up.png" border="0" alt="Go up" />
</a>
<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 %]">
<img src="[% interface %]/[% theme %]/img/go-top.png" border="0" alt="Go top" />
</a>
<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 %]">
<img src="[% interface %]/[% theme %]/img/go-bottom.png" border="0" alt="Go bottom" />
</a>
<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 %]">
<img src="[% interface %]/[% theme %]/img/go-down.png" border="0" alt="Go down" />
</a>
</td>
<td>[% ActionsLoo.ordering %]</td>
<td>
[% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
[% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
[% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
[% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
[% UNLESS ( ActionsLoo.action_update_field ) %]
[% IF ( ActionsLoo.field_number ) %]
1st
[% END %]
[% END %]
field
[% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %]
[% IF ( ActionsLoo.field_value ) %]
with value <i>[% ActionsLoo.field_value %]</i>
[% END %]
[% IF ( ActionsLoo.to_field ) %]
to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
[% IF ( ActionsLoo.to_regex_search ) %]
using RegEx s<strong>/[% ActionsLoo.to_regex_search %]/[% ActionsLoo.to_regex_replace %]/[% ActionsLoo.to_regex_modifiers %]</strong>
[% END %]
[% END %]
[% IF ( ActionsLoo.conditional ) %]
[% IF ( ActionsLoo.conditional_if ) %] if [% END %]
[% IF ( ActionsLoo.conditional_unless ) %] unless [% END %]
[% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %]
[% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %]
[% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %]
[% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %]
[% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %]
[% IF ( ActionsLoo.conditional_regex ) %] RegEx m/[% END %]
<strong>[% ActionsLoo.conditional_value %]</strong>
[% IF ( ActionsLoo.conditional_regex ) %]/[% END %]
[% END %]
</td>
<td>[% ActionsLoo.description %]</td>
<td><a href="#modaction" onclick='editAction(
"[% ActionsLoo.mmta_id |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.ordering |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.action |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.field_number |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.from_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.from_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.field_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.to_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.to_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.to_regex_search |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.to_regex_replace |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.to_regex_modifiers |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.conditional |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.conditional_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.conditional_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.conditional_comparison |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.conditional_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.conditional_regex |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
"[% ActionsLoo.description |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
)'>Edit</a></td>
<td><a href="marc_modification_templates.pl?template_id=[% ActionsLoo.template_id %]&op=delete_action&mmta_id=[% ActionsLoo.mmta_id %]">Delete</a></td>
</tr>
[% END %]
</table>
[% ELSE %]
<div class="dialog message"><p>There are no defined actions for this template.</p></div>
[% END %]
<form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_action" >
<a name="modaction"></a>
<fieldset>
<legend id="modaction_legend">Add a new action</legend>
<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>
<select name="action" id="action" onchange="onActionChange(this);">
<option value="delete_field">Delete</option>
<option value="update_field">Add/Update</option>
<option value="move_field">Move</option>
<option value="copy_field">Copy</option>
</select>
<span id="field_number_block">
<select name="field_number" id="field_number">
<option value="0">All</option>
<option value="1">1st</option>
</select>
</span>
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" />
<span name="with_value_block" id="with_value_block" style="display:none;">
with value <input type="text" name="field_value" id="field_value" />
</span>
<span name="to_field_block" id="to_field_block" style="display:none;">
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" />
<span name="to_field_regex_block" id="to_field_regex_block">
<sup>
<label for="to_field_regex">RegEx</label>
<input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
<span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
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" />
</span>
</sup>
</span>
</span>
<p/>
<select name="conditional" id="conditional" onchange="onConditionalChange(this);">
<option value="" selected="selected" />
<option value="if">if</option>
<option value="unless">unless</option>
</select>
<span name="conditional_block" id="conditional_block" style="display:none;">
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" />
<select name="conditional_comparison" id="conditional_comparison" onchange="onConditionalComparisonChange(this);">
<option value="" />
<option value="exists">exists</option>
<option value="not_exists">doesn't exist</option>
<option value="equals">matches</option>
<option value="not_equals">doesn't match</option>
</select>
<span name="conditional_comparison_block" id="conditional_comparison_block" style="display:none;">
<span class="match_regex_prefix">m/</span><input type="text" id="conditional_value" name="conditional_value" /><span class="match_regex_suffix">/</span>
<sup>
<label for="conditional_regex">RegEx</label>
<input type="checkbox" name="conditional_regex" id="conditional_regex" onchange="onConditionalRegexChange(this);" />
</sup>
</span>
</span>
<input type="hidden" name="template_id" value="[% template_id %]" />
<input type="hidden" name="mmta_id" id="mmta_id" />
<input type="hidden" name="op" value="add_action" />
<br/><br/>
<label for="description">Description:</label>
<input type="text" name="description" id="description" size="60" />
<br/><br/>
<input id="action_submit" type="submit" value="Add action" /> <a href="#modaction" id="cancel_edit" onclick="cancelEditAction();" style="display:none;">Cancel</a>
</fieldset>
</form>
[% ELSE %]
<div class="dialog message"><p>There are no defined templates. Please create a template first.</p></div>
[% END %]
<form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_template" class="validated">
<fieldset>
<legend>Create a new template</legend>
<label for="template_name" class="required">Name: </label>
<input name="template_name" id="template_name" type="text" size="30" required="required" class="required" />
<span class="required">Required</span>
<input type="hidden" name="op" value="create_template" />
<input type="submit" value="Create template" />
[% IF ( template_id ) %]
<input type="hidden" name="template_id" value="[% template_id %]" />
<input type="checkbox" name="duplicate_current_template" id="duplicate_current_template" />
<label for="duplicate_current_template">Duplicate current template</label>
[% END %]
</fieldset>
</form>
</div>
</div>
<div class="yui-b">
[% INCLUDE 'tools-menu.inc' %]
</div>
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]