From d0278e1f17abb25903decb70ee8922ed89b6a0e4 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 16 Dec 2020 15:28:50 +0100
Subject: [PATCH] Bug 8287: Improve "show checked out items" filter on the
 overdues report

The "Show any items currently checked out" was confusing, especially if
the "From" and "To" due date filters were passed.

This patch moves the checkbox close to the 2 other filters and show/hide
the due date filters when needed.

Test plan:
0. Have some overdue
1. Search for overdues
2. Confirm that the filters are shown/hidden depending on the status of
the checkbox
3. Fill "To" with a date, tick the checkbox, submit the form
=> Confirm that the date was not taken into account

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 .../intranet-tmpl/prog/en/modules/circ/overdue.tt  | 56 +++++++++++++++-------
 1 file changed, 39 insertions(+), 17 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt
index f5a32f2d1c..d4c90e5700 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt
@@ -114,16 +114,27 @@
 <form method="post" action="/cgi-bin/koha/circ/overdue.pl">
   <fieldset class="brief">
 <h4>Filter on:</h4>
-	<fieldset><legend>Date due:</legend>
-	<ol>
-    <li><label for="from">From:</label>
-    <input type="text" id="from" name="dateduefrom" size="10" value="[% filters.dateduefrom | $KohaDates %]" class="datepickerfrom" />
-	</li>
-	<li>
-    <label for="to">To:</label>
-    <input type="text" id="to" name="datedueto" size="10" value="[% filters.datedueto | $KohaDates %]" class="datepickerto" />
-    </li>
-    </ol></fieldset>
+    <fieldset><legend>Date due:</legend>
+        <ol>
+            <li class="radio">
+                <label for="showall">Show any items currently checked out:</label>
+                [% IF ( showall ) %]
+                        <input type="checkbox" id="showall" name="showall" value="show" checked="checked" />
+                [% ELSE %]
+                    <input type="checkbox" id="showall" name="showall" value="show" />
+                [% END %]
+            </li>
+
+            <li class="date_due_filter">
+                <label for="from">From:</label>
+                <input type="text" id="from" name="dateduefrom" size="10" value="[% filters.dateduefrom | $KohaDates %]" class="datepickerfrom" />
+            </li>
+            <li class="date_due_filter">
+                <label for="to">To:</label>
+                <input type="text" id="to" name="datedueto" size="10" value="[% filters.datedueto | $KohaDates %]" class="datepickerto" />
+            </li>
+        </ol>
+    </fieldset>
     <ol>
     <li><label>Name or cardnumber:</label><input type="text" name="borname" value="[% filters.borname | html %]" /></li>
     <li><label>Patron category:</label><select name="borcat" id="borcat"><option value="">Any</option>
@@ -132,6 +143,7 @@
       [% END %]
       </select>
     </li>
+
     <li><label>Patron flags:</label>
         <select name="borflag" size="1" id="borflag">
             <option value="">None</option>
@@ -202,13 +214,6 @@
         </select>
     </li>
 
-<li class="radio"><label for="showall">Show any items currently checked out:</label>
-	[% IF ( showall ) %]
-            <input type="checkbox" id="showall" name="showall" value="show" checked="checked" />
-    [% ELSE %]
-        <input type="checkbox" id="showall" name="showall" value="show" />
-    [% END %]
-</li>
 </ol>
    <fieldset class="action">
       <input type="submit" value="Apply filter" class="submit" />
@@ -277,6 +282,18 @@
             });
         }
 
+        function update_date_due_filters_visibility(){
+            if( $("#showall").is(":checked")) {
+                $(".date_due_filter").hide();
+                $("#from").prop("disabled", true);
+                $("#to").prop("disabled", true);
+            } else {
+                $(".date_due_filter").show();
+                $("#from").prop("disabled", false);
+                $("#to").prop("disabled", false);
+            }
+        }
+
         $(document).ready(function(){
             var columns_settings = [% TablesSettings.GetColumns( 'circ', 'overdues', 'circ-overdues', 'json' ) | $raw %];
             KohaTable("overduest", {
@@ -285,6 +302,11 @@
                 "autoWidth": false,
                 "stateSave": true
             }, columns_settings);
+
+            $("#showall").on("change", function(){
+                update_date_due_filters_visibility();
+            });
+            update_date_due_filters_visibility();
         });
   </script>
 [% END %]
-- 
2.11.0