Bugzilla – Attachment 48313 Details for
Bug 15867
Move MARC modification templates JavaScript into separate file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF]Bug 15867: Move MARC modification templates JavaScript into separate file
SIGNED-OFFBug-15867-Move-MARC-modification-templat.patch (text/plain), 23.12 KB, created by
Héctor Eduardo Castro Avalos
on 2016-02-23 15:04:45 UTC
(
hide
)
Description:
[SIGNED-OFF]Bug 15867: Move MARC modification templates JavaScript into separate file
Filename:
MIME Type:
Creator:
Héctor Eduardo Castro Avalos
Created:
2016-02-23 15:04:45 UTC
Size:
23.12 KB
patch
obsolete
>From 89f8d0995e9721e4f0d0c1e4d48470922ed8b898 Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >Date: Fri, 19 Feb 2016 13:30:44 -0500 >Subject: [PATCH] [SIGNED-OFF]Bug 15867: Move MARC modification templates > JavaScript into separate file > >The JavaScript embedded in the MARC modification templates template is >not dependent on template processing to such an extent that it can't >be safely moved to a separate file. This patch does so, adding >definition of a some translatable strings to the template. > >Other minor changes: A couple of JSHint warnings corrected, a couple of >missing semicolons added to template markup. > >To test, apply the patch and go to Tools -> MARC modification templates > >- Confirm that The add/update form works normally with various actions > (Add/update,Delete,Move, etc.). >- Confirm that template switching works correctly. >- Confirm that template deletion confirmation works correctly. >- Confirm that cancelling an edit works correctly > >Signed-off-by: Hector Castro <hector.hecaxmmx@gmail.com> >Works as advertised >--- > .../prog/en/js/marc_modification_templates.js | 288 ++++++++++++++++++ > .../modules/tools/marc_modification_templates.tt | 315 ++------------------ > 2 files changed, 305 insertions(+), 298 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/marc_modification_templates.js > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/marc_modification_templates.js b/koha-tmpl/intranet-tmpl/prog/en/js/marc_modification_templates.js >new file mode 100644 >index 0000000..185afa8 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/js/marc_modification_templates.js >@@ -0,0 +1,288 @@ >+$(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' || action == 'copy_and_replace_field') { >+ if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) { >+ alert( MSG_MMT_SUBFIELDS_MATCH ); >+ return false; >+ } >+ if ( $("#to_field").val().length <= 0 ) { >+ alert( MSG_MMT_DESTINATION_REQUIRED ); >+ return false; >+ } >+ if ( ( $("#to_field").val() < 10 && $("#to_subfield").val().length > 0 ) || >+ ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) { >+ alert( MSG_MMT_CONTROL_FIELD_EMPTY ); >+ return false; >+ } >+ if ( ( $("#from_field").val() < 10 && $("#to_subfield").val().length === 0 ) || >+ ( $("#to_field").val() < 10 && $("#from_subfield").val().length === 0 ) ) { >+ alert( MSG_MMT_CONTROL_FIELD ); >+ return false; >+ } >+ } >+ if ( action == 'update_field' ) { >+ if ( $("#from_subfield").val().length <= 0 ) { >+ alert( MSG_MMT_SOURCE_SUBFIELD ); >+ return false; >+ } >+ } >+ if ( $("#from_field").val().length <= 0 ) { >+ alert( MSG_MMT_SOURCE_FIELD ); >+ return false; >+ } >+ }); >+ >+ $("#conditional_field,#from_field").change(function(){ >+ updateAllEvery(); >+ }); >+}); >+ >+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( MSG_MMT_EVERY ); >+ } else { >+ $("#field_number option[value='0']").html( MSG_MMT_ALL ); >+ } >+ } >+} >+ >+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; >+ >+ case 'copy_and_replace_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( MSG_MMT_CONFIRM_DEL_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 = MSG_MMT_EDIT_ACTION.format(ordering); >+ >+ window.action_submit_value = document.getElementById('action_submit').value; >+ document.getElementById('action_submit').value = MSG_MMT_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; >+ } >+ } >+} >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt >index 0dcaab9..e621de2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt >@@ -1,303 +1,22 @@ > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Tools › 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' || 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 ( ( $("#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 ( ( $("#from_field").val() < 10 && $("#to_subfield").val().length == 0 ) || >- ( $("#to_field").val() < 10 && $("#from_subfield").val().length == 0 ) ) { >- alert(_("A control field cannot be used with a regular field.")); >- 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; >- } >- }); >- >- $("#conditional_field,#from_field").change(function(){ >- updateAllEvery(); >- }); >-}); >-//]]> >+ //<![CDATA[ >+ var MSG_MMT_SUBFIELDS_MATCH = _("Both subfield values should be filled or empty."); >+ var MSG_MMT_DESTINATION_REQUIRED = _("The destination should be filled."); >+ var MSG_MMT_CONTROL_FIELD_EMPTY = _("If the field is a control field, the subfield should be empty"); >+ var MSG_MMT_CONTROL_FIELD = _("A control field cannot be used with a regular field."); >+ var MSG_MMT_SOURCE_SUBFIELD = _("The source subfield should be filled for update."); >+ var MSG_MMT_SOURCE_FIELD = _("The source field should be filled."); >+ var MSG_MMT_EVERY = _("Every"); >+ var MSG_MMT_ALL = _("All"); >+ var MSG_MMT_CONFIRM_DEL_TEMPLATE= _("Are you sure you wish to delete this template?"); >+ var MSG_MMT_EDIT_ACTION = _("Edit action %s"); >+ var MSG_MMT_UPDATE_ACTION = _("Update action"); >+ //]]> > </script> >- >-<script> >-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")); >- } >- } >-} >- >-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; >- >- case 'copy_and_replace_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> >- >+<script type="text/javascript" src="[% themelang %]/js/marc_modification_templates.js"></script> > </head> > > <body id="tools_marc_modification_templates" class="tools"> >@@ -311,7 +30,7 @@ function setSelectByValue( selectId, value ) { > <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> >@@ -351,8 +70,8 @@ function setSelectByValue( selectId, value ) { > <th>Order</th> > <th>Action</th> > <th>Description</th> >- <th> </th> >- <th> </th> >+ <th> </th> >+ <th> </th> > </tr> > > [% FOREACH ActionsLoo IN ActionsLoop %] >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15867
:
48253
|
48313
|
48461