From d37a73c6cee7e42a57c7157530fc84ebc03a2bae Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Mon, 11 Jan 2016 11:32:23 +0000
Subject: [PATCH] Bug 2669: Change checkboxes to radio buttons on dictionary
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On creating new dictionary for report, the choice between "All dates"
and "Date range" should be a real radio button, not 2 radio buttons with
different names (which means they could be selected altogether...)

Note that I don't understand what means 'All dates', there is no
condition generated for the dictionary. We should not have to select a
field if we don't want to add a condition on it :)

Test plan:
Create a new dictionary for the Patron module, then a date field
(dateenrolled or birthdate, etc.)

Confirm that the radio buttons now behave as radio buttons...

Signed-off-by: Aleisha <aleishaamohia@hotmail.com>

Looks so much nicer too!

Radio buttons display as expected.
Signed-off-by: Marc Véron <veron@veron.ch>
---
 .../prog/en/modules/reports/dictionary.tt          |   36 ++++++--------
 reports/dictionary.pl                              |   51 +++++++++++---------
 2 files changed, 41 insertions(+), 46 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tt
index f356cd9..c21af0d 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tt
@@ -189,28 +189,20 @@
 	</select></li>
 [% END %]
 [% IF ( column.date ) %]
-	<li><span class="label">Choose: </span><table>
-	<tr valign="top">
-	<td><input type="radio" name="[% column.name %]_all" value="all" />All dates</td>
-	<td>OR</td>
-	<td><input type="radio" name="dates" value="range" />Date range<br />
-	<table>
-	<tr>
-	<td>Start of date range</td>
-    <td><input type="text" size="10" id="from" name="[% column.name %]_start_value" value="" class="datepickerfrom" />
-	<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
-	</td>
-	</tr>
-	<tr>
-	<td>End of date range</td>
-	<td>
-    <input type="text" size="10" id="to" name="[% column.name %]_end_value" value="" class="datepickerto" />
-	<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
-	</td>
-	</tr>
-	</table></td>
-	</tr>
-</table></li>
+    <li class="radio">
+        <label for="all_dates">All dates</label>
+        <input type="radio" id="all_dates" name="[% column.name %]_date_type_value" value="all" checked="checked" />
+        <label for="date_range">Date range</label>
+        <input type="radio" id="date_range" name="[% column.name %]_date_type_value" value="range" />
+    </li>
+    <li class="radio">
+        Start of date range
+        <input type="text" size="10" id="from" name="[% column.name %]_start_value" value="" class="datepickerfrom" />
+        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+        End of date range
+        <input type="text" size="10" id="to" name="[% column.name %]_end_value" value="" class="datepickerto" />
+        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
+    </li>
 [% END %]
 [% IF ( column.text ) %]
 	<li><label for="[% column.name %]_value">Search string matches: </label> <input type="text" size="13" name="[% column.name %]_value" /></li>
diff --git a/reports/dictionary.pl b/reports/dictionary.pl
index 964f76f..ae6fe7d 100755
--- a/reports/dictionary.pl
+++ b/reports/dictionary.pl
@@ -147,31 +147,34 @@ elsif ( $phase eq 'New Term step 5' ) {
 
             $query_criteria .= " AND $crit='$value'";
         }
-        $value = $input->param( $crit . "_start_value" );
 
-        if ($value) {
-            my %tmp_hash;
-            $tmp_hash{'name'}  = "$crit Start";
-            $tmp_hash{'value'} = $value;
-            push @criteria_loop, \%tmp_hash;
-            my $value_dt = eval { dt_from_string( $value ) };
-            $value = output_pref( { dt => $value_dt, dateonly => 1, dateformat => 'iso' } )
-                if ( $value_dt );
-
-            $query_criteria .= " AND $crit >= '$value'";
-        }
-
-        $value = $input->param( $crit . "_end_value" );
-        if ($value) {
-            my %tmp_hash;
-            $tmp_hash{'name'}  = "$crit End";
-            $tmp_hash{'value'} = $value;
-            push @criteria_loop, \%tmp_hash;
-            my $value_dt = eval { dt_from_string( $value ) };
-            $value = output_pref( { dt => $value_dt, dateonly => 1, dateformat => 'iso' } )
-                if ( $value_dt );
-
-            $query_criteria .= " AND $crit <= '$value'";
+        if ( my $date_type_value = $input->param( $crit . "_date_type_value" ) ) {
+            if ( $date_type_value eq 'range' ) {
+                if ( $value = $input->param( $crit . "_start_value" ) ) {
+                    my %tmp_hash;
+                    $tmp_hash{'name'}  = "$crit Start";
+                    $tmp_hash{'value'} = $value;
+                    push @criteria_loop, \%tmp_hash;
+                    my $value_dt = eval { dt_from_string( $value ) };
+                    $value = output_pref( { dt => $value_dt, dateonly => 1, dateformat => 'iso' } )
+                        if ( $value_dt );
+
+                    $query_criteria .= " AND $crit >= '$value'";
+                }
+
+                if ( $value = $input->param( $crit . "_end_value" ) ) {
+                    my %tmp_hash;
+                    $tmp_hash{'name'}  = "$crit End";
+                    $tmp_hash{'value'} = $value;
+                    push @criteria_loop, \%tmp_hash;
+                    my $value_dt = eval { dt_from_string( $value ) };
+                    $value = output_pref( { dt => $value_dt, dateonly => 1, dateformat => 'iso' } )
+                        if ( $value_dt );
+
+                    $query_criteria .= " AND $crit <= '$value'";
+                }
+            }
+            # else we want all dates
         }
     }
     $template->param(
-- 
1.7.10.4