From 7c2a4295a22d0397b8b624454d70d155f623a7e4 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 16 Apr 2021 16:59:44 +0000 Subject: [PATCH] Bug 24154: Get rules rather than values to determine if set or not Template plugin CirculationRules.Search returns "" if a rule doesn't exist or if the rule exists but is set to "" To get more info, we add a 'want_rule' parameter and use that to test if defined but blank To test: 1 - In circulation rules set the 'Default checkout, hold and return policy' without setting values 2 - Unset it 3 - Notice there is no visual difference 4 - Apply patch 5 - Reload the page 6 - note there is no 'Unset button' and first column says 'Not set' 7 - Save the rule with no values 8 - Now 'Defaults' is displayed and the unset button exists Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart --- Koha/Template/Plugin/CirculationRules.pm | 4 +- .../prog/en/modules/admin/smart-rules.tt | 57 +++++++++++-------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/Koha/Template/Plugin/CirculationRules.pm b/Koha/Template/Plugin/CirculationRules.pm index e82dce01ed..0e39e908bc 100644 --- a/Koha/Template/Plugin/CirculationRules.pm +++ b/Koha/Template/Plugin/CirculationRules.pm @@ -43,7 +43,7 @@ sub Get { } sub Search { - my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_; + my ( $self, $branchcode, $categorycode, $itemtype, $rule_name, $want_rule) = @_; $branchcode = undef if $branchcode eq q{} or $branchcode eq q{*}; $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*}; @@ -58,8 +58,8 @@ sub Search { } )->next; + return $rule if $want_rule; return $rule->rule_value if $rule; } - 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index 088657327e..d805ef208a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -543,28 +543,39 @@ Return policy Actions + [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty', 1, 1 ) %] + [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty', 1, 1 ) %] + [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds', 1, 1 ) %] + [% SET holdallowed = CirculationRules.Search( current_branch, undef, undef, 'holdallowed', 1 ) %] + [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy', 1 ) %] + [% SET returnbranch = CirculationRules.Search( current_branch, undef, undef, 'returnbranch', 1 ) %] + [% SET dcharp = ( patron_maxissueqty || patron_maxonsiteissueqty || rule_value || holdallowed || hold_fulfillment_policy || returnbranch ) %] - Defaults - [% SET patron_maxissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxissueqty' ) %] - + [% IF ( dcharp ) %] + + Defaults + + [% ELSE %] + Not set + [% END %] + + + - [% SET patron_maxonsiteissueqty = CirculationRules.Search( current_branch, undef, undef, 'patron_maxonsiteissueqty' ) %] - + - [% SET rule_value = CirculationRules.Search( current_branch, undef , undef, 'max_holds' ) %] - + - [% SET hold_fulfillment_policy = CirculationRules.Search( current_branch, undef, undef, 'hold_fulfillment_policy' ) %] - [% IF hold_fulfillment_policy == 'any' %] + [% IF hold_fulfillment_policy.rule_value == 'any' %] @@ -615,7 +625,7 @@ [% END %] - [% IF hold_fulfillment_policy == 'holdgroup' %] + [% IF hold_fulfillment_policy.rule_value == 'holdgroup' %] @@ -625,7 +635,7 @@ [% END %] - [% IF hold_fulfillment_policy == 'patrongroup' %] + [% IF hold_fulfillment_policy.rule_value == 'patrongroup' %] @@ -635,7 +645,7 @@ [% END %] - [% IF hold_fulfillment_policy == 'homebranch' %] + [% IF hold_fulfillment_policy.rule_value == 'homebranch' %] @@ -645,7 +655,7 @@ [% END %] - [% IF hold_fulfillment_policy == 'holdingbranch' %] + [% IF hold_fulfillment_policy.rule_value == 'holdingbranch' %] @@ -658,27 +668,26 @@