Bug 766: Create a plugin routine to build dropdown list
authorJonathan Druart <jonathan.druart@biblibre.com>
Thu, 6 Mar 2014 16:07:08 +0000 (17:07 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Sun, 4 May 2014 23:02:29 +0000 (23:02 +0000)
On this way, dropdown list could be generated from the templates.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Koha/Template/Plugin/AuthorisedValues.pm

index 8f80cb1..3013706 100644 (file)
@@ -25,6 +25,7 @@ use base qw( Template::Plugin );
 use Encode qw{encode decode};
 
 use C4::Koha;
+use C4::Charset;
 
 =pod
 
@@ -43,9 +44,34 @@ sub GetByCode {
     return encode( 'UTF-8', GetAuthorisedValueByCode( $category, $code, $opac ) );
 }
 
+
 sub Get {
     my ( $self, $category, $selected, $opac ) = @_;
     return GetAuthorisedValues( $category, $selected, $opac );
 }
 
+sub BuildDropbox {
+    my ( $self, $name, $category, $default, $params ) = @_;
+    my $class = $params->{class};
+    my $avs = C4::Koha::GetAuthvalueDropbox($category, $default);
+    my $size = $params->{size} || 20;
+    my $html;
+    if ( @$avs ) {
+        $html = qq|<select id="$name" name="$name" class="$class" >|;
+        for my $av ( @$avs ) {
+            if ( $av->{default} ) {
+                $html .= qq|<option value="$av->{value}" selected="selected">$av->{label}</option>|;
+            } else {
+                $html .= qq|<option value="$av->{value}">$av->{label}</option>|;
+            }
+        }
+        $html .= q|</select>|;
+    } else {
+        $html .= qq|<input type="text" id="$name" name="$name" size="$size" value="$default" class="$class" />|;
+
+    }
+
+    return encode( 'UTF-8', $html );
+}
+
 1;