From 6e05d3edf397a323d0fd439c3a10a637a14b5a37 Mon Sep 17 00:00:00 2001 From: Nick Clemens 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 Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- 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 6e7724c749..2c88908086 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 05d0f8382b..d72da4fe9f 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 %] - Delete + + Delete [% END %] @@ -537,7 +538,9 @@ [% MACRO jsinclude BLOCK %] + [% 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 f189ba2b5b..6f9901bf71 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 @@
  • Details
  • [% IF invoice.closedate %] [% IF CAN_user_acquisition_reopen_closed_invoices %] -
  • Reopen
  • +
  • Reopen
  • [% END %] [% ELSE %] [% IF CAN_user_acquisition_edit_invoices %] -
  • Close
  • +
  • Close
  • [% END %] [% END # /IF invoice.closedate %] [% UNLESS invoice.receivedbiblios || invoice.receiveditems %] [% IF CAN_user_acquisition_delete_invoices %] -
  • Delete
  • +
  • Delete
  • [% END %] [% END %] @@ -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 0000000000..5f2ff44eda --- /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 = $('
    '); + 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, + }) + ); + }); + $('body').append( the_form ); + the_form.submit(); + }); +}); -- 2.39.5