Bugzilla – Attachment 164830 Details for
Bug 36246
Have a centralized method for submitting a form via a link
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36246: Add JS function/include for submitting forms from link data
Bug-36246-Add-JS-functioninclude-for-submitting-fo.patch (text/plain), 12.12 KB, created by
Nick Clemens (kidclamp)
on 2024-04-12 11:51:48 UTC
(
hide
)
Description:
Bug 36246: Add JS function/include for submitting forms from link data
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-04-12 11:51:48 UTC
Size:
12.12 KB
patch
obsolete
>From 79b364977c464020a15353e43122ad92acfa6a0d Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 28 Feb 2024 09:46:43 -0500 >Subject: [PATCH] Bug 36246: Add JS function/include for submitting forms from > link data > >This patch adds a new js include file form-submit.js which will read data elements from a link >and use those to submit a form > >This patch fixes forms on acqui/invoice.pl as an example > >To test: >1 - Add some invoices for a vendor >2 - Got to Acquisitions->Invoices >3 - Actions -> Close - confirm it works >4 - Got to 'Closed invoices' - reopen >5 - Go to Details on the invoice >6 - Add an adjustment >7 - Delete the adjustment >8 - Confirm it works > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > acqui/invoice.pl | 6 ++-- > .../prog/en/modules/acqui/invoice.tt | 8 ++--- > .../prog/en/modules/acqui/invoices.tt | 7 ++-- > .../intranet-tmpl/prog/js/form-submit.js | 34 +++++++++++++++++++ > 4 files changed, 45 insertions(+), 10 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/form-submit.js > >diff --git a/acqui/invoice.pl b/acqui/invoice.pl >index 6e7724c7496..2c889080869 100755 >--- a/acqui/invoice.pl >+++ b/acqui/invoice.pl >@@ -71,7 +71,7 @@ if ( C4::Context->preference('AcqEnableFiles') ) { > tabletag => 'aqinvoices', recordid => $invoiceid ); > } > >-if ( $op && $op eq 'close' ) { >+if ( $op && $op eq 'cud-close' ) { > output_and_exit( $input, $cookie, $template, 'insufficient_permission' ) > unless $logged_in_patron->has_permission( { acquisition => 'edit_invoices' } ); > my @invoiceid = $input->multi_param('invoiceid'); >@@ -84,7 +84,7 @@ if ( $op && $op eq 'close' ) { > exit 0; > } > } >-elsif ( $op && $op eq 'reopen' ) { >+elsif ( $op && $op eq 'cud-reopen' ) { > output_and_exit( $input, $cookie, $template, 'insufficient_permission' ) > unless $logged_in_patron->has_permission( { acquisition => 'reopen_closed_invoices' } ); > my @invoiceid = $input->multi_param('invoiceid'); >@@ -154,7 +154,7 @@ elsif ( $op && $op eq 'cud-delete' ) { > exit 0; > } > } >-elsif ( $op && $op eq 'del_adj' ) { >+elsif ( $op && $op eq 'cud-del_adj' ) { > > output_and_exit( $input, $cookie, $template, 'insufficient_permission' ) > unless $logged_in_patron->has_permission( { acquisition => 'edit_invoices' } ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >index 05d0f8382bd..d72da4fe9fa 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >@@ -230,7 +230,8 @@ > [% END # /IF adjustment.encumber_open %] > [% UNLESS readonly %] > <td> >- <a class="btn btn-default btn-xs delete_adjustment" href="/cgi-bin/koha/acqui/invoice.pl?op=del_adj&adjustment_id=[% adjustment.adjustment_id | html %]&invoiceid=[% invoiceid | html %]"><i class="fa fa-trash-can"></i> Delete</a> >+ <a class="btn btn-default btn-xs submit-form-link" href="#" data-adjustment_id="[% adjustment.adjustment_id | html %]" data-invoiceid="[% invoiceid | html %]" data-action="invoice.pl" data-method="post" data-op="cud-del_adj" data-confirmation="confirm_del_adj"> >+ <i class="fa fa-trash-can"></i> Delete</a> > </td> > [% END %] > </tr> >@@ -537,7 +538,9 @@ > </span> <!-- /#all_fund_dropdown --> > > [% MACRO jsinclude BLOCK %] >+ <script>var confirm_del_adj = _("Are you sure you want to delete this adjustment?");</script> > [% Asset.js("js/acquisitions-menu.js") | $raw %] >+ [% Asset.js("js/form-submit.js") | $raw %] > [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] > [% Asset.js("js/acq.js") | $raw %] > [% INCLUDE 'calendar.inc' %] >@@ -586,9 +589,6 @@ > e.preventDefault(); > $("#show_invoice_adjustment, #cancel_invoice_adjustment, #add_invoice_adjustment").toggle(); > }); >- $("a.delete_adjustment").click(function(){ >- return ( confirm( _("Are you sure you want to delete this file ?") ) ); >- }); > > //keep a copy of all budgets before removing the inactives > var disabledBudgetsCopy = $("#all_fund_dropdown").html(); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt >index f189ba2b5bb..6f9901bf713 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt >@@ -102,16 +102,16 @@ > <li><a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% invoice.invoiceid | uri %]"><i class="fa fa-search"></i> Details</a></li> > [% IF invoice.closedate %] > [% IF CAN_user_acquisition_reopen_closed_invoices %] >- <li><a href="invoice.pl?op=reopen&invoiceid=[% invoice.invoiceid | uri %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]"><i class="fa-solid fa-rotate"></i> Reopen</a></li> >+ <li><a class="submit-form-link" data-action="invoice.pl" data-op="cud-reopen" data-invoiceid="[% invoice.invoiceid | uri %]" data-referer="/cgi-bin/koha/acqui/invoices.pl?op=do_search&invoicenumber=[% invoicenumber | html %]&supplier=[% booksellerid | html %]&shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]&shipmentdateto=[% shipmentdateto | $KohaDates %]&billingdatefrom=[% billingdatefrom | $KohaDates %]&billingdateto=[% billingdateto | $KohaDates %]&isbneanissn=[% isbneanissn | html %]&title=[% title | html %]&author=[% author | html %]&publisher=[% publisher | html %]&publicationyear=[% publicationyear | html %]&branch=[% branch | html %]" data-method="post"><i class="fa-solid fa-rotate"></i> Reopen</a></li> > [% END %] > [% ELSE %] > [% IF CAN_user_acquisition_edit_invoices %] >- <li><a href="invoice.pl?op=close&invoiceid=[% invoice.invoiceid | uri %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]"><i class="fa fa-times-circle"></i> Close</a></li> >+ <li><a class="submit-form-link" data-action="invoice.pl" data-op="cud-close" data-invoiceid="[% invoice.invoiceid | html %]" data-referer="/cgi-bin/koha/acqui/invoices.pl?op=do_search&invoicenumber=[% invoicenumber | html %]&supplier=[% booksellerid | html %]&shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]&shipmentdateto=[% shipmentdateto | $KohaDates %]&billingdatefrom=[% billingdatefrom | $KohaDates %]&billingdateto=[% billingdateto | $KohaDates %]&isbneanissn=[% isbneanissn | html %]&title=[% title | html %]&author=[% author | html %]&publisher=[% publisher | html %]&publicationyear=[% publicationyear | html %]&branch=[% branch | html %]" data-method="post"><i class="fa fa-times-circle"></i> Close</a></li> > [% END %] > [% END # /IF invoice.closedate %] > [% UNLESS invoice.receivedbiblios || invoice.receiveditems %] > [% IF CAN_user_acquisition_delete_invoices %] >- <li><a href="invoice.pl?op=delete&invoiceid=[% invoice.invoiceid | uri %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber | uri %]%26supplier=[% booksellerid | uri %]%26shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]%26shipmentdateto=[% shipmentdateto | $KohaDates %]%26billingdatefrom=[% billingdatefrom | $KohaDates %]%26billingdateto=[% billingdateto | $KohaDates %]%26isbneanissn=[% isbneanissn | uri %]%26title=[% title | uri %]%26author=[% author | uri %]%26publisher=[% publisher | uri %]%26publicationyear=[% publicationyear | uri %]%26branch=[% branch | uri %]" class="delete_invoice"><i class="fa fa-trash-can"></i> Delete</a></li> >+ <li><a class="submit-form-link" data-action="invoice.pl" data-op="cud-delete" data-invoiceid="[% invoice.invoiceid | html %]" data-referer="/cgi-bin/koha/acqui/invoices.pl?op=do_search&invoicenumber=[% invoicenumber | html %]&supplier=[% booksellerid | html %]&shipmentdatefrom=[% shipmentdatefrom | $KohaDates %]&shipmentdateto=[% shipmentdateto | $KohaDates %]&billingdatefrom=[% billingdatefrom | $KohaDates %]&billingdateto=[% billingdateto | $KohaDates %]&isbneanissn=[% isbneanissn | uri %]&title=[% title | html %]%26author=[% author | html %]&publisher=[% publisher | html %]&publicationyear=[% publicationyear | html %]&branch=[% branch | html %]" data-method="post"><i class="fa fa-trash-can"></i> Delete</a></li> > [% END %] > [% END %] > </ul> >@@ -418,6 +418,7 @@ > > [% MACRO jsinclude BLOCK %] > [% Asset.js("js/acquisitions-menu.js") | $raw %] >+ [% Asset.js("js/form-submit.js") | $raw %] > [% INCLUDE 'datatables.inc' %] > [% INCLUDE 'calendar.inc' %] > [% INCLUDE 'select2.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..5f2ff44eda3 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/form-submit.js >@@ -0,0 +1,34 @@ >+$(document).ready(function(){ >+ >+ $('.submit-form-link').click(function(e){ >+ e.preventDefault(); >+ let form_data = $(this).data(); >+ >+ form_confirm = form_data.confirmation; >+ let confirmation = 1; >+ if( form_confirm ){ >+ delete form_data.confirmation; >+ confirmation = confirm( eval(form_confirm) ); >+ } >+ if( !confirmation ){ return false } >+ >+ 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, >+ }) >+ ); >+ }); >+ $('body').append( the_form ); >+ the_form.submit(); >+ }); >+}); >-- >2.39.2
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 36246
:
162835
|
163098
|
163517
|
164830
|
164831
|
164832
|
165967
|
165968
|
165969
|
165970
|
165971