From 2dce12d93baf9e9455e4465a769357e0561dd3a7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 Apr 2025 10:44:21 +0200 Subject: [PATCH] Bug 39567: Include form-submit code from js_includes.inc (staff interface) Import the form-submit.js script in the global includes file for the staff interface, so that all pages have access to it without needing to import it directly. --- .../prog/en/includes/js_includes.inc | 7 ++ .../intranet-tmpl/prog/js/form-submit.js | 65 +++++++++---------- 2 files changed, 38 insertions(+), 34 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 b5126c6174..d60d163ede 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -26,6 +26,13 @@ [% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %] [% Asset.js("js/staff-global.js") | $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 e52196c058..30855ff297 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/form-submit.js +++ b/koha-tmpl/intranet-tmpl/prog/js/form-submit.js @@ -1,38 +1,35 @@ -$(document).ready(function () { - $("body").on("click", ".submit-form-link", function (e) { - e.preventDefault(); - let form_data = $(this).data(); +export 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(); +} -- 2.34.1