Bugzilla – Attachment 180687 Details for
Bug 39567
Move form-submit js into js includes files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39567: [POC] Keep form-submit code into a separate file but include it from js_includes.inc
Bug-39567-Keep-form-submit-code-into-a-separate-fi.patch (text/plain), 4.23 KB, created by
Jonathan Druart
on 2025-04-07 08:47:27 UTC
(
hide
)
Description:
Bug 39567: [POC] Keep form-submit code into a separate file but include it from js_includes.inc
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-04-07 08:47:27 UTC
Size:
4.23 KB
patch
obsolete
>From b08fdc6187c71fdda76215fd553c8d5ebf80fea2 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 7 Apr 2025 10:44:21 +0200 >Subject: [PATCH] Bug 39567: Keep form-submit code into a separate file but > include it from js_includes.inc > >--- > .../prog/en/includes/js_includes.inc | 7 ++++ > .../intranet-tmpl/prog/js/form-submit.js | 35 +++++++++++++++++ > .../intranet-tmpl/prog/js/staff-global.js | 38 ------------------- > 3 files changed, 42 insertions(+), 38 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/form-submit.js > >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 b5126c6174d..d60d163ede7 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 %] > <!-- 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> > [% 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 >new file mode 100644 >index 00000000000..30855ff2972 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/form-submit.js >@@ -0,0 +1,35 @@ >+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 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(); >+} >diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >index 6a45d5e4982..b660011277a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >@@ -99,44 +99,6 @@ $(document).ready(function () { > } > ); > >- // form-submit js >- $("body").on("click", ".submit-form-link", function (e) { >- e.preventDefault(); >- let form_data = $(this).data(); >- >- 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(); >- }); >- > $(".close, .close_window").on("click", function (e) { > e.preventDefault(); > window.close(); >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39567
:
180669
|
180687
|
180983
|
180984
|
180985
|
180986
|
180987
|
180988
|
181235
|
182168
|
182169
|
182170
|
182171
|
182234
|
182235
|
182236
|
182237