--- trunk/lib/Frey/Action.pm 2008/11/28 17:18:56 595
+++ trunk/lib/Frey/Action.pm 2008/12/06 00:25:19 731
@@ -36,6 +36,7 @@
sub required {
my ( $self ) = @_;
$self->load_class( $self->class );
+
my @required =
grep {
defined $_ && $_->can('name') &&
@@ -97,9 +98,9 @@
my $default = clone $self->params; # XXX we really don't want to modify params!
- my $config_params = {};
- $config_params = $self->config($class);
- warn "# $class config = ",dump( $config_params ) if $self->debug;
+ my $params_config = {};
+ $params_config = $self->config($class);
+ warn "# $class config = ",dump( $params_config ) if $self->debug;
my $form;
@@ -114,52 +115,113 @@
qq|| if $options;
}
- foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) {
+ foreach my $checkbox ( split(/\s+/, $default->{'frey-checkboxes'} ) ) {
+ next if defined $default->{ $checkbox };
+
+ $default->{ $checkbox } = 0;
+ $self->params->{ $checkbox } = 0;
+ warn "# checkbox $checkbox not ticked";
+ }
+
+ my @checkboxes;
+
+ my $skip_prefix;
+ if ( $self->class->can('action') ) {
+ my $action = eval $self->class . '->action';
+ $skip_prefix->{$_}++ foreach eval $self->class .'->action_order';
+ warn "# skip_prefix = ", $self->dump( $skip_prefix );
+ }
+
+ my $label_width = 1; # minimum
+
+ foreach my $name (
+ grep {
+ ! $class->meta->get_attribute($_)->is_lazy
+ && ! defined $default->{$_}
+ && ! m{^_} # skip _private
+ } $self->attributes
+ ) {
my $attr_type = '';
my $type = $name =~ m/^pass/ ? 'password' : 'text';
my $label = $name;
- my $value = '';
my $label_title = '';
my $value_html = '';
my $attr = $class->meta->get_attribute( $name );
$attr_type = $attr->type_constraint->name if $attr->has_type_constraint;
- $value = $attr->default( $name ) if ! $value && $attr->has_default;
-
- if ( ref($config_params) eq 'HASH' ) {
- $value = $config_params->{$name};
- } elsif ( ref($config_params) eq 'ARRAY' ) {
- $value_html = select_values( $name, $attr_type, $config_params );
- $default->{$name} = $config_params->[0]->{$name};
+ my $value =
+ defined $default->{$name} ? $default->{$name} :
+ $attr->has_default ? $attr->default( $name ) :
+ '';
+
+ if ( ref($params_config) eq 'HASH' ) {
+ $value = $params_config->{$name};
+ } elsif ( ref($params_config) eq 'ARRAY' ) {
+ $value_html = select_values( $name, $attr_type, $params_config );
+ $default->{$name} = $params_config->[0]->{$name};
} elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
- $value_html = select_values( $name, $attr_type, $attr->type_constraint->values );
- } elsif ( $attr_type !~ m{^(Str|Int)$} ) {
- $value_html = qq||;
+ $value_html = select_values( $name, $attr_type, $attr->type_constraint->values );
+ } elsif ( $attr_type =~ m{^Bool} ) {
+ my $suffix = '';
+ $suffix = ' checked' if $value;
+ $value_html = qq||;
+ push @checkboxes, $name;
+ } elsif ( ! defined $value ) {
+ $value_html = qq|undef|; # FIXME if $self->debug
+ } elsif ( $attr_type !~ m{^(Str|Int)$} || $value =~ $Frey::Web::re_html ) {
+ $value_html = qq||;
}
-
+
$label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation;
$default->{$name} = $value unless defined $default->{$name};
- if ( ! $value_html ) {
- my $suffix = '';
- if ( $attr_type =~ m{^Bool$} ) {
- $type = 'checkbox';
- $suffix = ' checked' if $value;
- }
- $value_html = qq||;
- }
+ $value_html = qq|| unless $value_html;
# warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );
- $form .= qq|| . $value_html;
+ $form .= qq|$value_html
|;
+ my $ll = length($label);
+ $label_width = $ll if $ll > $label_width;
}
- my $html = qq|