From 61db92209d48038c0552c10992c5928de37246a6 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 10 Apr 2024 03:24:21 +0000 Subject: [PATCH] Bug 36515: Amend MARC modification templates so control fields can be copied to subfields Test plan: 1. Apply patch and restart services 2. Create a MARC modification template to move 001 to 099$a 3. Perform a Batch record modification using your MARC modification template from #1 4. Confirm that the template has successfully moved the 001 control field value to the 099$a subfield Sponsored-by: Education Services Australia SCIS --- Koha/SimpleMARC.pm | 5 +- .../prog/js/marc_modification_templates.js | 392 ++++++++++-------- 2 files changed, 223 insertions(+), 174 deletions(-) diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm index a77ce9ea9e7..81657cf943c 100644 --- a/Koha/SimpleMARC.pm +++ b/Koha/SimpleMARC.pm @@ -133,8 +133,9 @@ sub copy_and_replace_field { if ( ! ( $record && $fromFieldName && $toFieldName ) ) { return; } - if ( !defined $fromSubfieldName or $fromSubfieldName eq '' - or !defined $toSubfieldName or $toSubfieldName eq '' + if ( + ( !defined $fromSubfieldName or $fromSubfieldName eq '' ) + and ( !defined $toSubfieldName or $toSubfieldName eq '' ) ) { _copy_move_field( { record => $record, diff --git a/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js b/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js index 39dfd7226d7..d6526f73faa 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js +++ b/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js @@ -1,74 +1,107 @@ /* global __ KohaTable table_settings */ -$(document).ready(function() { +$(document).ready(function () { window.modaction_legend_innerhtml = $("#modaction_legend").text(); window.action_submit_value = $("#action_submit").val(); - $('#select_template').find("input:submit").hide(); - $('#select_template').change(function() { - $('#select_template').submit(); + $("#select_template").find("input:submit").hide(); + $("#select_template").change(function () { + $("#select_template").submit(); }); - $("span.match_regex_prefix" ).hide(); - $("span.match_regex_suffix" ).hide(); + $("span.match_regex_prefix").hide(); + $("span.match_regex_suffix").hide(); - $("#add_action").submit(function(){ + $("#add_action").submit(function () { var action = $("#action").val(); - if ( action == 'move_field' || action == 'copy_field' || action == 'copy_and_replace_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 == "move_field" || + action == "copy_field" || + action == "copy_and_replace_field" + ) { + if ( + $("#from_subfield").val().length != + $("#to_subfield").val().length + ) { + if ( + $("#to_field").val() >= 10 && + $("#to_subfield").val().length > 0 && + $("#from_field").val() >= 10 && + $("#from_subfield").val().length > 0 + ) { + alert( + __("Both subfield values should be filled or empty.") + ); + return false; + } } - if ( ( $("#to_field").val() < 10 && $("#to_subfield").val().length > 0 ) || - ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) { - alert( __("If the field is a control field, the subfield should be empty") ); + if ($("#to_field").val().length <= 0) { + alert(__("The destination should be filled.")); return false; } - if ( ( $("#from_field").val() < 10 && $("#to_field").val() >= 10 ) || - ( $("#to_field").val() < 10 && $("#from_field").val() >= 10 ) ) { - alert( __("A control field cannot be used with a regular field.") ); + if ( + ($("#to_field").val() < 10 && + $("#to_subfield").val().length > 0) || + ($("#from_field").val() < 10 && + $("#from_subfield").val().length > 0) + ) { + alert( + __( + "If the field is a control field, the subfield should be empty" + ) + ); return false; } } - if ( action == 'update_field' ) { - if ( $("#from_subfield").val().length <= 0 ) { - alert( __("The source subfield should be filled for update.") ); + 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.") ); + if ($("#from_field").val().length <= 0) { + alert(__("The source field should be filled.")); return false; } - if ( $("#conditional").val() == 'if' || $("#conditional").val() == 'unless' ) { - if ( $("#conditional_field").val() == '' ) { - alert( __("The conditional field should be filled.") ); + if ( + $("#conditional").val() == "if" || + $("#conditional").val() == "unless" + ) { + if ($("#conditional_field").val() == "") { + alert(__("The conditional field should be filled.")); return false; } - if ( $("#conditional_comparison").val() == '' ) { - alert( __("The conditional comparison operator should be filled.") ); + if ($("#conditional_comparison").val() == "") { + alert( + __("The conditional comparison operator should be filled.") + ); return false; } - if ( $("#conditional_value").val() == '' && - ( $("#conditional_comparison").val() == 'equals' || $("#conditional_comparison").val() == 'not_equals' ) ) { - if ( document.getElementById('conditional_regex').checked == true ) { - alert( __("The conditional regular expression should be filled.") ); + if ( + $("#conditional_value").val() == "" && + ($("#conditional_comparison").val() == "equals" || + $("#conditional_comparison").val() == "not_equals") + ) { + if ( + document.getElementById("conditional_regex").checked == true + ) { + alert( + __( + "The conditional regular expression should be filled." + ) + ); return false; } else { - alert( __("The conditional value should be filled.") ); + alert(__("The conditional value should be filled.")); return false; } } } }); - $("#conditional_field,#from_field").change(function(){ + $("#conditional_field,#from_field").change(function () { updateAllEvery(); }); - $(".new_action").on("click",function(e){ + $(".new_action").on("click", function (e) { e.preventDefault(); cancelEditAction(); $("#no_defined_actions").hide(); @@ -76,54 +109,58 @@ $(document).ready(function() { $("#action").focus(); }); - $(".duplicate_template").on("click",function(e){ + $(".duplicate_template").on("click", function (e) { e.preventDefault(); var template_id = $(this).data("template_id"); $("#duplicate_a_template").val(template_id); $("#duplicate_current_template").val(1); }); - $('#createTemplate').on('shown.bs.modal', function (e) { + $("#createTemplate").on("shown.bs.modal", function (e) { e.preventDefault(); $("#template_name").focus(); }); - $("#duplicate_a_template").on("change",function(e){ + $("#duplicate_a_template").on("change", function (e) { e.preventDefault(); - if( this.value === '' ){ + if (this.value === "") { $("#duplicate_current_template").val(""); } else { $("#duplicate_current_template").val(1); } }); - $(".edit_action").on("click", function(){ + $(".edit_action").on("click", function () { var mmta_id = $(this).data("mmta_id"); - var mmta = $.grep(mmtas, function(elt, id) { - return elt['mmta_id'] == mmta_id; + var mmta = $.grep(mmtas, function (elt, id) { + return elt["mmta_id"] == mmta_id; }); - editAction( mmta[0] ); + editAction(mmta[0]); updateAllEvery(); }); - KohaTable("templatest", { - }, table_settings); + KohaTable("templatest", {}, table_settings); - $(".confirm-delete-action").on("click", function(){ - return confirm( __("Are you sure you wish to delete this template action?") ); + $(".confirm-delete-action").on("click", function () { + return confirm( + __("Are you sure you wish to delete this template action?") + ); }); - $(".confirm-delete-template").on("click", function(){ - return confirm( __("Are you sure you wish to delete this template?") ); + $(".confirm-delete-template").on("click", function () { + return confirm(__("Are you sure you wish to delete this template?")); }); }); -function updateAllEvery(){ - if ( $("#conditional_field").is(":visible") ) { - if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) { - $("#field_number option[value='0']").html( __("Every") ); +function updateAllEvery() { + if ($("#conditional_field").is(":visible")) { + if ( + $("#conditional_field").val() == $("#from_field").val() && + $("#from_field").val().length > 0 + ) { + $("#field_number option[value='0']").html(__("Every")); } else { - $("#field_number option[value='0']").html( __("All") ); + $("#field_number option[value='0']").html(__("All")); } } } @@ -135,43 +172,42 @@ function onActionChange(selectObj) { // 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'); + switch (action) { + case "delete_field": + show("field_number_block"); + hide("with_value_block"); + hide("to_field_block"); break; - case 'add_field': - hide('field_number_block'); - show('with_value_block'); - hide('to_field_block'); + case "add_field": + hide("field_number_block"); + show("with_value_block"); + hide("to_field_block"); break; - case 'update_field': - hide('field_number_block'); - show('with_value_block'); - hide('to_field_block'); + 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'); + 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'); + case "copy_field": + show("field_number_block"); + hide("with_value_block"); + show("to_field_block"); break; - case 'copy_and_replace_field': - show('field_number_block'); - hide('with_value_block'); - show('to_field_block'); + case "copy_and_replace_field": + show("field_number_block"); + hide("with_value_block"); + show("to_field_block"); break; - } } @@ -182,14 +218,14 @@ function onConditionalChange(selectObj) { // get the value of the selected option var action = selectObj.options[idx].value; - switch( action ) { - case '': - hide('conditional_block'); + switch (action) { + case "": + hide("conditional_block"); break; - case 'if': - case 'unless': - show('conditional_block'); + case "if": + case "unless": + show("conditional_block"); break; } } @@ -201,55 +237,55 @@ function onConditionalComparisonChange(selectObj) { // get the value of the selected option var action = selectObj.options[idx].value; - switch( action ) { - case 'equals': - case 'not_equals': - show('conditional_comparison_block'); + switch (action) { + case "equals": + case "not_equals": + show("conditional_comparison_block"); break; default: - hide('conditional_comparison_block'); + hide("conditional_comparison_block"); break; } } -function onToFieldRegexChange( checkboxObj ) { - if ( checkboxObj.checked ) { - show('to_field_regex_value_block'); +function onToFieldRegexChange(checkboxObj) { + if (checkboxObj.checked) { + show("to_field_regex_value_block"); } else { - hide('to_field_regex_value_block'); + hide("to_field_regex_value_block"); } } -function onConditionalRegexChange( checkboxObj ) { - if ( checkboxObj.checked ) { - $("span.match_regex_prefix" ).show(); - $("span.match_regex_suffix" ).show(); +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(); + $("span.match_regex_prefix").hide(); + $("span.match_regex_suffix").hide(); } } function show(eltId) { - elt = document.getElementById( eltId ); - elt.style.display='inline'; + elt = document.getElementById(eltId); + elt.style.display = "inline"; } function hide(eltId) { - clearFormElements( eltId ); - elt = document.getElementById( eltId ); - elt.style.display='none'; + clearFormElements(eltId); + elt = document.getElementById(eltId); + elt.style.display = "none"; } function clearFormElements(divId) { - myBlock = document.getElementById( divId ); + myBlock = document.getElementById(divId); - var inputElements = myBlock.getElementsByTagName( "input" ); + var inputElements = myBlock.getElementsByTagName("input"); for (var i = 0; i < inputElements.length; i++) { - switch( inputElements[i].type ) { + switch (inputElements[i].type) { case "text": - inputElements[i].value = ''; + inputElements[i].value = ""; break; case "checkbox": inputElements[i].checked = false; @@ -257,108 +293,120 @@ function clearFormElements(divId) { } } - var selectElements = myBlock.getElementsByTagName( "select" ); + var selectElements = myBlock.getElementsByTagName("select"); for (var i = 0; i < selectElements.length; i++) { selectElements[i].selectedIndex = 0; } - } var modaction_legend_innerhtml; var action_submit_value; -function editAction( mmta ) { +function editAction(mmta) { $("#add_action").show(); - document.getElementById('mmta_id').value = mmta['mmta_id']; - - setSelectByValue( 'action', mmta['action'] ); - $('#action').change(); - - setSelectByValue( 'field_number', mmta['field_number'] ); - - document.getElementById('from_field').value = mmta['from_field']; - document.getElementById('from_subfield').value = mmta['from_subfield']; - document.getElementById('field_value').value = mmta['field_value']; - document.getElementById('to_field').value = mmta['to_field']; - document.getElementById('to_subfield').value = mmta['to_subfield']; - if ( mmta['regex_search'] == '' && mmta['to_regex_replace'] == '' && mmta['to_regex_modifiers'] == '' ) { - $('#to_field_regex').prop('checked', false).change(); + document.getElementById("mmta_id").value = mmta["mmta_id"]; + + setSelectByValue("action", mmta["action"]); + $("#action").change(); + + setSelectByValue("field_number", mmta["field_number"]); + + document.getElementById("from_field").value = mmta["from_field"]; + document.getElementById("from_subfield").value = mmta["from_subfield"]; + document.getElementById("field_value").value = mmta["field_value"]; + document.getElementById("to_field").value = mmta["to_field"]; + document.getElementById("to_subfield").value = mmta["to_subfield"]; + if ( + mmta["regex_search"] == "" && + mmta["to_regex_replace"] == "" && + mmta["to_regex_modifiers"] == "" + ) { + $("#to_field_regex").prop("checked", false).change(); } else { - $('#to_field_regex').prop('checked', true).change(); - $("#to_regex_search").val(mmta['to_regex_search']); - $("#to_regex_replace").val(mmta['to_regex_replace']); - $("#to_regex_modifiers").val(mmta['to_regex_modifiers']); + $("#to_field_regex").prop("checked", true).change(); + $("#to_regex_search").val(mmta["to_regex_search"]); + $("#to_regex_replace").val(mmta["to_regex_replace"]); + $("#to_regex_modifiers").val(mmta["to_regex_modifiers"]); } - setSelectByValue( 'conditional', mmta['conditional'] ); - $('#conditional').change(); + setSelectByValue("conditional", mmta["conditional"]); + $("#conditional").change(); - document.getElementById('conditional_field').value = mmta['conditional_field']; - document.getElementById('conditional_subfield').value = mmta['conditional_subfield']; + document.getElementById("conditional_field").value = + mmta["conditional_field"]; + document.getElementById("conditional_subfield").value = + mmta["conditional_subfield"]; - setSelectByValue( 'conditional_comparison', mmta['conditional_comparison'] ); - $('#conditional_comparison').change(); + setSelectByValue("conditional_comparison", mmta["conditional_comparison"]); + $("#conditional_comparison").change(); - document.getElementById('conditional_value').value = mmta['conditional_value']; + document.getElementById("conditional_value").value = + mmta["conditional_value"]; - document.getElementById('conditional_regex').checked = parseInt( mmta['conditional_regex'] ); - $('#conditional_regex').change(); + document.getElementById("conditional_regex").checked = parseInt( + mmta["conditional_regex"] + ); + $("#conditional_regex").change(); - document.getElementById('description').value = mmta['description']; + document.getElementById("description").value = mmta["description"]; - window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML; - document.getElementById('modaction_legend').innerHTML = __("Edit action %s").format(mmta['ordering']); + window.modaction_legend_innerhtml = + document.getElementById("modaction_legend").innerHTML; + document.getElementById("modaction_legend").innerHTML = __( + "Edit action %s" + ).format(mmta["ordering"]); - window.action_submit_value = document.getElementById('action_submit').value; - document.getElementById('action_submit').value = __("Update action"); + window.action_submit_value = document.getElementById("action_submit").value; + document.getElementById("action_submit").value = __("Update action"); } function cancelEditAction() { - document.getElementById('mmta_id').value = ''; + document.getElementById("mmta_id").value = ""; - setSelectByValue( 'action', 'delete_field' ); - $('#action').change(); + setSelectByValue("action", "delete_field"); + $("#action").change(); - 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 = ''; + 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(""); $("#description").val(""); - $('#to_field_regex').prop('checked', false).change(); + $("#to_field_regex").prop("checked", false).change(); - setSelectByValue( 'conditional', '' ); - $('#conditional').change(); + setSelectByValue("conditional", ""); + $("#conditional").change(); - document.getElementById('conditional_field').value = ''; - document.getElementById('conditional_subfield').value = ''; + document.getElementById("conditional_field").value = ""; + document.getElementById("conditional_subfield").value = ""; - setSelectByValue( 'conditional_comparison', '' ); - $('#conditional_comparison').change(); + setSelectByValue("conditional_comparison", ""); + $("#conditional_comparison").change(); - document.getElementById('conditional_value').value = ''; + document.getElementById("conditional_value").value = ""; - document.getElementById('conditional_regex').checked = false; + document.getElementById("conditional_regex").checked = false; - document.getElementById('modaction_legend').innerHTML = window.modaction_legend_innerhtml; - document.getElementById('action_submit').value = window.action_submit_value; + document.getElementById("modaction_legend").innerHTML = + window.modaction_legend_innerhtml; + document.getElementById("action_submit").value = window.action_submit_value; - if( $("#template_actions").length < 1 ){ + if ($("#template_actions").length < 1) { $("#no_defined_actions").show(); } $("#add_action").hide(); } -function setSelectByValue( selectId, value ) { - s = document.getElementById( selectId ); +function setSelectByValue(selectId, value) { + s = document.getElementById(selectId); - for ( i = 0; i < s.options.length; i++ ) { - if ( s.options[i].value == value ) { + for (i = 0; i < s.options.length; i++) { + if (s.options[i].value == value) { s.selectedIndex = i; } } -- 2.30.2