/[Frey]/trunk/lib/Frey/Action.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Action.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 715 by dpavlin, Thu Dec 4 17:33:39 2008 UTC revision 731 by dpavlin, Sat Dec 6 00:25:19 2008 UTC
# Line 36  has 'params' => ( Line 36  has 'params' => (
36  sub required {  sub required {
37          my ( $self ) = @_;          my ( $self ) = @_;
38          $self->load_class( $self->class );          $self->load_class( $self->class );
39    
40          my @required =          my @required =
41                  grep {                  grep {
42                          defined $_ && $_->can('name') &&                          defined $_ && $_->can('name') &&
# Line 97  sub params_form { Line 98  sub params_form {
98    
99          my $default = clone $self->params; # XXX we really don't want to modify params!          my $default = clone $self->params; # XXX we really don't want to modify params!
100    
101          my $config_params = {};          my $params_config = {};
102          $config_params = $self->config($class);          $params_config = $self->config($class);
103          warn "# $class config = ",dump( $config_params ) if $self->debug;          warn "# $class config = ",dump( $params_config ) if $self->debug;
104    
105          my $form;          my $form;
106    
# Line 124  sub params_form { Line 125  sub params_form {
125    
126          my @checkboxes;          my @checkboxes;
127    
128            my $skip_prefix;
129            if ( $self->class->can('action') ) {
130                    my $action = eval $self->class . '->action';
131                    $skip_prefix->{$_}++ foreach eval $self->class .'->action_order';
132                    warn "# skip_prefix = ", $self->dump( $skip_prefix );
133            }
134    
135            my $label_width = 1; # minimum
136    
137          foreach my $name (          foreach my $name (
138                  grep {                  grep {
139                          ! $class->meta->get_attribute($_)->is_lazy                          ! $class->meta->get_attribute($_)->is_lazy
# Line 145  sub params_form { Line 155  sub params_form {
155                          $attr->has_default        ? $attr->default( $name ) :                          $attr->has_default        ? $attr->default( $name ) :
156                          '';                          '';
157    
158                  if ( ref($config_params) eq 'HASH' ) {                  if ( ref($params_config) eq 'HASH' ) {
159                          $value = $config_params->{$name};                          $value = $params_config->{$name};
160                  } elsif ( ref($config_params) eq 'ARRAY' ) {                  } elsif ( ref($params_config) eq 'ARRAY' ) {
161                          $value_html = select_values( $name, $attr_type, $config_params );                          $value_html = select_values( $name, $attr_type, $params_config );
162                          $default->{$name} = $config_params->[0]->{$name};                          $default->{$name} = $params_config->[0]->{$name};
163                  } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {                  } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
164                                  $value_html = select_values( $name, $attr_type, $attr->type_constraint->values );                          $value_html = select_values( $name, $attr_type, $attr->type_constraint->values );
165                  } elsif ( $attr_type =~ m{^Bool} ) {                  } elsif ( $attr_type =~ m{^Bool} ) {
166                                  my $suffix = '';                          my $suffix = '';
167                                  $suffix = ' checked' if $value;                          $suffix = ' checked' if $value;
168                                  $value_html = qq|<input type="checkbox" name="$name" title="$attr_type" value="$value"$suffix>|;                          $value_html = qq|<input type="checkbox" name="$name" title="$attr_type" value="$value"$suffix>|;
169                                  push @checkboxes, $name;                          push @checkboxes, $name;
170                    } elsif ( ! defined $value ) {
171                            $value_html = qq|<tt id="$name">undef</tt><!-- $name = undef -->|; # FIXME if $self->debug
172                  } elsif ( $attr_type !~ m{^(Str|Int)$} || $value =~ $Frey::Web::re_html ) {                  } elsif ( $attr_type !~ m{^(Str|Int)$} || $value =~ $Frey::Web::re_html ) {
173                                  $value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|;                          $value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|;
174                  }                  }
175                    
176                  $label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation;                  $label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation;
177    
178                  $default->{$name} = $value unless defined $default->{$name};                  $default->{$name} = $value unless defined $default->{$name};
# Line 168  sub params_form { Line 180  sub params_form {
180                  $value_html = qq|<input type="$type" name="$name" title="$attr_type" value="$value">| unless $value_html;                  $value_html = qq|<input type="$type" name="$name" title="$attr_type" value="$value">| unless $value_html;
181    
182  #               warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );  #               warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 );
183                  $form .= qq|<label for="$name"$label_title>$label</label>| . $value_html;                  $form .= qq|<label for="$name"$label_title>$label</label>$value_html<br>|;
184                    my $ll = length($label);
185                    $label_width = $ll if $ll > $label_width;
186          }          }
187          $form .= qq|<input type="hidden" name="frey-checkboxes" value="| . join(' ', @checkboxes) . qq|">| if @checkboxes;          $form .= qq|<input type="hidden" name="frey-checkboxes" value="| . join(' ', @checkboxes) . qq|">| if @checkboxes;
188    
189            $self->add_css(qq|
190                    label,input {
191                            display: block;
192                            float: left;
193                            margin-bottom: 10px;
194                    }
195    
196                    label {
197                            text-align: right;
198                            width: ${label_width}ex;
199                            padding-right: 20px;
200                    }
201    
202                    br {
203                            clear: left;
204                    }
205            |);
206    
207          my $html;          my $html;
208    
209            $form =~ s{<([^>]+)(name=")([^"]+)(")([^>]*)>}
210                    {<$1$2$3$4 id="$3" $5}gs; # http://www.quirksmode.org/oddsandends/forms.html
211    
212          $html = qq|          $html = qq|
213                  <h1>$class params</h1>                  <h1>$class params</h1>
214                  <form method="post">                  <form method="post">
# Line 185  sub params_form { Line 220  sub params_form {
220          $self->add_status({          $self->add_status({
221                  $self->class => {                  $self->class => {
222                          params  => $self->params,                          params  => $self->params,
223                          config_params  => $config_params,                          params_config  => $params_config,
224                          default => $default                          default => $default,
225                  },                  },
226          });          });
227    
# Line 194  sub params_form { Line 229  sub params_form {
229          return $html;          return $html;
230  }  }
231    
232    =head1 SEE ALSO
233    
234    L<http://www.quirksmode.org/css/forms.html> for info on CSS2 forms
235    
236    =cut
237    
238  1;  1;

Legend:
Removed from v.715  
changed lines
  Added in v.731

  ViewVC Help
Powered by ViewVC 1.1.26