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 2008/04/08 07:23:04 UTC
svn commit: r645765 - in /perl/embperl/trunk/Embperl/Form/Control:
datetime.pm duration.pm hidden.pm
Author: richter
Date: Mon Apr 7 22:23:01 2008
New Revision: 645765
URL: http://svn.apache.org/viewvc?rev=645765&view=rev
Log:
Date/Time controls
Added:
perl/embperl/trunk/Embperl/Form/Control/datetime.pm
perl/embperl/trunk/Embperl/Form/Control/duration.pm
Modified:
perl/embperl/trunk/Embperl/Form/Control/hidden.pm
Added: perl/embperl/trunk/Embperl/Form/Control/datetime.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/datetime.pm?rev=645765&view=auto
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/datetime.pm (added)
+++ perl/embperl/trunk/Embperl/Form/Control/datetime.pm Mon Apr 7 22:23:01 2008
@@ -0,0 +1,240 @@
+
+###################################################################################
+#
+# 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::datetime ;
+
+use strict ;
+use base 'Embperl::Form::Control::number' ;
+
+use Embperl::Inline ;
+use POSIX qw(strftime);
+use Time::Local qw(timelocal_nocheck timegm_nocheck);
+use Date::Calc qw{Delta_DHMS Add_Delta_Days} ;
+
+use vars qw{%fdat} ;
+
+our $tz_local = (timegm_nocheck(localtime())-time())/60;
+
+
+# ---------------------------------------------------------------------------
+#
+# 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 $name = $self->{name} ;
+ my $time = $fdat{$name} ;
+ return if ($time eq '') ;
+
+ my ($y, $m, $d, $h, $min, $s, $z) = ($time =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(.)/) ;
+
+ # Getting the local timezone
+
+ my $date = eval
+ {
+ my @time = gmtime(timegm_nocheck($s,$min,$h,$d,$m-1,$y-1900)+($tz_local*60));
+
+ my $format = $s == 0 && $h == 0 && $min == 0?'%d.%m.%Y':'%d.%m.%Y, %H:%M' ;
+ strftime ($format, @time[0..5]) ;
+ } ;
+
+ $fdat{$name} = $date ;
+ }
+
+# ------------------------------------------------------------------------------------------
+#
+# prepare_fdat - daten zusammenfuehren
+#
+
+sub prepare_fdat
+ {
+ my ($self, $req) = @_ ;
+
+ my $name = $self->{name} ;
+ my $date = $fdat{$name} ;
+ return if ($date eq '') ;
+
+ my ($year, $mon, $day, $hour, $min, $sec) ;
+ if ($date eq '*' || $date eq '.')
+ {
+ my $offset ||= 0 ;
+ ($sec, $min, $hour, $day, $mon, $year) = gmtime (time + $offset) ;
+ $year += 1900 ;
+ $mon++ ;
+ }
+ else
+ {
+ my ($d, $t) = split (/\s+/, $date) ;
+ if ($d =~ /:/)
+ {
+ $t = $d ;
+ $d = '' ;
+ }
+ ($day, $mon, $year) = map { $_ + 0 } split (/\./, $d) ;
+ ($hour, $min, $sec) = map { $_ + 0 } split (/\:/, $t) ;
+
+ if ($year == 0 || $mon == 0 || $day == 0)
+ {
+ my ($s, $min, $h, $md, $m, $y) = localtime ;
+
+ $day ||= $md ;
+ $mon ||= $m + 1;
+ $year ||= $y + 1900 ;
+ }
+
+ if ($year < 70)
+ {
+ $year += 2000 ;
+ }
+ elsif ($year >= 70 && $year < 100)
+ {
+ $year += 1900 ;
+ }
+ if ($year < 1907)
+ {
+ $year = $year % 100 + 2000 ;
+ }
+
+ ($year,$mon,$day, $hour,$min,$sec) =
+ Date::Calc::Add_Delta_DHMS($year,$mon,$day, $hour,$min,$sec,
+ 0, 0, -$tz_local, 0) if ($hour || $min || $sec) ;
+ }
+
+ $fdat{$name} = $year?sprintf ('%04d%02d%02d%02d%02d%02dZ', $year, $mon, $day, $hour, $min, $sec):'' ;
+
+print STDERR "datetime: $date -> $year, $mon, $day $hour:$min:$sec\n" ;
+ }
+
+1 ;
+
+__EMBPERL__
+
+
+[# ---------------------------------------------------------------------------
+#
+# show_control - output the control
+#]
+
+[$ sub show_control ($self)
+
+$self -> {size} ||= 80 / ($self -> {width} || 2) ;
+my $class = $self -> {class} ||= 'cControlWidthInput' ;
+my $nsprefix = $self -> form -> {jsnamespace} ;
+$]
+
+<input type="text" class="cBase cControl [+ $class +]" name="[+ $self->{name} +]" id="[+ $self->{id} +]"
+[$if $self -> {size} $]size="[+ $self->{size} +]"[$endif$]
+[$if $self -> {maxlength} $]maxlength="[+ $self->{maxlength} +]"[$endif$]
+>
+<script type="text/javascript">
+ [+ $nsprefix +]Calendar.setup(
+ {
+ inputField : document.getElementById('[+ $self -> {id} +]'), // ID of the input field
+ ifFormat : "%d.%m.%Y", // the date format
+ //button : "trigger" // ID of the button
+ }
+ );
+</script>
+
+
+
+[$endsub$]
+
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Embperl::Form::Control::price - A price input control with optional unit inside an Embperl Form
+
+
+=head1 SYNOPSIS
+
+ {
+ type => 'price',
+ text => 'blabla',
+ name => 'foo',
+ unit => 'sec',
+ }
+
+=head1 DESCRIPTION
+
+Used to create a price input control inside an Embperl Form.
+Will format number as a money ammout.
+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 'price'
+
+=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.
+(Default: )
+
+=head3 use_comma
+
+If set the decimal character is comma instead of point (Default: on)
+
+=head1 Author
+
+G. Richter (richter@dev.ecos.de)
+
+=head1 See Also
+
+perl(1), Embperl, Embperl::Form
+
+
Added: perl/embperl/trunk/Embperl/Form/Control/duration.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/duration.pm?rev=645765&view=auto
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/duration.pm (added)
+++ perl/embperl/trunk/Embperl/Form/Control/duration.pm Mon Apr 7 22:23:01 2008
@@ -0,0 +1,162 @@
+
+###################################################################################
+#
+# 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::duration ;
+
+use strict ;
+use base 'Embperl::Form::Control::number' ;
+
+use Embperl::Inline ;
+
+use vars qw{%fdat} ;
+
+# ---------------------------------------------------------------------------
+#
+# init - init the new control
+#
+
+sub init
+
+ {
+ my ($self) = @_ ;
+print STDERR "durx1\n" ;
+ $self->{unit} ||= '' ;
+
+ return $self ;
+ }
+
+# ------------------------------------------------------------------------------------------
+#
+# init_data - daten aufteilen
+#
+
+sub init_data
+ {
+ my ($self, $req, $parentctrl) = @_ ;
+
+print STDERR "durx2\n" ;
+ my $name = $self->{name} ;
+ my $val = $fdat{$name} ;
+ return if ($val eq '') ;
+
+ my $sec = $val % 60 ;
+ my $min = (int ($val / 60) % 60) ;
+ my $hour = int($val / 3600) ;
+
+ my $duration = $hour?sprintf('%d:%02d', $hour, $min):$min ;
+ if ($sec != 0)
+ {
+ $duration .= sprintf (':%02d', $sec) ;
+ }
+ $fdat{$name} = $duration ;
+
+print STDERR "duration init: $fdat{$name}\n" ;
+ }
+
+# ------------------------------------------------------------------------------------------
+#
+# prepare_fdat - daten zusammenfuehren
+#
+
+sub prepare_fdat
+ {
+ my ($self, $req) = @_ ;
+
+print STDERR "durx3\n" ;
+ my $name = $self->{name} ;
+ my $val = $fdat{$name} ;
+ return if ($val eq '') ;
+
+ my @vals = split (/:/, $val, 3) ;
+
+
+
+ $fdat{$name} = @vals == 1?$vals[0] * 60:$vals[0] * 3600 + $vals[1] * 60 + $vals[2] ;
+
+print STDERR "duration: (@vals) val = $fdat{$name}\n" ;
+
+ }
+
+1 ;
+
+__EMBPERL__
+
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Embperl::Form::Control::price - A price input control with optional unit inside an Embperl Form
+
+
+=head1 SYNOPSIS
+
+ {
+ type => 'price',
+ text => 'blabla',
+ name => 'foo',
+ unit => 'sec',
+ }
+
+=head1 DESCRIPTION
+
+Used to create a price input control inside an Embperl Form.
+Will format number as a money ammout.
+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 'price'
+
+=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.
+(Default: )
+
+=head3 use_comma
+
+If set the decimal character is comma instead of point (Default: on)
+
+=head1 Author
+
+G. Richter (richter@dev.ecos.de)
+
+=head1 See Also
+
+perl(1), Embperl, Embperl::Form
+
+
Modified: perl/embperl/trunk/Embperl/Form/Control/hidden.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/hidden.pm?rev=645765&r1=645764&r2=645765&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/hidden.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/hidden.pm Mon Apr 7 22:23:01 2008
@@ -81,6 +81,10 @@
Will be used as name for the hidden input field.
+=head3 value
+
+Value for the hidden field.
+
=head1 Author
G. Richter (richter@dev.ecos.de), A. Beckert (beckert@ecos.de)
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-cvs-help@perl.apache.org