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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit eeb86254da)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
David Cook 2025-04-22 01:27:15 +00:00 committed by Fridolin Somers
parent ae3fb6470d
commit a885752801
No known key found for this signature in database
GPG Key ID: 9A8E73E2A8B96537
4 changed files with 69 additions and 71 deletions

View File

@ -26,13 +26,7 @@
[% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %]
<!-- koha core js -->
[% Asset.js("js/staff-global.js") | $raw %]
<script type="module">
import { submit_form } from "/intranet-tmpl/prog/js/form-submit.js";
$("body").on("click", ".submit-form-link", function (e) {
e.preventDefault();
submit_form(this);
});
</script>
[% 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' %]

View File

@ -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 = $("<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(
$("<input/>", {
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 = $("<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(
$("<input/>", {
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);
});

View File

@ -84,13 +84,7 @@
let logged_in_user_id = "[% logged_in_user.borrowernumber | html %]";
</script>
[% Asset.js("js/global.js") | $raw %]
<script type="module">
import { submit_form } from "/opac-tmpl/bootstrap/js/form-submit.js";
$("body").on("click", ".submit-form-link", function (e) {
e.preventDefault();
submit_form(this);
});
</script>
[% Asset.js("js/form-submit.js",{'type' => 'module'}) | $raw %]
[% IF ( OPACAmazonCoverImages || SyndeticsCoverImages ) %]
[% Asset.js("js/amazonimages.js") | $raw %]
[% END %]

View File

@ -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 = $("<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(
$("<input/>", {
type: "hidden",
name: key,
value: value,
})
);
});
let the_form = $("<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(
$("<input/>", {
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);
});