From 2801f0e1a48c4cce8876ff8cfae5217614a4efdb Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Mon, 20 Apr 2015 16:59:05 +0200
Subject: [PATCH] [PASSED QA] Bug 14022: Does not reset the subscription length
 on editing a subscription
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The subscription length is always set to the first/default value
('issues') when editing a subscription.
Even if you selected another value on creating/editing it, the form will
show you the first option.

Test plan:
1/ Add/Edit a subscription, select a subscription length different of
the first value (issues)
2/ Edit the subscription and confirm the value is kept

Bonus: issues, week and months become translatable.

Works as expected.
Signed-off-by: Marc Véron <veron@veron.ch>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 .../prog/en/modules/serials/subscription-add.tt    | 30 +++++++++++++++++-----
 serials/subscription-add.pl                        | 18 ++++---------
 2 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt
index 8401968..6bfe8d4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt
@@ -652,13 +652,31 @@ $(document).ready(function() {
                                     <li>
                                         <label for="subtype">Subscription length:</label>
                                         <select name="subtype" id="subtype">
-                                            [% FOREACH subt IN subtype %]
-                                                [% IF (subt.selected) %]
-                                                    <option value="[% subt.name %]" selected="selected">
-                                                [% ELSE %]
-                                                    <option value="[% subt.name %]">
+                                            [% FOREACH st IN subtypes %]
+                                                [% SWITCH st %]
+                                                    [% CASE 'numberlength' %]
+                                                        [% IF st == subtype %]
+                                                            <option value="issues" selected="selected">
+                                                        [% ELSE %]
+                                                            <option value="issues">
+                                                        [% END %]
+                                                        issues
+                                                    [% CASE 'weeklength' %]
+                                                        [% IF st == subtype %]
+                                                            <option value="weeks" selected="selected">
+                                                        [% ELSE %]
+                                                            <option value="weeks">
+                                                        [% END %]
+                                                        weeks
+                                                    [% CASE 'monthlength' %]
+                                                        [% IF st == subtype %]
+                                                            <option value="months" selected="selected">
+                                                        [% ELSE %]
+                                                            <option value="months">
+                                                        [% END %]
+                                                        months
+                                                    [% CASE %][% st %]
                                                 [% END %]
-                                                    [% subt.name %]
                                                 </option>
                                             [% END %]
                                         </select>
diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl
index 39d79b7..ce6f91d 100755
--- a/serials/subscription-add.pl
+++ b/serials/subscription-add.pl
@@ -59,8 +59,6 @@ my ($template, $loggedinuser, $cookie)
 
 
 my $sub_on;
-my @subscription_types = (qw(issues weeks months));
-my @sub_type_data;
 
 my $subs;
 our $firstissuedate;
@@ -164,17 +162,11 @@ if ($op eq 'addsubscription') {
 } elsif ($op eq 'modsubscription') {
     redirect_mod_subscription();
 } else {
-        while (@subscription_types) {
-           my $sub_type = shift @subscription_types;
-           my %row = ( 'name' => $sub_type );
-           if ( defined $sub_on and $sub_on eq $sub_type ) {
-	     $row{'selected'} = ' selected';
-           } else {
-	     $row{'selected'} = '';
-           }
-           push( @sub_type_data, \%row );
-        }
-    $template->param(subtype => \@sub_type_data);
+
+    $template->param(
+        subtypes => [ qw( numberlength weeklength monthlength ) ],
+        subtype => $sub_on,
+    );
 
     if ( $op ne 'modsubscription' && $op ne 'dup' && $op ne 'modify' ) {
         my $letters = get_letter_loop();
-- 
1.9.1