From c8ea6ba025455a26a585733fdb214942a9823a45 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 30 Jan 2013 15:19:58 +0100 Subject: [PATCH] Bug 9507: prevent submit: refactor some code in a js file This patch refactors some code in a js file. Test plan: On acqui/neworderempty.pl, acqui/orderreceive.pl and serials/serials-edit.tt try to scan a barcode (or press enter) on the form and check that it is not sent. Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy Have to note that the code for IE9 does not work. Before and after this patch. If we refactor code, it would have been nice to resolve this too. But I do not oppose pushing this patch. The test uses 'an ancient Netscape property' window.Event (uppercase!) to make the distinction between browers and event models. Some more documentation here would be welcome too. Signed-off-by: Galen Charlton (cherry picked from commit 9e4c289d3f68aaab5d47172940e30fba0819804e) Signed-off-by: Tomas Cohen Arazi Refactoring, but needed for 10310 inclusion --- .../prog/en/js/prevent_submit.js | 18 +++++++++++++++++ .../prog/en/modules/acqui/neworderempty.tt | 19 +----------------- .../prog/en/modules/acqui/orderreceive.tt | 20 +------------------ .../prog/en/modules/serials/serials-edit.tt | 19 +----------------- 4 files changed, 21 insertions(+), 55 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/prevent_submit.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/prevent_submit.js b/koha-tmpl/intranet-tmpl/prog/en/js/prevent_submit.js new file mode 100644 index 0000000000..bafd42ac93 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/js/prevent_submit.js @@ -0,0 +1,18 @@ +var prevent_nav = window.Event ? true : false; +if (prevent_nav) { + window.captureEvents(Event.KEYDOWN); + window.onkeydown = NetscapeEventHandler_KeyDown; +} else { + document.onkeydown = IEEventHandler_KeyDown; +} + +function NetscapeEventHandler_KeyDown(e) { + if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false; } + return true; +} + +function IEEventHandler_KeyDown() { + if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit') + return false; + return true; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index cc554ed62d..87cfa8a1bb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -6,25 +6,8 @@ [% INCLUDE 'additem.js.inc' %] + + +