Author: richter
Date: Thu Jul 19 05:55:05 2012
New Revision: 1363224

URL: http://svn.apache.org/viewvc?rev=1363224&view=rev
Log:
Add flat readonly view for grid

Modified:
    perl/embperl/trunk/Embperl/Form/Control/grid.pm

Modified: perl/embperl/trunk/Embperl/Form/Control/grid.pm
URL: 
http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/grid.pm?rev=1363224&r1=1363223&r2=1363224&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/grid.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/grid.pm Thu Jul 19 05:55:05 2012
@@ -55,10 +55,27 @@ sub init
     $self -> {header_bottom} = 10 if (!exists ($self -> {header_bottom})) ;
     $self -> {width} = 1 ;
     
+    my $flat   = $self -> {flatopt} ;
+    my @flat   = split /\s*;\s*/, $flat ;
+    my $fields = $self -> {fields} ;
+    if (@flat)
+        {
+        my @fields = @$fields ;
+        foreach (@fields)
+            {
+            my $name = $_ -> {name} ;
+            for (my $i = 0 ; $i < @flat; $i+=3)
+                {
+                $_ -> {$flat[$i+1]} = $flat[$i+2] if ($name eq $flat[$i]);     
   
+                }
+            }
+        $fields = \@fields ;
+        $self -> {fields} = $fields ;    
+        }
     my $form = $self -> form ;
     my $options = $form -> {options} ;
     my $validate_rules = $self -> {validate_rules} = [] ;
-    $form -> new_controls ($self -> {fields}, $options, undef, undef, 
$validate_rules, $options -> {masks}, $options -> {defaults}, 1) ;
+    $form -> new_controls ($fields, $options, undef, undef, $validate_rules, 
$options -> {masks}, $options -> {defaults}, 1) ;
     if ($self -> {line2})
         {
         my $ctl = [$self -> {line2}] ;
@@ -255,6 +272,56 @@ sub prepare_fdat
 
 __EMBPERL__
 
+[# ---------------------------------------------------------------------------
+#
+#   show_control_readonly - output readonly grid
+#]
+
+[$ sub show_control_readonly ($self, $req)
+
+    my $name     = $self -> {name} ;
+    my $max    = $fdat{"__${name}_max"} ;
+
+    my $flat   = $self -> {flat} ;
+    my @flat   = split /\s*;\s*/, $flat ;
+    my $fields = $self -> {'fields'};
+    my $i = 0 ;
+    my @fields ;
+    my %fields ;
+    foreach my $field (@$fields)
+        {
+        $fields{$field -> {name}} = $i ;
+        push @fields, $field -> {name} ;
+        $i++ ;
+        }
+    @fields = @flat if (@flat) ;
+
+    my @data ;
+    for ($i = 0; $i < $max ; $i++)
+        {
+        my $j ;
+        my @row ;
+        foreach $fieldname (@fields)
+            {
+            my $field = $fields -> [$fields{$fieldname}] ;
+            next if $field -> is_hidden ;
+            $j = $fields{$fieldname} ;
+            if ($field -> {datasrcobj})
+                {
+                push @row, $field -> get_option_from_value 
($fdat{"__${name}_${j}_$i"}, $req) ;
+                }
+            else
+                {
+                push @row, $fdat{"__${name}_${j}_$i"} ;
+                }
+            }
+        push @data, join (' ', @row) if (grep /\S/, @row) ;
+        }
+    my $value = join (' / ', @data) ;    
+    $]
+<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, '', 
'readonly') } +]>[+ $value +]</div>
+[$endsub$]
+  
 
 [# ---------------------------------------------------------------------------
 #
@@ -534,6 +601,21 @@ Sort descending
 Offset added to column number. Default: 1
 If > 1, column number will set to the rownumber
 
+=head3 flat
+
+This can be used for readonly view of grid. Normaly readonly view will show
+the content as one large string. The flat attribute can contain a semikolon
+delimited list of fields that should be show in readony view. That allows
+to selectivly show fields in readonly view. 
+This can be used to show a readonly view of a grid inside of another grid.
+
+=head3 flatopt
+
+Semikolon delimited list of tripels that add special options for flat view:
+
+<name of fields>;<option name>;<option value>
+
+
 =head2 Example
 
      {
@@ -547,6 +629,7 @@ If > 1, column number will set to the ro
         ],
     },
 
+
 =head1 Author
 
 G. Richter (rich...@dev.ecos.de)



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-cvs-unsubscr...@perl.apache.org
For additional commands, e-mail: embperl-cvs-h...@perl.apache.org

Reply via email to