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>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Nick Clemens 2024-02-28 09:46:43 -05:00 committed by Katrin Fischer
parent 915d585b50
commit 6e05d3edf3
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
4 changed files with 45 additions and 10 deletions

View file

@ -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' } );

View file

@ -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();

View file

@ -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&amp;invoiceid=[% invoice.invoiceid | uri %]&amp;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&amp;invoiceid=[% invoice.invoiceid | uri %]&amp;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&amp;invoiceid=[% invoice.invoiceid | uri %]&amp;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' %]

View file

@ -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();
});
});