From 912894e30d8852037cd372028bce2d7ee99f062b Mon Sep 17 00:00:00 2001
From: Lucas Gass <lucas@bywatersolutions.com>
Date: Tue, 10 Sep 2024 19:40:49 +0000
Subject: [PATCH] Bug 37883: Adjust template for new system preference

To test:

0. Apply patch, restart_all, and regenerate CSS ( https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_interface ) I also recommend clearing your browser cache.
1. Search fof the FilterSearchResultsByLoggedInBranch system preference and set it to 'Do'.
2. Do a catalog search and notice the 'Show local items only' button above the "Location" column.
3. Click it to show information ( in that column ) that is only related to the branch you are currently logged in at.
4. In the same result set have some items that are checked out, withdrawn, lost, damaged, and notforlaon.
5. Play more with the search results and ensure everything is accurate.
6. Set the FilterSearchResultsByLoggedInBranch system preference to 'Don't' and confirm that there is no button to filter by branch anymore.
---
 .../prog/en/modules/catalogue/results.tt      | 36 +++++++++++--------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
index 95d0b1391ca..d23efc5ee9a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
@@ -451,7 +451,9 @@
 
                         <div id="searchresults">
                             [% INCLUDE 'page-numbers.inc' %]
-                            <button href="#" id="toggleitems" class="btn btn-primary btn-xs" style="float: right;">Show local items only</button>
+                            [% IF Koha.Preference('FilterSearchResultsByLoggedInBranch') %]
+                                <button href="#" id="toggleitems" class="btn btn-primary btn-xs" style="float: right;">Show local items only</button>
+                            [% END %]
                             <form action="/cgi-bin/koha/catalogue/search.pl" method="get" name="bookbag_form" id="bookbag_form">
                                 [% IF ( searchdesc ) %]
                                     [% FOREACH QUERY_INPUT IN QUERY_INPUTS %]
@@ -612,7 +614,7 @@
                                                             [% END %]
 
                                                             <div class="all">[% tnx('{count} item', '{count} items', SEARCH_RESULT.items_count, {count = SEARCH_RESULT.items_count}) | html %][% IF ( SEARCH_RESULT.availablecount ) %], [% SEARCH_RESULT.availablecount | html %] <span>available:</span>[% ELSE %], <span>None available</span>[% END %]</div>
-                                                            [% IF SEARCH_RESULT.branchtotalcount > 0 %]
+                                                            [% IF ( SEARCH_RESULT.branchtotalcount > 0 ) && Koha.Preference('FilterSearchResultsByLoggedInBranch') %]
                                                                 <div class="branch_specific">[% tnx('{count} item', '{count} items', SEARCH_RESULT.branchtotalcount, {count = SEARCH_RESULT.branchtotalcount}) | html %][% IF ( SEARCH_RESULT.branchavailablecount ) %], [% SEARCH_RESULT.branchavailablecount | html %] <span>available:</span>[% ELSE %], <span>None available</span>[% END %]</div>
                                                             [% END %]
 
@@ -625,12 +627,16 @@
                                                             [% IF status_count == "onloancount" %]
                                                                 [% IF SEARCH_RESULT.${status_count} > 0 %]
                                                                     <div class="results_checkedout all">[% SEARCH_RESULT.${status_count} | html %] checked out:</div>
-                                                                    <div class="results_checkedout branch_specific">[% SEARCH_RESULT.branchonloancount | html %] checked out:</div>
+                                                                    [% IF Koha.Preference('FilterSearchResultsByLoggedInBranch') %]
+                                                                        <div class="results_checkedout branch_specific">[% SEARCH_RESULT.branchonloancount | html %] checked out:</div>
+                                                                    [% END %]
                                                                 [% END %]
                                                             [% ELSIF status_count == "othercount" %]
                                                                 [% IF SEARCH_RESULT.${status_count} > 0 %]
                                                                     <div class="results_unavailablei all">[% SEARCH_RESULT.${status_count} | html %] unavailable:</div>
-                                                                    <div class="results_unavailablei branch_specific">[% SEARCH_RESULT.branchothercount | html %] unavailable:</div>
+                                                                    [% IF Koha.Preference('FilterSearchResultsByLoggedInBranch') %]
+                                                                        <div class="results_unavailablei branch_specific">[% SEARCH_RESULT.branchothercount | html %] unavailable:</div>
+                                                                    [% END %]
                                                                 [% END %]
                                                             [% END %]
                                                             [% IF SEARCH_RESULT.${items_loop}.size > 0 %]
@@ -712,7 +718,7 @@
                                                             <span class="unavailable all">No items</span>
                                                         [% END %]
                                                     [% END # /IF ( SEARCH_RESULT.items_count ) %]
-                                                    [% IF SEARCH_RESULT.branchtotalcount == 0 %]
+                                                    [% IF SEARCH_RESULT.branchtotalcount == 0 && Koha.Preference('FilterSearchResultsByLoggedInBranch') %]
                                                             <span class="unavailable branch_specific">No items</span>
                                                     [% END %]
                                                 </div> <!-- /.availability -->
@@ -826,16 +832,18 @@
         var holdforclub = "[% holdforclub | html %]";
         var userbranch = "[% userbranch | html %]";
 
-        $('#toggleitems').click( function() {
-            $('#toggleitems').text() === 'Show local items only' ? $('#toggleitems').text("Show items in all libraries") : $('#toggleitems').text("Show local items only");
-            $('.branch_specific').toggle();
-            $('.all').toggle();
-            $('ul[class*="_loop_items"] li').each( function() {
-                if ( !$(this).hasClass(userbranch) ) {
-                    $(this).toggle();
-                }
+        [% IF Koha.Preference('FilterSearchResultsByLoggedInBranch') %]
+            $('#toggleitems').click( function() {
+                $('#toggleitems').text() === 'Show local items only' ? $('#toggleitems').text("Show items in all libraries") : $('#toggleitems').text("Show local items only");
+                $('.branch_specific').toggle();
+                $('.all').toggle();
+                $('ul[class*="_loop_items"] li').each( function() {
+                    if ( !$(this).hasClass(userbranch) ) {
+                        $(this).toggle();
+                    }
+                });
             });
-        });
+        [% END %]
         [% IF SEARCH_RESULTS %]
             var SEARCH_RESULTS = 1;
         [% ELSE %]
-- 
2.39.2