You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl-cvs@perl.apache.org by ri...@apache.org on 2011/06/16 06:49:08 UTC

svn commit: r1136288 - in /perl/embperl/trunk: Embperl/Form/Control/age.pm Embperl/Form/Control/grid.pm MANIFEST

Author: richter
Date: Thu Jun 16 04:49:07 2011
New Revision: 1136288

URL: http://svn.apache.org/viewvc?rev=1136288&view=rev
Log:
- Allow mulitple times the same field in a grid
- Add age form control

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

Added: perl/embperl/trunk/Embperl/Form/Control/age.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/age.pm?rev=1136288&view=auto
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/age.pm (added)
+++ perl/embperl/trunk/Embperl/Form/Control/age.pm Thu Jun 16 04:49:07 2011
@@ -0,0 +1,151 @@
+
+###################################################################################
+#
+#   Embperl - Copyright (c) 1997-2005 Gerald Richter / ecos gmbh   www.ecos.de
+#
+#   You may distribute under the terms of either the GNU General Public
+#   License or the Artistic License, as specified in the Perl README file.
+#
+#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+#
+#   $Id$
+#
+###################################################################################
+
+package Embperl::Form::Control::age ;
+
+use strict ;
+use base 'Embperl::Form::Control::number' ;
+
+use Embperl::Inline ;
+
+use vars qw{%fdat} ;
+
+use Date::Calc qw{Delta_DHMS};
+# ---------------------------------------------------------------------------
+#
+#   init - init the new control
+#
+
+sub init
+
+    {
+    my ($self) = @_ ;
+
+    $self->{unit}      ||= '' ;
+    
+    return $self ;
+    }
+    
+# ------------------------------------------------------------------------------------------
+#
+#   init_data - daten aufteilen
+#
+
+sub init_data
+    {
+    my ($self, $req, $parentctrl) = @_ ;
+    
+    my $fdat  = $req -> {docdata} || \%fdat ;
+    my $name    = $self->{name} ;
+    my $val     = $fdat->{$name} ;
+    return if ($val eq '') ;
+
+    #20060914041444Z
+    my ($year, $mon, $mday, $hour, $min, $sec, $tz) = ($val =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(.)$/) ;
+    my ($sec2, $min2, $hour2, $mday2, $mon2, $year2) = gmtime ;
+    $mon2++ ;
+    $year2+=1900 ;
+    #warn "$_[0] $year,$mon,$mday, $hour,$min,$sec,$year2,$mon2,$mday2, $hour2,$min2,$sec2" ;
+    my ($Dd,$Dh,$Dm,$Ds) = eval { Delta_DHMS($year,$mon,$mday, $hour,$min,$sec,
+                                      $year2,$mon2,$mday2, $hour2,$min2,$sec2) } ;
+
+    $fdat->{$name} = $Dd > 0?"${Dd}Tage":sprintf ('%d:%02dh', $Dh, $Dm) ;
+    }
+
+# ------------------------------------------------------------------------------------------
+#
+#   prepare_fdat - daten zusammenfuehren
+#
+
+sub prepare_fdat
+    {
+    my ($self, $req) = @_ ;
+
+    my $fdat  = $req -> {form} || \%fdat ;
+    my $name    = $self->{name} ;
+    my $val     = $fdat->{$name} ;
+    return if ($val eq '') ;
+    
+    }
+
+1 ;
+
+__EMBPERL__
+
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Embperl::Form::Control::age - A age input control with optional unit inside an Embperl Form
+
+
+=head1 SYNOPSIS
+
+  {
+  type => 'age',
+  text => 'blabla',
+  name => 'foo',
+  unit => 'sec',
+  }
+
+=head1 DESCRIPTION
+
+Used to create a age input control inside an Embperl Form.
+Will format date as days:hours:minutes from current time.
+Optionaly it can display an unit after the input field.
+See Embperl::Form on how to specify parameters.
+
+=head2 PARAMETER
+
+=head3 type
+
+Needs to be 'age'
+
+=head3 name
+
+Specifies the name of the control
+
+=head3 text
+
+Will be used as label for the numeric input control
+
+=head3 size
+
+Gives the size in characters. (Default: 10)
+
+=head3 maxlength
+
+Gives the maximun length in characters
+
+=head3 unit
+
+Gives a string that should be displayed right of the input field.
+(
+
+
+
+=head1 Author
+
+G. Richter (richter@dev.ecos.de)
+
+=head1 See Also
+
+perl(1), Embperl, Embperl::Form
+
+

Modified: perl/embperl/trunk/Embperl/Form/Control/grid.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/grid.pm?rev=1136288&r1=1136287&r2=1136288&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/grid.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/grid.pm Thu Jun 16 04:49:07 2011
@@ -90,10 +90,10 @@ sub init_data
         foreach my $field (@$fields)
             {
             $col = exists $field -> {col}?$field -> {col}:$j ;
-            $fdat->{"$name-$field->{name}-$i"} = $data->[$col] ;
+            $fdat->{"$name-$j-$i"} = $data->[$col] ;
             if ($field -> can ('init_data'))
                 {
-                local $field->{name} = "$name-$field->{name}-$i" ;
+                local $field->{name} = "$name-$j-$i" ;
                 $field -> init_data ($req, $self)  ;
                 }
             $j++ ;    
@@ -142,14 +142,16 @@ sub prepare_fdat
     for (my $i = 0; $i < $max; $i++)
         {
 	my $ok = 0 ;
+        my $j = 0 ;
         foreach my $field (@$fields)
             {
             if ((ref ($field) =~ /::/) && $field -> can ('prepare_fdat'))
                 {
-                local $field->{name} = "$name-$field->{name}-$i" ;
+                local $field->{name} = "$name-$j-$i" ;
                 $field -> prepare_fdat ($req)  ;
                 }
 	    $ok++ ;
+            $j++ ;
             }
         
 	next if (!$ok) ;
@@ -170,7 +172,7 @@ sub prepare_fdat
         foreach my $field (@$fields)
             {
             $col = exists $field -> {col}?$field -> {col}:$j ;
-            $data[$col+1] = $fdat->{"$name-$field->{name}-$i"} ;
+            $data[$col+1] = $fdat->{"$name-$j-$i"} ;
             $j++ ;
             }
         $val = $ldap?ecos::LdapBase -> joinAttrValue(\@data):\@data ;
@@ -290,13 +292,14 @@ $]
     my $n      = 0 ;
     my $gridro = $self -> is_readonly () ;
     my $ro ;
+    my $j = 0 ;
     $]
 
     <tr class="cGridRow" id="[+ "$id-row-$i" +]">
         [$foreach $field (@$fields)$]
             [- $ro = $gridro || $field -> is_readonly ; -]
             <td class="[+ $ro?'cGridCellReadonly':'cGridCell' +]">[$if $n++ == 0$]<input type="hidden" name="[+ "$name-#row#-$i" +]" value="[+ $i +]">[$endif$][-
-                local $field -> {name} = "$name-$field->{name}-$i" ;
+                local $field -> {name} = "$name-$j-$i" ;
                 if ($ro)
                     {
                     $field -> show_control_readonly ($req)
@@ -305,6 +308,7 @@ $]
                     {
                     $field -> show_control ($req)
                     }
+                $j++ ;
                 -]</td>
         [$endforeach$]     
     </tr>

Modified: perl/embperl/trunk/MANIFEST
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/MANIFEST?rev=1136288&r1=1136287&r2=1136288&view=diff
==============================================================================
--- perl/embperl/trunk/MANIFEST (original)
+++ perl/embperl/trunk/MANIFEST Thu Jun 16 04:49:07 2011
@@ -11,6 +11,7 @@ Embperl/App.pm
 Embperl/Constant.pm
 Embperl/Form.pm
 Embperl/Form/Control.pm
+Embperl/Form/Control/age.pm
 Embperl/Form/Control/addremove.pm
 Embperl/Form/Control/blank.pm
 Embperl/Form/Control/button.pm



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