--- trunk/lib/Frey/Action.pm 2008/11/18 02:15:11 399 +++ trunk/lib/Frey/Action.pm 2008/11/30 16:22:45 645 @@ -38,11 +38,13 @@ $self->load_class( $self->class ); my @required = grep { - defined $_ && $_->can('name') && !defined( $self->params->{ $_->name } ) + defined $_ && $_->can('name') && + ! defined( $self->params->{ $_->name } ) && + ! $_->is_lazy } map { my $attr = $self->class->meta->get_attribute($_); - $attr->is_required && $attr; + blessed $attr && $attr->is_required && $attr; } $self->class->meta->get_attribute_list; warn "## required = ",dump( map { $_->name } @required ), " for ", $self->class if @required && $self->debug; @@ -82,7 +84,7 @@ my ( $self ) = @_; my @required = $self->required; if ( ! @required ) { - warn "all params available ", dump( $self->params ), " not creating form"; + warn "all params available ", dump( $self->params ), " not creating form" if $self->debug; return (undef,$self->params) if wantarray; return; } else { @@ -101,54 +103,91 @@ my $form; - foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) { - my $attr_type; + sub select_values { + my ( $name, $attr_type, $values ) = @_; + my $options = join("\n", + map { + my $v = ref($_) eq 'HASH' ? $_->{$name} : $_; + qq|| if $v; + } @$values + ); + qq|| if $options; + } + + 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; + + foreach my $name ( + grep { + ! $class->meta->get_attribute($_)->is_lazy + && ! defined $default->{$_} + } $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; + + my $value = + defined $default->{$name} ? $default->{$name} : + $attr->has_default ? $attr->default( $name ) : + ''; + if ( ref($config_params) eq 'HASH' ) { $value = $config_params->{$name}; } elsif ( ref($config_params) eq 'ARRAY' ) { - $value_html = qq||; + $value_html = select_values( $name, $attr_type, $config_params ); $default->{$name} = $config_params->[0]->{$name}; - } elsif ( my $attr = $class->meta->get_attribute( $name ) ) { - if ( $attr->has_type_constraint ) { - $attr_type = $attr->type_constraint->name; - if ( $attr->type_constraint->can('values') ) { - $value_html = qq||; - } elsif ( $attr_type !~ m{^(Str|Int)$} ) { - $value_html = qq||; - } - } - $value = $attr->default( $name ) if ! $value && $attr->has_default; - $label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation; - } else { - warn "wired attribute $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{^Bool} ) { + my $suffix = ''; + $suffix = ' checked' if $value; + $value_html = qq||; + push @checkboxes, $name; + } elsif ( $attr_type !~ m{^(Str|Int)$} ) { + $value_html = qq||; } - - $value_html = qq|| unless $value_html; + + $label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation; $default->{$name} = $value unless defined $default->{$name}; + $value_html = qq|| unless $value_html; + # warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 ); $form .= qq|| . $value_html; } - my $html = qq|

$class params

$form
|; - push @{ $self->status }, { 'Params' => - { - 'Config' => $config_params, - 'Default' => $default + $form .= qq|| if @checkboxes; + + my $html; + + $html = qq| +

$class params

+
+ $form + +
+ | if $form; + + $self->add_status({ + $self->class => { + params => $self->params, + config_params => $config_params, + default => $default }, - }; + }); return ($html,$default) if wantarray; return $html;