Author: richter
Date: Fri Dec 9 15:11:57 2005
New Revision: 355636
URL: http://svn.apache.org/viewcvs?rev=355636&view=rev
Log:
Embperl::Form updates
Modified:
perl/embperl/trunk/Embperl/Form.pm
perl/embperl/trunk/Embperl/Form/Control.pm
perl/embperl/trunk/Embperl/Form/Control/input.pm
perl/embperl/trunk/Embperl/Form/Control/number.pm
perl/embperl/trunk/Embperl/Form/Control/password.pm
Modified: perl/embperl/trunk/Embperl/Form.pm
URL:
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Form.pm?rev=355636&r1=355635&r2=355636&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form.pm (original)
+++ perl/embperl/trunk/Embperl/Form.pm Fri Dec 9 15:11:57 2005
@@ -42,11 +42,11 @@
sub new
{
- my ($class, $controls, $id, $validate_rules, $parentid) = @_ ;
+ my ($class, $controls, $options, $id, $validate_rules, $parentid) = @_ ;
my $toplevel = $validate_rules?0:1 ;
$id ||= 'topdiv' ;
-
+ $options ||= {} ;
my $self = ref $class?$class:{} ;
@@ -66,7 +66,7 @@
$validate_rules = $self -> {validate_rules} = [] ;
}
- $self -> new_controls ($controls, undef, $id, $validate_rules) ;
+ $self -> new_controls ($controls, $options, undef, $id, $validate_rules,
$options -> {masks}, $options -> {defaults}) ;
$self -> {noframe} = 1 if ($controls && @$controls > 0 &&
$controls -> [0] -> noframe) ;
@@ -116,18 +116,37 @@
sub new_controls
{
- my ($self, $controls, $id, $formid, $validate_rules) = @_ ;
+ my ($self, $controls, $options, $id, $formid, $validate_rules, $mask,
$default) = @_ ;
my $n = 0 ;
my $packages = $self -> get_control_packages ;
foreach my $control (@$controls)
{
+ my $name = $control -> {name} ;
$control -> {type} =~ s/sf_select.+/select/ ;
$control -> {parentid} = $id if ($id) ;
$control -> {id} ||= "$control->{name}-$n" ;
$control -> {formid} = $formid ;
+ my $default = $defaults -> {$name} || $defaults -> {$type} ;
+ my $mask = $masks -> {$name} || $masks -> {$type} ;
+ if ($mask)
+ {
+ foreach (keys %$mask)
+ {
+ $control -> {$_} = $mask -> {$_} ;
+ }
+ }
+ if ($default)
+ {
+ foreach (keys %$default)
+ {
+ $control -> {$_} = $default -> {$_} if (!exists $control ->
{$_}) ;
+ }
+ }
+
+
if (ref $control eq 'HASH')
{
my $ctlmod ;
@@ -171,9 +190,10 @@
}
}
die "No Module found for type = $type, searched: @$packages" if
(!$ctlmod) ;
-
- push @{$validate_rules}, $control -> get_validate_rules ;
}
+
+ next if ($control -> is_disabled) ;
+ push @{$validate_rules}, $control -> get_validate_rules ;
if ($control -> {sublines})
{
my $i = 0 ;
@@ -181,7 +201,7 @@
foreach my $subcontrols (@{$control -> {sublines}})
{
next if (!$subcontrols) ;
- $self -> new_controls ($subcontrols, "$name-$i", $formid,
$validate_rules) ;
+ $self -> new_controls ($subcontrols, $options, "$name-$i",
$formid, $validate_rules, $mask, $default) ;
$i++ ;
}
}
@@ -196,7 +216,7 @@
next if (!$subcontrols) ;
my $id = "$control->{name}-$i" ;
my $class = ref $self ;
- my $subform = $class -> new ($subcontrols, $id,
$validate_rules, $self -> {id}) ;
+ my $subform = $class -> new ($subcontrols, $options, $id,
$validate_rules, $self -> {id}) ;
push @ids, $id ;
push @obj, $subform ;
$i++ ;
Modified: perl/embperl/trunk/Embperl/Form/Control.pm
URL:
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Form/Control.pm?rev=355636&r1=355635&r2=355636&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control.pm Fri Dec 9 15:11:57 2005
@@ -48,6 +48,35 @@
return ;
}
+# ---------------------------------------------------------------------------
+#
+# is_disabled - do not display this control at all
+#
+
+
+sub is_disabled
+
+ {
+ my ($self) = @_ ;
+
+ return $self -> {disable} ;
+ }
+
+# ---------------------------------------------------------------------------
+#
+# is_readonly - could value of this control be changed ?
+#
+
+
+sub is_readonly
+
+ {
+ my ($self) = @_ ;
+
+ return $self -> {readonly} ;
+ }
+
+
# ---------------------------------------------------------------------------
#
@@ -59,6 +88,7 @@
{
my ($self, $data) = @_ ;
+ $fdat{$self -> {name}} = $self -> {default} if ($fdat{$self -> {name}} eq
'' && exists ($self -> {default}))
my $span = 0 ;
$span += $self -> show_label_cell ($span);
return $self -> show_control_cell ($span, $data) ;
@@ -191,15 +221,22 @@
[# ---------------------------------------------------------------------------
#
-# show - output the control
+# show_control - output the control
#]
[$ sub show_control ($self) $][+ $self->{value} +][$endsub$]
+[# ---------------------------------------------------------------------------
+#
+# show_control_readonly - output the control as readonly
+#]
+
+[$ sub show_control_readonly ($self) $][+ $self -> {value} || $fdat{$self ->
{name}} +][$endsub$]
+
[# ---------------------------------------------------------------------------
#
-# show - output the control
+# show_controll_cell - output the table cell for the control
#]
[$ sub show_control_cell ($self, $x)
@@ -207,7 +244,7 @@
my $span = $self->{width_percent} - $x ;
$]
<td class="cControlBox" colspan="[+ $span +]">
- [* my @ret = $self -> show_control ; *]
+ [* my @ret = $self -> is_readonly?$self -> show_control_readonly:$self ->
show_control ; *]
</td>
[* return @ret ; *]
[$endsub$]
@@ -241,6 +278,14 @@
Do not draw frame border if this is the only control
+=head2 is_disabled
+
+Do not display this control at all.
+
+=head2 is_readonly
+
+Could value of this control be changed ?
+
=head2 show
output the control
@@ -288,6 +333,15 @@
=head1 PARAMETERS
+=head3 name
+
+Specifies the name of the control
+
+=head3 text
+
+Will be used as label for the control, if not given
+name is used as default
+
=head2 labelnowrap
If set, the text label will not be line wrapped.
@@ -296,7 +350,25 @@
If set, will be used as additional CSS classes for the label text cell.
+=head2 readonly
+
+If set, displays a readonly version of t control.
+
+=head2 disable
+
+If set, the control will not be displayed at all.
+
+=head2 newline
+
+If set to 1, forces a new line before the control.
+If set to -1, forces a new line after the control.
+
+=head2 width
+Gives the widths of the control. The value is 1/width
+of the the whole width of the form. So if you want to
+have four controls in one line set width to 4. The default value
+is 2.
=head1 AUTHOR
Modified: perl/embperl/trunk/Embperl/Form/Control/input.pm
URL:
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Form/Control/input.pm?rev=355636&r1=355635&r2=355636&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/input.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/input.pm Fri Dec 9 15:11:57 2005
@@ -70,6 +70,10 @@
Needs to be 'input'
+=head3 name
+
+Specifies the name of the control
+
=head3 text
Will be used as label for the text input control
Modified: perl/embperl/trunk/Embperl/Form/Control/number.pm
URL:
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Form/Control/number.pm?rev=355636&r1=355635&r2=355636&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/number.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/number.pm Fri Dec 9 15:11:57 2005
@@ -68,6 +68,10 @@
Needs to be 'number'
+=head3 name
+
+Specifies the name of the control
+
=head3 text
Will be used as label for the numeric input control
Modified: perl/embperl/trunk/Embperl/Form/Control/password.pm
URL:
http://svn.apache.org/viewcvs/perl/embperl/trunk/Embperl/Form/Control/password.pm?rev=355636&r1=355635&r2=355636&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/password.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/password.pm Fri Dec 9 15:11:57 2005
@@ -67,6 +67,10 @@
Needs to be 'password'
+=head3 name
+
+Specifies the name of the control
+
=head3 text
Will be used as label for the text input control
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]