[Rt-commit] r5245 - in rt/branches/3.7-EXPERIMENTAL: html/Widgets/Form

ruz at bestpractical.com ruz at bestpractical.com
Thu May 18 06:14:10 EDT 2006


Author: ruz
Date: Thu May 18 06:14:09 2006
New Revision: 5245

Modified:
   rt/branches/3.7-EXPERIMENTAL/   (props changed)
   rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Select

Log:
 r2887 at cubic-pc:  cubic | 2006-05-13 01:59:41 +0400
 * add ValuesCallback argument, function reference
 ** function should return arrayref with values or hashref with value => label pairs
 * return array reference only when Multiple is true, otherwise always return scalar


Modified: rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Select
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Select	(original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Select	Thu May 18 06:14:09 2006
@@ -29,6 +29,19 @@
 </div>
 <%INIT>
 my %CurrentValue = map {$_ => 1} grep defined, @CurrentValue;
+if ( $ValuesCallback ) {
+    my $values = $ValuesCallback->(
+        CurrentUser => $session{'CurrentUser'},
+        NamePrefix  => $NamePrefix,
+        Name        => $Name,
+    );
+    if ( ref $values eq 'ARRAY' ) {
+        @Values = @$values;
+    } else {
+        %ValuesLabel = %$values;
+        @Values = keys %ValuesLabel;
+    }
+}
 </%INIT>
 <%ARGS>
 $NamePrefix       => 'Select-',
@@ -36,6 +49,7 @@
 $Description      => undef,
 
 @Values           => (),
+$ValuesCallback   => undef,
 %ValuesLabel      => (),
 @CurrentValue     => (),
 
@@ -67,7 +81,10 @@
 <%INIT>
 my $value = $Arguments->{ $NamePrefix . $Name };
 if( !defined $value || $value eq '__empty_value__' ) {
-    return [ @CurrentValue ] unless $Empty;
+    unless ( $Empty ) {
+        return [ @CurrentValue ] if $Multiple;
+        return $CurrentValue[0];
+    }
     return undef;
 }
 $value = [$value] unless ref $value;


More information about the Rt-commit mailing list