From a88db3ae5983f41ea2ff2f4914e42d8b61c5ce5f Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Wed, 15 Sep 2021 12:14:19 +0000
Subject: [PATCH] Bug 29015: (follow-up) Show sidebar filter form with results

This patch adds the new filter form in the sidebar when showing results.
To do so the form markup is moved into a BLOCK so that it can be reused.

This patch also adds pre-selection of submitted options on the filter
form so that it reflects the user's choices.

To test, apply the patch and rebuild the staff client CSS
(https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client).

- Go to Circulation -> Holds queue.
- Submit the form with one or more filters selected.
- On the results page the queue should be correctly filtered and the
  sidebar should show your search fields preselected.
- Test with the CircSidebar preference enabled and disabled. The
  circulation menu should appear correctly, with the filter form only
  displaying in the sidebar after submitting the form.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
---
 .../prog/css/src/staff-global.scss            |   5 +
 .../prog/en/modules/circ/view_holdsqueue.tt   | 106 ++++++++++--------
 2 files changed, 66 insertions(+), 45 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
index 9d8f5e8069..199f01f6ea 100644
--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
@@ -223,6 +223,11 @@ aside {
                 margin-right: 3px;
                 width: calc(100% - 20px);
             }
+
+            &+.action {
+                margin-left: 0;
+                padding: 0;
+            }
         }
     }
 }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt
index 6c9e5ffea1..630b58ad4b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt
@@ -53,7 +53,7 @@
             <main>
                 <div class="row">
 
-                [% IF Koha.Preference('CircSidebar') %]
+                [% IF ( total || Koha.Preference('CircSidebar') ) %]
                     <div class="col-sm-10 col-sm-push-2">
                 [% ELSE %]
                     <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
@@ -202,58 +202,74 @@
 	[% END %] 
 	[% END %]
 
-[% UNLESS ( total ) %]
-<form name="f" action="/cgi-bin/koha/circ/view_holdsqueue.pl">
-	<fieldset class="rows">
-	<ol>
-        <li>
-            <label for="branchlimit">Library: </label>
-            <select name="branchlimit" id="branchlimit">
-                <option value="">All</option>
-                [% PROCESS options_for_libraries libraries => Branches.all( only_from_group => 1 ) %]
-            </select>
-        </li>
-        <li>
-            <label for="itemtypeslimit">Item type: </label>
-            <select name="itemtypeslimit" id="itemtypeslimit">
-                <option value="">All</option>
-                [% PROCESS options_for_item_types itemtypes => ItemTypes.Get() %]
-            </select>
-        </li>
-        <li>
-            <label for="ccodeslimit">Collection code: </label>
-            <select name="ccodeslimit" id="ccodeslimit">
-                <option value="">All</option>
-                [% PROCESS options_for_authorised_values authorised_values => AuthorisedValues.GetAuthValueDropbox( 'CCODE' ) %]
-            </select>
-        </li>
-        <li>
-            <label for="locationsslimit">Shelving location: </label>
-            <select name="locationslimit" id="ccodeslimit">
-                <option value="">All</option>
-                [% PROCESS options_for_authorised_values authorised_values => AuthorisedValues.GetAuthValueDropbox( 'LOC' ) %]
-            </select>
-        </li>
-    </ol></fieldset>
-    <fieldset class="action">    <input type="submit" value="Submit" />
-        <input type="hidden" name="run_report" value="1" /></fieldset>
-</form>
-[% END %]
+                        [% UNLESS ( total ) %]
+                            [% PROCESS filter_form %]
+                        [% END %]
 
-                    [% IF Koha.Preference('CircSidebar') %]
-                            </div> <!-- /.col-sm-10.col-sm-push-2 -->
-                            <div class="col-sm-2 col-sm-pull-10">
-                                <aside>
+                    </div> <!-- /.col-sm-10.col-sm-push-2 -->
+                    [% IF ( total || Koha.Preference('CircSidebar') ) %]
+                        <div class="col-sm-2 col-sm-pull-10">
+                            <aside>
+                                [% IF ( total ) %]
+                                    [% PROCESS filter_form %]
+                                [% END %]
+                                [% IF Koha.Preference('CircSidebar') %]
                                     [% INCLUDE 'circ-nav.inc' %]
-                                </aside>
-                            </div> <!-- /.col-sm-2.col-sm-pull-10 -->
-                        </div> <!-- /.row -->
+                                [% END %]
+                            </aside>
+                        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
                     [% END %]
+                </div> <!-- /.row -->
 
             </main>
         </div> <!-- /.col-sm-12 -->
     </div> <!-- /.row -->
 
+[% BLOCK filter_form %]
+    <form name="f" action="/cgi-bin/koha/circ/view_holdsqueue.pl">
+        [% IF ( total ) %]
+            <fieldset class="brief">
+        [% ELSE -%]
+            <fieldset class="rows">
+        [% END %]
+            <ol>
+                <li>
+                    <label for="branchlimit">Library: </label>
+                    <select name="branchlimit" id="branchlimit">
+                        <option value="">All</option>
+                        [% PROCESS options_for_libraries libraries => Branches.all( selected => branchlimit, only_from_group => 1 ) %]
+                    </select>
+                </li>
+                <li>
+                    <label for="itemtypeslimit">Item type: </label>
+                    <select name="itemtypeslimit" id="itemtypeslimit">
+                        <option value="">All</option>
+                        [% PROCESS options_for_item_types itemtypes => ItemTypes.Get(), selected_itemtype => itemtypeslimit %]
+                    </select>
+                </li>
+                <li>
+                    <label for="ccodeslimit">Collection code: </label>
+                    <select name="ccodeslimit" id="ccodeslimit">
+                        <option value="">All</option>
+                        [% PROCESS options_for_authorised_values authorised_values => AuthorisedValues.GetAuthValueDropbox( 'CCODE' ), selected_av => ccodeslimit %]
+                    </select>
+                </li>
+                <li>
+                    <label for="locationsslimit">Shelving location: </label>
+                    <select name="locationslimit" id="locationslimit">
+                        <option value="">All</option>
+                        [% PROCESS options_for_authorised_values authorised_values => AuthorisedValues.GetAuthValueDropbox( 'LOC' ), selected_av => locationslimit %]
+                    </select>
+                </li>
+            </ol>
+        </fieldset>
+        <fieldset class="action">
+            <input type="submit" value="Submit" />
+            <input type="hidden" name="run_report" value="1" />
+        </fieldset>
+    </form>
+[% END %]
+
 [% MACRO jsinclude BLOCK %]
     [% INCLUDE 'datatables.inc' %]
     [% INCLUDE 'columns_settings.inc' %]
-- 
2.30.1 (Apple Git-130)