Bug 42467: Remove event attributes from MARC modification templates template
This patch removes several "onChange" event attributes from
marc_modification_templates.tt and moves the event handlers into
marc_modification_templates.js.
The patch also corrects a view minor zxlinting errors in the JS file.
To test, apply the patch and clear your browser cache if necessary.
- Go to Cataloging -> MARC modification templates.
- Create a new template if necessary.
- Click "New action."
- Test the behavior of dropdowns and checkboxes in the new action form.
- Fields should be correctly shown or hidden based on the selected
actions
- Fields should be correctly shown or hidden based on the "RegEx"
checkbox.
- Text the conditional dropdown along with the "matches" dropdown.
- Test that the "matches" regex fields are correctly displayed
according to the checkbox.
- The browser developer console should show no "Content-Security-Policy"
errors.
Sponsored-by: Athens County Public Libraries
Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 561e8180ce)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
This commit is contained in:
parent
281f826ee7
commit
0e9b3edb0c
|
|
@ -242,7 +242,7 @@
|
|||
>
|
||||
|
||||
<div class="action_line">
|
||||
<select name="action" id="action" onchange="onActionChange(this);">
|
||||
<select name="action" id="action">
|
||||
<option value="delete_field">Delete</option>
|
||||
<option value="add_field">Add new</option>
|
||||
<option value="update_field">Update existing or add new</option>
|
||||
|
|
@ -268,7 +268,7 @@
|
|||
<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);" />
|
||||
<input type="checkbox" name="to_field_regex" id="to_field_regex" />
|
||||
|
||||
<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
|
||||
|
|
@ -284,7 +284,7 @@
|
|||
</div>
|
||||
|
||||
<div class="action_line">
|
||||
<select name="conditional" id="conditional" onchange="onConditionalChange(this);">
|
||||
<select name="conditional" id="conditional">
|
||||
<option value="" selected="selected" />
|
||||
<option value="if">if</option>
|
||||
<option value="unless">unless</option>
|
||||
|
|
@ -293,7 +293,7 @@
|
|||
<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);">
|
||||
<select name="conditional_comparison" id="conditional_comparison">
|
||||
<option value="" />
|
||||
<option value="exists">exists</option>
|
||||
<option value="not_exists">doesn't exist</option>
|
||||
|
|
@ -306,7 +306,7 @@
|
|||
|
||||
<sup>
|
||||
<label for="conditional_regex">RegEx</label>
|
||||
<input type="checkbox" name="conditional_regex" id="conditional_regex" onchange="onConditionalRegexChange(this);" />
|
||||
<input type="checkbox" name="conditional_regex" id="conditional_regex" />
|
||||
</sup>
|
||||
</span>
|
||||
</span>
|
||||
|
|
@ -322,7 +322,7 @@
|
|||
<input type="hidden" name="mmta_id" id="mmta_id" />
|
||||
<input type="hidden" name="op" value="cud-add_action" />
|
||||
<input type="submit" id="action_submit" class="btn btn-primary" value="Add action" />
|
||||
<a href="#modaction" class="cancel" id="cancel_edit" onclick="cancelEditAction();">Cancel</a>
|
||||
<a href="#modaction" class="cancel" id="cancel_edit">Cancel</a>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
|
@ -381,8 +381,9 @@
|
|||
[% INCLUDE 'datatables.inc' %]
|
||||
<script>
|
||||
table_settings = [% TablesSettings.GetTableSettings('tools', 'marc-modification-templates', 'templatest', 'json') | $raw %];
|
||||
var mmtas;
|
||||
[% IF ActionsLoop %]
|
||||
var mmtas = [% ActionsLoop.json | $raw %]
|
||||
mmtas = [% ActionsLoop.json | $raw %]
|
||||
[% END %]
|
||||
</script>
|
||||
[% Asset.js("js/marc_modification_templates.js") | $raw %]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* global __ kohaTable table_settings */
|
||||
/* global __ kohaTable table_settings mmtas */
|
||||
$(document).ready(function () {
|
||||
window.modaction_legend_innerhtml = $("#modaction_legend").text();
|
||||
window.action_submit_value = $("#action_submit").val();
|
||||
|
|
@ -10,6 +10,10 @@ $(document).ready(function () {
|
|||
$("span.match_regex_prefix").hide();
|
||||
$("span.match_regex_suffix").hide();
|
||||
|
||||
$("#action").on("change", function () {
|
||||
onActionChange(this);
|
||||
});
|
||||
|
||||
$("#add_action").submit(function () {
|
||||
var action = $("#action").val();
|
||||
if (
|
||||
|
|
@ -101,6 +105,11 @@ $(document).ready(function () {
|
|||
updateAllEvery();
|
||||
});
|
||||
|
||||
$("#cancel_edit").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
cancelEditAction();
|
||||
});
|
||||
|
||||
$(".new_action").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
cancelEditAction();
|
||||
|
|
@ -132,7 +141,7 @@ $(document).ready(function () {
|
|||
|
||||
$(".edit_action").on("click", function () {
|
||||
var mmta_id = $(this).data("mmta_id");
|
||||
var mmta = $.grep(mmtas, function (elt, id) {
|
||||
var mmta = $.grep(mmtas, function (elt) {
|
||||
return elt["mmta_id"] == mmta_id;
|
||||
});
|
||||
editAction(mmta[0]);
|
||||
|
|
@ -150,6 +159,22 @@ $(document).ready(function () {
|
|||
$(".confirm-delete-template").on("click", function () {
|
||||
return confirm(__("Are you sure you wish to delete this template?"));
|
||||
});
|
||||
|
||||
$("#to_field_regex").on("change", function () {
|
||||
onToFieldRegexChange(this);
|
||||
});
|
||||
|
||||
$("#conditional_regex").on("change", function () {
|
||||
onConditionalRegexChange(this);
|
||||
});
|
||||
|
||||
$("#conditional").on("change", function () {
|
||||
onConditionalChange(this);
|
||||
});
|
||||
|
||||
$("#conditional_comparison").on("change", function () {
|
||||
onConditionalComparisonChange(this);
|
||||
});
|
||||
});
|
||||
|
||||
function updateAllEvery() {
|
||||
|
|
@ -268,18 +293,18 @@ function onConditionalRegexChange(checkboxObj) {
|
|||
}
|
||||
|
||||
function show(eltId) {
|
||||
elt = document.getElementById(eltId);
|
||||
let elt = document.getElementById(eltId);
|
||||
elt.style.display = "inline";
|
||||
}
|
||||
|
||||
function hide(eltId) {
|
||||
clearFormElements(eltId);
|
||||
elt = document.getElementById(eltId);
|
||||
let elt = document.getElementById(eltId);
|
||||
elt.style.display = "none";
|
||||
}
|
||||
|
||||
function clearFormElements(divId) {
|
||||
myBlock = document.getElementById(divId);
|
||||
let myBlock = document.getElementById(divId);
|
||||
|
||||
var inputElements = myBlock.getElementsByTagName("input");
|
||||
for (var i = 0; i < inputElements.length; i++) {
|
||||
|
|
@ -294,14 +319,11 @@ function clearFormElements(divId) {
|
|||
}
|
||||
|
||||
var selectElements = myBlock.getElementsByTagName("select");
|
||||
for (var i = 0; i < selectElements.length; i++) {
|
||||
selectElements[i].selectedIndex = 0;
|
||||
for (var k = 0; k < selectElements.length; k++) {
|
||||
selectElements[k].selectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
var modaction_legend_innerhtml;
|
||||
var action_submit_value;
|
||||
|
||||
function editAction(mmta) {
|
||||
$("#add_action").show();
|
||||
document.getElementById("mmta_id").value = mmta["mmta_id"];
|
||||
|
|
@ -403,9 +425,9 @@ function cancelEditAction() {
|
|||
}
|
||||
|
||||
function setSelectByValue(selectId, value) {
|
||||
s = document.getElementById(selectId);
|
||||
let s = document.getElementById(selectId);
|
||||
|
||||
for (i = 0; i < s.options.length; i++) {
|
||||
for (let i = 0; i < s.options.length; i++) {
|
||||
if (s.options[i].value == value) {
|
||||
s.selectedIndex = i;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue