Bug 766: Use a TT include instead of a method in the AV plugin
authorJonathan Druart <jonathan.druart@biblibre.com>
Mon, 17 Mar 2014 11:36:55 +0000 (12:36 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Sun, 4 May 2014 23:04:35 +0000 (23:04 +0000)
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
This gives a koha-qa error, but on another user/env not.
Really don't know

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
I see the same error, but can't see where this is coming from,
code seems to work ok.
Works as described, no regressions found.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Koha/Template/Plugin/AuthorisedValues.pm
koha-tmpl/intranet-tmpl/prog/en/includes/av-build-dropbox.inc [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt

index 3013706..b60819d 100644 (file)
@@ -44,34 +44,14 @@ 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 );
+sub GetAuthValueDropbox {
+    my ( $self, $category, $default ) = @_;
+    return C4::Koha::GetAuthvalueDropbox($category, $default);
 }
 
 1;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/av-build-dropbox.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/av-build-dropbox.inc
new file mode 100644 (file)
index 0000000..5002842
--- /dev/null
@@ -0,0 +1,29 @@
+[% USE AuthorisedValues %]
+[%#
+    Parameters:
+    name: tthe name of the select element
+    category: the authorised value category
+    default: the default authorised value to select
+    class: the css class of the select element
+    size: the size to use for the input (generated if not authorised value category exist).
+%]
+
+[% SET avs = AuthorisedValues.GetAuthValueDropbox( category, default ) %]
+[% DEFAULT
+    class = ''
+    size = 20
+%]
+
+[% IF avs %]
+  <select id="[% name %]" name="[% name %]" class="[% class %]" >
+  [% FOR av IN avs %]
+    [% IF av.default %]
+      <option value="[% av.value %]" selected="selected">[% av.label %]</option>
+    [% ELSE %]
+      <option value="[% av.value %]">[% av.label %]</option>
+    [% END %]
+  [% END %]
+  </select>
+[% ELSE %]
+  <input type="text" id="[% name %]" name="[% name %]" size="[% size %]" value="[% default %]" class="[% class %]" />
+[% END %]
index c4d0c6a..430543e 100644 (file)
@@ -1,4 +1,3 @@
-[% USE AuthorisedValues %]
 [% IF ( opduplicate ) %][% SET focusAction = "clearDupe" %][% END %]
 [% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
         <label for="sort1">
       [% END %]
       Sort 1: </label>
-      [% AuthorisedValues.BuildDropbox("sort1", "Bsort1", sort1, { class => focusAction, size => 20 } ) %]
+      [% PROCESS 'av-build-dropbox.inc' name="sort1", category="Bsort1", default=sort1, class=focusAction, size = 20 %]
       [% IF ( mandatorysort1 ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]
     <label for="sort2">
     [% END %]
     Sort 2: </label>
-    [% AuthorisedValues.BuildDropbox("sort2", "Bsort2", sort2, { class => focusAction, size => 20 } ) %]
+    [% PROCESS 'av-build-dropbox.inc' name="sort2", category="Bsort2", default=sort2, class=focusAction, size = 20 %]
     [% IF ( mandatorysort2 ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]