From 69ceb326f61ce94bbac740078eb3ebb8f41a03a1 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 19 Apr 2016 21:02:05 -0400 Subject: [PATCH] Bug 16305 - Remove the use of "onclick" from transport cost matrix MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch updates the transport cost matrix template to eliminate the use of event attributes (onclick and onblur) in favor of JS separate from the markup. To test, apply the patch and go to Administration -> Transport cost matrix. - Click in any table cell. Form fields in the cell should activate. - Check and uncheck the "disable" checkbox. The form field should be correctly disabled and enabled. - Fill various enabled fields and submit the form to confirm that data is saved correctly. Signed-off-by: Marc Véron Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall --- .../en/modules/admin/transport-cost-matrix.tt | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/transport-cost-matrix.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/transport-cost-matrix.tt index f108dbd8e4..dfdf64c3b7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/transport-cost-matrix.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/transport-cost-matrix.tt @@ -11,7 +11,9 @@ function check_transport_cost(e) { } alert(_("Cost must be expressed as a decimal number >= 0")); } -function disable_transport_cost_chg(e, cost_id) { +function disable_transport_cost_chg(e) { + var input_name = e.name; + var cost_id = input_name.replace(/disable_/,''); // Parse the code_id out of the input name disable_transport_cost(cost_id, e.checked); } function disable_transport_cost(cost_id, disable) { @@ -28,8 +30,8 @@ function enable_cost_input(cost_id) { $(cell).removeClass('disabled-transfer'); $('#celldiv_'+cost_id).html( - ''+ - '
Disable ' + ''+ + '
Disable ' ); disable_transport_cost(cost_id, disabled); } @@ -38,6 +40,18 @@ function form_submit (f) { $(f).find('input:disabled').prop('disabled', false); return true; } +$(document).ready(function(){ + $(".enable_cost_input").on("click",function(){ + var cost_id = $(this).data("cost-id"); + enable_cost_input( cost_id ); + }); + $("body").on("blur",".cost_input",function(){ + check_transport_cost(this); + }); + $("body").on("change",".disable_transport_cost",function(){ + disable_transport_cost_chg(this); + }); +}) //]]>