Bug 12675: Remove CGI::scrolling_list from labeledMARCdetail.pl
authorBernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Tue, 29 Jul 2014 18:49:44 +0000 (15:49 -0300)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Sun, 3 Aug 2014 19:53:00 +0000 (16:53 -0300)
This patch removes only instance in this file.

Also updates getframework POD on C4/Koha.pm,
adds new GetFrameworksLoop() func on same file from
suggested code, but with ordered result.

To test:
1. Apply the patch
2. Enable viewLabeledMARC syspref
3. On staff, search for a record, goto detail view
4. Clic on Labeled MARC
5. Framework pulldown was replaced, check changing
framework.

A bug was fixed, because selecting any fw and then Default
tries to load values from 'Default' fw code, which does not
exists.

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

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/Koha.pm
catalogue/labeledMARCdetail.pl
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/labeledMARCdetail.tt

index 6f98ac6..ee4bd67 100644 (file)
@@ -46,6 +46,7 @@ BEGIN {
                &GetSupportName &GetSupportList
                &get_itemtypeinfos_of
                &getframeworks &getframeworkinfo
+        &GetFrameworksLoop
                &getauthtypes &getauthtype
                &getallthemes
                &getFacets
@@ -363,12 +364,13 @@ build a HTML select with the following code :
 
 =head3 in PERL SCRIPT
 
-  my $frameworks = frameworks();
+  my $frameworks = getframeworks();
   my @frameworkloop;
   foreach my $thisframework (keys %$frameworks) {
     my $selected = 1 if $thisframework eq $frameworkcode;
-    my %row =(value => $thisframework,
-                selected => $selected,
+    my %row =(
+                value       => $thisframework,
+                selected    => $selected,
                 description => $frameworks->{$thisframework}->{'frameworktext'},
             );
     push @frameworksloop, \%row;
@@ -377,14 +379,18 @@ build a HTML select with the following code :
 
 =head3 in TEMPLATE
 
-  <form action='<!-- TMPL_VAR name="script_name" -->' method=post>
+  <form action="[% script_name %] method=post>
     <select name="frameworkcode">
         <option value="">Default</option>
-    <!-- TMPL_LOOP name="frameworkloop" -->
-        <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="frameworktext" --></option>
-    <!-- /TMPL_LOOP -->
+        [% FOREACH framework IN frameworkloop %]
+        [% IF ( framework.selected ) %]
+        <option value="[% framework.value %]" selected="selected">[% framework.description %]</option>
+        [% ELSE %]
+        <option value="[% framework.value %]">[% framework.description %]</option>
+        [% END %]
+        [% END %]
     </select>
-    <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->">
+    <input type=text name=searchfield value="[% searchfield %]">
     <input type="submit" value="OK" class="button">
   </form>
 
@@ -403,6 +409,55 @@ sub getframeworks {
     return ( \%itemtypes );
 }
 
+=head2 GetFrameworksLoop
+
+  $frameworks = GetFrameworksLoop( $frameworkcode );
+
+Returns the loop suggested on getframework(), but ordered by framework description.
+
+build a HTML select with the following code :
+
+=head3 in PERL SCRIPT
+
+  $template->param( frameworkloop => GetFrameworksLoop( $frameworkcode ) );
+
+=head3 in TEMPLATE
+
+  Same as getframework()
+
+  <form action="[% script_name %] method=post>
+    <select name="frameworkcode">
+        <option value="">Default</option>
+        [% FOREACH framework IN frameworkloop %]
+        [% IF ( framework.selected ) %]
+        <option value="[% framework.value %]" selected="selected">[% framework.description %]</option>
+        [% ELSE %]
+        <option value="[% framework.value %]">[% framework.description %]</option>
+        [% END %]
+        [% END %]
+    </select>
+    <input type=text name=searchfield value="[% searchfield %]">
+    <input type="submit" value="OK" class="button">
+  </form>
+
+=cut
+
+sub GetFrameworksLoop {
+    my $frameworkcode = shift;
+    my $frameworks = getframeworks();
+    my @frameworkloop;
+    foreach my $thisframework (sort { uc($frameworks->{$a}->{'frameworktext'}) cmp uc($frameworks->{$b}->{'frameworktext'}) } keys %$frameworks) {
+        my $selected = ( $thisframework eq $frameworkcode ) ? 1 : undef;
+        my %row = (
+                value       => $thisframework,
+                selected    => $selected,
+                description => $frameworks->{$thisframework}->{'frameworktext'},
+            );
+        push @frameworkloop, \%row;
+  }
+  return \@frameworkloop;
+}
+
 =head2 getframeworkinfo
 
   $frameworkinfo = &getframeworkinfo($frameworkcode);
index 66c0f74..11f8f85 100755 (executable)
@@ -29,6 +29,7 @@ use C4::Items;
 use C4::Members; # to use GetMember
 use C4::Search;                # enabled_staff_search_views
 use C4::Acquisition qw(GetOrdersByBiblionumber);
+use C4::Koha qw( GetFrameworksLoop );
 
 my $query        = new CGI;
 my $dbh          = C4::Context->dbh;
@@ -79,30 +80,8 @@ my $itemcount = GetItemsCount($biblionumber);
 $template->param( count => $itemcount,
                                        bibliotitle => $biblio->{title}, );
 
-#Getting the list of all frameworks
-my $queryfwk =
-  $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
-$queryfwk->execute;
-my %select_fwk;
-my @select_fwk;
-my $curfwk;
-push @select_fwk, "Default";
-$select_fwk{"Default"} = "Default";
-
-while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
-    push @select_fwk, $fwk;
-    $select_fwk{$fwk} = $description;
-}
-$curfwk=$frameworkcode;
-my $framework=CGI::scrolling_list( -name     => 'Frameworks',
-            -id => 'Frameworks',
-            -default => $curfwk,
-            -OnChange => 'Changefwk(this);',
-            -values   => \@select_fwk,
-            -labels   => \%select_fwk,
-            -size     => 1,
-            -multiple => 0 );
-$template->param(framework => $framework);
+#Getting framework loop
+$template->param(frameworkloop => GetFrameworksLoop( $frameworkcode ) );
 
 my @marc_data;
 my $prevlabel = '';
index 882a90c..957f6ce 100644 (file)
                                        [% UNLESS ( popup ) %]
                                                <h1>Labeled MARC biblio : [% biblionumber %]  ( [% bibliotitle %] )</h1>
                                        [% END %]
-                    <p><b>With framework :[% framework %]</b></p>
+                    <p><b>With framework:
+                    <select name="Frameworks" id="Frameworks" size="1" onchange="Changefwk(this);">
+                        <option value="">Default</option>
+                        [% FOREACH framework IN frameworkloop %]
+                        [% IF ( framework.selected ) %]
+                        <option value="[% framework.value %]" selected="selected">[% framework.description %]</option>
+                        [% ELSE %]
+                        <option value="[% framework.value %]">[% framework.description %]</option>
+                        [% END %]
+                        [% END %]
+                    </select>
+                    </b></p>
                                        <!-- div id="bibliotabs" class="toptabs numbered" -->
                                        <div>
                                                <table class="labeledmarc-table">