From a179832aa7bfb888610ee6958fd05e961b62ca6e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 19 Jun 2025 12:16:06 -0300 Subject: [PATCH] Bug 40206: Fix wrong layout in curbside pickups when 'CircSidebar' enabled This patch solves the following issues: * Template flow issue: the template called STOP which prevented the WRAPPER to complete and affected how things were rendered. * Redirect to 404 if feature disabled. This is common practice in other modules. The fact things can be executed even with the feature disabled is not ok (syspref). * Shortcircuit earlier. Similar to the above, if the feature is disabled for the current branch, no DB queries and stuff should take place. Notice the lack of checks actually makes the controller perform the actions. It is just that it is not displayed afterwards! To test: 1. Enable the `CurbsidePickup` syspref. 2. 'Activate' the `CircSidebar` syspref. 3. Be on a branch that doesn't have them enabled 4. Go to Circulation > Check in => SUCCESS: A nice left-hand sidebar is displayed with access to Circulation actions 5. Click on 'Curbside pickups' => FAIL: The sidebar doesn't display. boo! 6. Apply this patch 7. Restart plack $ ktd --shell k$ koha-plack --restart kohadev 8. Repeat 4 => SUCCESS: It renders much better! 9. Sign off :-D --- circ/curbside_pickups.pl | 20 +- .../prog/en/modules/circ/curbside_pickups.tt | 395 +++++++++--------- 2 files changed, 218 insertions(+), 197 deletions(-) diff --git a/circ/curbside_pickups.pl b/circ/curbside_pickups.pl index 354e927a2e1..0a9c63ff50a 100755 --- a/circ/curbside_pickups.pl +++ b/circ/curbside_pickups.pl @@ -28,7 +28,13 @@ use Koha::CurbsidePickupPolicies; use Koha::Libraries; use Koha::Patrons; -my $input = CGI->new; +my $input = CGI->new; + +unless ( C4::Context->preference('CurbsidePickup') ) { + print $input->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + my $op = $input->param('op') || 'list'; my $tab = $input->param('tab'); my $auto_refresh = $input->param('auto_refresh'); @@ -45,7 +51,15 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); my $branchcode = C4::Context->userenv()->{'branch'}; -my $libraries = Koha::Libraries->search( {}, { order_by => ['branchname'] } ); + +my $policy = Koha::CurbsidePickupPolicies->find( { branchcode => $branchcode } ); +unless ( $policy && $policy->enabled ) { + $template->param( disabled_for_branch => 1 ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; +} + +my $libraries = Koha::Libraries->search( {}, { order_by => ['branchname'] } ); if ( $op eq 'find-patron' ) { my $borrowernumber = $input->param('borrowernumber'); @@ -150,7 +164,7 @@ $template->param( tab => $tab, auto_refresh => $auto_refresh, refresh_delay => $refresh_delay, - policy => Koha::CurbsidePickupPolicies->find( { branchcode => $branchcode } ), + policy => $policy, curbside_pickups => Koha::CurbsidePickups->search( { branchcode => $branchcode, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt index e6503096cc4..529147b1708 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt @@ -84,16 +84,9 @@ [% END %] [% END %] -[% SET aside = Koha.Preference('CircSidebar') ? 'circ-nav' : '' %] -[% WRAPPER 'main-container.inc' aside=aside %] +[% BLOCK curbside_pickups_enabled %]

Curbside pickups

- [% UNLESS policy.enabled %] -
Curbside pickups are not enabled for your library.
- [% INCLUDE 'intranet-bottom.inc' %] - [% STOP %] - [% END %] - [% FOR m IN messages %]
[% SWITCH m.code %] @@ -457,239 +450,253 @@ [% END # /tab_panel %] [% END # /WRAPPER tab_panels %] [% END # /WRAPPER tabs %] -[% END %] -[% MACRO jsinclude BLOCK %] - [% Asset.js("lib/dayjs/plugin/isSameOrAfter.js") | $raw %] - - - [% INCLUDE 'calendar.inc' %] - [% INCLUDE 'js-patron-format.inc' %] - [% INCLUDE 'datatables.inc' %] - + + [% INCLUDE 'calendar.inc' %] + [% INCLUDE 'js-patron-format.inc' %] + [% INCLUDE 'datatables.inc' %] + + [% END %] +[% END # /BLOCK enabled %] - function set_interval_if_needed(){ - const refresh_delay = $("#refresh_delay").val(); - const auto_refresh = $("#auto_refresh").is(":checked"); +[% BLOCK curbside_pickups_disabled %] +

Curbside pickups

+
Curbside pickups are not enabled for your library.
+[% END # /BLOCK disabled %] - if (auto_refresh && refresh_delay){ - set_interval(refresh_delay * 1000); - } else { - clear_intervals(); - } - } - -[% END %] +[% SET aside = Koha.Preference('CircSidebar') ? 'circ-nav' : '' %] +[% WRAPPER 'main-container.inc' aside=aside %] + [% IF !disabled_for_branch %] + [% PROCESS curbside_pickups_enabled %] + [% ELSE %] + [% PROCESS curbside_pickups_disabled %] + [% END %] +[% END # /WRAPPER %] [% INCLUDE 'intranet-bottom.inc' %] -- 2.50.0