From a885752801a2a6b0dfd5a361485f633e68941691 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 22 Apr 2025 01:27:15 +0000 Subject: [PATCH] Bug 39567: Run JS change in separate file ESM as per JS1 As per JS1 in the coding guidelines, I've moved the inline JS from the template into a separate file. Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer (cherry picked from commit eeb86254dac56b660467ef7cc32cd9049904d52e) Signed-off-by: Fridolin Somers --- .../prog/en/includes/js_includes.inc | 8 +-- .../intranet-tmpl/prog/js/form-submit.js | 65 ++++++++++--------- .../bootstrap/en/includes/opac-bottom.inc | 8 +-- .../opac-tmpl/bootstrap/js/form-submit.js | 59 +++++++++-------- 4 files changed, 69 insertions(+), 71 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc index 314abd0c38..90e1c9bb75 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -26,13 +26,7 @@ [% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %] [% Asset.js("js/staff-global.js") | $raw %] - +[% Asset.js("js/form-submit.js",{'type' => 'module'}) | $raw %] [% INCLUDE 'js-date-format.inc' %] [% INCLUDE 'js-patron-get-age.inc' %] [% INCLUDE 'js-patron-format-address.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/form-submit.js b/koha-tmpl/intranet-tmpl/prog/js/form-submit.js index 72aa076677..bcaaaa72ca 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/form-submit.js +++ b/koha-tmpl/intranet-tmpl/prog/js/form-submit.js @@ -1,35 +1,40 @@ -export function submit_form(form) { +function submit_form(form) { let form_data = $(form).data(); - let confirm_msg = form_data.confirmationMsg; - if (confirm_msg) { - let confirmation = confirm(confirm_msg); - if (!confirmation) { - return false; - } - delete form_data.confirmationMsg; + let confirm_msg = form_data.confirmationMsg; + if (confirm_msg) { + let confirmation = confirm(confirm_msg); + if (!confirmation) { + return false; } + delete form_data.confirmationMsg; + } - let the_form = $("
"); - if (form_data.method === "post") { - form_data.csrf_token = $('meta[name="csrf-token"]').attr("content"); - } - the_form.attr("method", form_data.method); - the_form.attr("action", form_data.action); - delete form_data.method; - delete form_data.action; - $.each(form_data, function (key, value) { - the_form.append( - $("", { - type: "hidden", - name: key, - value: value, - }) - ); - }); - if (form_data.new_tab) { - the_form.attr("target", "_blank"); - } - $("body").append(the_form); - the_form.submit(); + let the_form = $(""); + if (form_data.method === "post") { + form_data.csrf_token = $('meta[name="csrf-token"]').attr("content"); + } + the_form.attr("method", form_data.method); + the_form.attr("action", form_data.action); + delete form_data.method; + delete form_data.action; + $.each(form_data, function (key, value) { + the_form.append( + $("", { + type: "hidden", + name: key, + value: value, + }) + ); + }); + if (form_data.new_tab) { + the_form.attr("target", "_blank"); + } + $("body").append(the_form); + the_form.submit(); } + +$("body").on("click", ".submit-form-link", function (e) { + e.preventDefault(); + submit_form(this); +}); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index d0e6dea085..b2b83e3efb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -84,13 +84,7 @@ let logged_in_user_id = "[% logged_in_user.borrowernumber | html %]"; [% Asset.js("js/global.js") | $raw %] - +[% Asset.js("js/form-submit.js",{'type' => 'module'}) | $raw %] [% IF ( OPACAmazonCoverImages || SyndeticsCoverImages ) %] [% Asset.js("js/amazonimages.js") | $raw %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/form-submit.js b/koha-tmpl/opac-tmpl/bootstrap/js/form-submit.js index c486e55498..bcaaaa72ca 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/form-submit.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/form-submit.js @@ -1,35 +1,40 @@ -export function submit_form(form) { +function submit_form(form) { let form_data = $(form).data(); - let confirm_msg = form_data.confirmationMsg; - if (confirm_msg) { - let confirmation = confirm(confirm_msg); - if (!confirmation) { - return false; - } - delete form_data.confirmationMsg; + let confirm_msg = form_data.confirmationMsg; + if (confirm_msg) { + let confirmation = confirm(confirm_msg); + if (!confirmation) { + return false; } + delete form_data.confirmationMsg; + } - let the_form = $(""); - if (form_data.method === "post") { - form_data.csrf_token = $('meta[name="csrf-token"]').attr("content"); - } - the_form.attr("method", form_data.method); - the_form.attr("action", form_data.action); - delete form_data.method; - delete form_data.action; - $.each(form_data, function (key, value) { - the_form.append( - $("", { - type: "hidden", - name: key, - value: value, - }) - ); - }); + let the_form = $(""); + if (form_data.method === "post") { + form_data.csrf_token = $('meta[name="csrf-token"]').attr("content"); + } + the_form.attr("method", form_data.method); + the_form.attr("action", form_data.action); + delete form_data.method; + delete form_data.action; + $.each(form_data, function (key, value) { + the_form.append( + $("", { + type: "hidden", + name: key, + value: value, + }) + ); + }); if (form_data.new_tab) { the_form.attr("target", "_blank"); } - $("body").append(the_form); - the_form.submit(); + $("body").append(the_form); + the_form.submit(); } + +$("body").on("click", ".submit-form-link", function (e) { + e.preventDefault(); + submit_form(this); +});