2
###################################################################################
4
# Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5
# Embperl - Copyright (c) 2008-2012 Gerald Richter
7
# You may distribute under the terms of either the GNU General Public
8
# License or the Artistic License, as specified in the Perl README file.
10
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
###################################################################################
18
package Embperl::Form::Control::duration ;
21
use base 'Embperl::Form::Control::number' ;
27
# ---------------------------------------------------------------------------
29
# init - init the new control
37
$self->{unit} ||= '' ;
42
# ------------------------------------------------------------------------------------------
44
# init_data - daten aufteilen
49
my ($self, $req, $parentctrl) = @_ ;
51
my $fdat = $req -> {docdata} || \%fdat ;
52
my $name = $self->{name} ;
53
my $val = $fdat->{$name} ;
54
return if ($val eq '') ;
56
my $aval = abs ($val) ;
57
my $sec = $aval % 60 ;
58
my $min = int ($aval / 60) % 60 ;
59
my $hour = int($aval / 3600) ;
61
my $duration = ($val<0?'-':'') . ($hour?sprintf('%d:%02d', $hour, $min):$min) ;
64
$duration .= sprintf (':%02d', $sec) ;
66
$fdat->{$name} = $duration ;
69
# ------------------------------------------------------------------------------------------
71
# prepare_fdat - daten zusammenfuehren
76
my ($self, $req) = @_ ;
78
my $fdat = $req -> {form} || \%fdat ;
79
my $name = $self->{name} ;
80
my $val = $fdat->{$name} ;
81
return if ($val eq '') ;
84
$neg = 1 if ($val =~ s/^\s*-//) ;
85
my @vals = split (/:/, $val, 3) ;
89
$fdat->{$name} = @vals == 1?$vals[0] * 60:$vals[0] * 3600 + $vals[1] * 60 + $vals[2] ;
90
$fdat->{$name} = - $fdat{$name} if ($neg) ;
104
Embperl::Form::Control::price - A price input control with optional unit inside an Embperl Form
118
Used to create a price input control inside an Embperl Form.
119
Will format number as a money ammout.
120
Optionaly it can display an unit after the input field.
121
See Embperl::Form on how to specify parameters.
131
Specifies the name of the control
135
Will be used as label for the numeric input control
139
Gives the size in characters. (Default: 10)
143
Gives the maximun length in characters
147
Gives a string that should be displayed right of the input field.
152
If set the decimal character is comma instead of point (Default: on)
156
G. Richter (richter at embperl dot org)
160
perl(1), Embperl, Embperl::Form