Bugzilla – Attachment 188871 Details for
Bug 38728
Add option to automatically trigger cashup summary modal after cashup
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38728: (follow-up) Fix cashup modal triggering after POST/REDIRECT/GET implementation
Bug-38728-follow-up-Fix-cashup-modal-triggering-af.patch (text/plain), 6.38 KB, created by
Martin Renvoize (ashimema)
on 2025-11-01 12:12:45 UTC
(
hide
)
Description:
Bug 38728: (follow-up) Fix cashup modal triggering after POST/REDIRECT/GET implementation
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-11-01 12:12:45 UTC
Size:
6.38 KB
patch
obsolete
>From f59155338ca2f411b9fb4fe591ede16dd342e03b Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Sat, 1 Nov 2025 12:09:22 +0000 >Subject: [PATCH] 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 >--- > .../intranet-tmpl/prog/en/modules/pos/register.tt | 15 ++++++++++----- > .../prog/en/modules/pos/registers.tt | 15 ++++++++++----- > pos/register.pl | 3 ++- > pos/registers.pl | 9 +++++---- > 4 files changed, 27 insertions(+), 15 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt >index 7ef32771698..932189150f5 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt >@@ -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 %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/registers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/registers.tt >index dd35313309b..4c34a41dcde 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/registers.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/registers.tt >@@ -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 %] >diff --git a/pos/register.pl b/pos/register.pl >index 9d64a842843..3e785dbf184 100755 >--- a/pos/register.pl >+++ b/pos/register.pl >@@ -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 ); >diff --git a/pos/registers.pl b/pos/registers.pl >index da79977ec13..6718449dd32 100755 >--- a/pos/registers.pl >+++ b/pos/registers.pl >@@ -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 ); >-- >2.51.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 38728
:
175615
|
183071
|
183275
|
183457
|
183458
|
186668
|
186669
|
186670
|
186671
|
188867
|
188868
|
188869
|
188870
| 188871