Bug 766: Remove CGI::scrollinglist from authorised_values.pl
authorBernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Sat, 19 Jul 2014 03:22:12 +0000 (00:22 -0300)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Wed, 13 Aug 2014 13:11:11 +0000 (10:11 -0300)
This patch removes the only instance in this file.
Also fixes array sorting, removes some tabs, removes
an unneeded $dbh handler (there is a global one).
Makes use of C4::Koha::GetAuthorisedValueCategories.

To test:
1. Apply the patch
2. Go to Administration > Authorised values
3. Replaced pulldown next to 'Show category' must
show all (present & system) categories correctly ordered.
4. Select some and check for regressions, e.g. CCODE, Bsort2, YES_NO
no changes must be observed

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as described, no problems found.
Passes tests and QA script.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
admin/authorised_values.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt

index 8a44256..35afaca 100755 (executable)
@@ -237,12 +237,10 @@ exit 0;
 
 sub default_form {
     # build categories list
-    my $sth = $dbh->prepare("select distinct category from authorised_values");
-    $sth->execute;
-    my @category_list;
+    my $category_list = C4::Koha::GetAuthorisedValueCategories();
+    my @category_list = @{$category_list};
     my %categories;    # a hash, to check that some hardcoded categories exist.
-    while ( my ($category) = $sth->fetchrow_array ) {
-        push( @category_list, $category );
+    for my $category ( @category_list ) {
         $categories{$category} = 1;
     }
 
@@ -252,23 +250,19 @@ sub default_form {
     }
 
        #reorder the list
-       @category_list = sort {$a cmp $b} @category_list;
-       my $tab_list = CGI::scrolling_list(-name=>'searchfield',
-               -id=>'searchfield',
-                       -values=> \@category_list,
-                       -default=>"",
-                       -size=>1,
-                       -multiple=>0,
-                       );
+    @category_list = sort {lc($a) cmp lc($b)} @category_list;
        if (!$searchfield) {
                $searchfield=$category_list[0];
        }
+    my $tab_list = {
+        values  => \@category_list,
+        default => $searchfield,
+    };
     my ($results) = AuthorizedValuesForCategory($searchfield);
     my $count = scalar(@$results);
        my @loop_data = ();
        # builds value list
-    my $dbh = C4::Context->dbh;
-    $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?");
+    my $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?");
        for (my $i=0; $i < $count; $i++){
         $sth->execute( $results->[$i]{id} );
         my @selected_branches;
@@ -287,8 +281,10 @@ sub default_form {
                push(@loop_data, \%row_data);
        }
 
-       $template->param( loop     => \@loop_data,
-                          tab_list => $tab_list,
-                          category => $searchfield );
+    $template->param(
+            loop     => \@loop_data,
+            tab_list => $tab_list,
+            category => $searchfield,
+    );
 }
 
index 9e96c34..2549a0f 100644 (file)
@@ -194,7 +194,19 @@ $(document).ready(function() {
 <div class="dialog alert">Could not add value &quot;[% duplicate_value %]&quot; for category &quot;[% duplicate_category %]&quot; &mdash; value already present.
 </div>
 [% END %]
-<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category"><label for="searchfield">Show category: </label>[% tab_list %] <input type="submit" value="Submit" /></form>
+<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category">
+    <label for="searchfield">Show category: </label>
+    <select name="searchfield" id="searchfield" size="1">
+    [% FOREACH value IN tab_list.values %]
+    [% IF ( value == tab_list.default ) %]
+        <option value="[% value %]" selected="selected">[% value %]</option>
+    [% ELSE %]
+        <option value="[% value %]">[% value %]</option>
+    [% END %]
+    [% END %]
+    </select>
+    <input type="submit" value="Submit" />
+</form>
 [% IF ( category == 'Bsort1' ) %]
     <p>An authorized value attached to patrons, that can be used for stats purposes</p>
 [% END %]