Bug 38728: (follow-up) Fix cashup modal triggering after POST/REDIRECT/GET implementation
The upstream implementation of POST/REDIRECT/GET pattern for cashup operations introduced a regression where the cashup modal would no longer auto-trigger after successful cashup submission. The original approach passed cashup_id as a query parameter in the redirect, but the template variable was not being populated from the URL parameter, causing the JavaScript to receive an empty value. This follow-up implements a more modern and reliable solution using URL hash fragments instead of query parameters: 1. Changed redirect URLs to use hash fragments (e.g., #cashup-123) 2. Updated JavaScript to detect and parse hash fragments on page load 3. Auto-triggers the cashup modal when hash is present 4. Cleans up the URL using history.replaceState() after modal opens Benefits: - Maintains proper POST/REDIRECT/GET pattern - Hash fragments don't trigger server requests or require server-side handling - More reliable than template variable approach - Follows modern web development patterns - Works consistently across both register.pl and registers.pl pages Test plan: 1. Navigate to POS register page (pos/register.pl) 2. Perform a cashup operation 3. Verify the cashup summary modal automatically appears after redirect 4. Verify the URL is clean (no hash fragment visible) 5. Repeat for registers summary page (pos/registers.pl) 6. Perform individual register cashup 7. Verify modal auto-triggers correctly Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
f57279b52c
commit
2025731e52
|
|
@ -575,12 +575,17 @@
|
|||
}, null, 1);
|
||||
|
||||
$(document).ready(function() {
|
||||
[% IF cashup_id %]
|
||||
let $button = $('[data-cashup="[% cashup_id | html %]"]');
|
||||
if ($button.length) {
|
||||
$button[0].click();
|
||||
// Check for cashup hash in URL
|
||||
let hash = window.location.hash;
|
||||
if (hash && hash.startsWith('#cashup-')) {
|
||||
let cashup_id = hash.substring(8); // Remove '#cashup-' prefix
|
||||
let $button = $('[data-cashup="' + cashup_id + '"]');
|
||||
if ($button.length) {
|
||||
$button[0].click();
|
||||
// Clean up URL without page reload
|
||||
history.replaceState(null, null, window.location.pathname + window.location.search);
|
||||
}
|
||||
}
|
||||
[% END %]
|
||||
});
|
||||
</script>
|
||||
[% END %]
|
||||
|
|
|
|||
|
|
@ -241,12 +241,17 @@
|
|||
$('#cashup_registerid').val(rid);
|
||||
});
|
||||
|
||||
[% IF cashup_id %]
|
||||
let $button = $('[data-cashup="[% cashup_id | html %]"]');
|
||||
if ($button.length) {
|
||||
$button[0].click();
|
||||
// Check for cashup hash in URL
|
||||
let hash = window.location.hash;
|
||||
if (hash && hash.startsWith('#cashup-')) {
|
||||
let cashup_id = hash.substring(8); // Remove '#cashup-' prefix
|
||||
let $button = $('[data-cashup="' + cashup_id + '"]');
|
||||
if ($button.length) {
|
||||
$button[0].click();
|
||||
// Clean up URL without page reload
|
||||
history.replaceState(null, null, window.location.pathname + window.location.search);
|
||||
}
|
||||
}
|
||||
[% END %]
|
||||
});
|
||||
</script>
|
||||
[% END %]
|
||||
|
|
|
|||
|
|
@ -112,7 +112,8 @@ if ( !$registers->count ) {
|
|||
);
|
||||
|
||||
# Redirect to prevent duplicate submissions (POST/REDIRECT/GET pattern)
|
||||
print $input->redirect( "/cgi-bin/koha/pos/register.pl?registerid=" . $registerid . "&cashup_id=" . $cashup->id );
|
||||
print $input->redirect(
|
||||
"/cgi-bin/koha/pos/register.pl?registerid=" . $registerid . "#cashup-" . $cashup->id );
|
||||
exit;
|
||||
} else {
|
||||
$template->param( error_cashup_permission => 1 );
|
||||
|
|
|
|||
|
|
@ -56,16 +56,17 @@ if ( !$registers->count ) {
|
|||
my $op = $input->param('op') // '';
|
||||
if ( $op eq 'cud-cashup' ) {
|
||||
if ( $logged_in_user->has_permission( { cash_management => 'cashup' } ) ) {
|
||||
my $registerid = $input->param('registerid');
|
||||
my $registerid = $input->param('registerid');
|
||||
my $redirect_url = "/cgi-bin/koha/pos/registers.pl";
|
||||
if ($registerid) {
|
||||
my $register = Koha::Cash::Registers->find( { id => $registerid } );
|
||||
my $cashup = $register->add_cashup(
|
||||
my $cashup = $register->add_cashup(
|
||||
{
|
||||
manager_id => $logged_in_user->id,
|
||||
amount => $register->outstanding_accountlines->total
|
||||
}
|
||||
);
|
||||
$template->param( cashup_id => $cashup->id );
|
||||
$redirect_url .= "#cashup-" . $cashup->id;
|
||||
} else {
|
||||
for my $register ( $registers->as_list ) {
|
||||
$register->add_cashup(
|
||||
|
|
@ -78,7 +79,7 @@ if ( $op eq 'cud-cashup' ) {
|
|||
}
|
||||
|
||||
# Redirect to prevent duplicate submissions (POST/REDIRECT/GET pattern)
|
||||
print $input->redirect("/cgi-bin/koha/pos/registers.pl");
|
||||
print $input->redirect($redirect_url);
|
||||
exit;
|
||||
} else {
|
||||
$template->param( error_cashup_permission => 1 );
|
||||
|
|
|
|||
Loading…
Reference in New Issue