/[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 480 by dpavlin, Thu Nov 20 14:39:43 2008 UTC revision 504 by dpavlin, Mon Nov 24 22:08:10 2008 UTC
# Line 103  sub params_form { Line 103  sub params_form {
103    
104          my $form;          my $form;
105    
106            sub select_values {
107                    my ( $name, $attr_type, $values ) = @_;
108                    my $options = join("\n",
109                            map {
110                                    my $v = ref($_) eq 'HASH' ? $_->{$name} : $_;
111                                    qq|<option value="$v">$v</option>| if $v;
112                            } @$values
113                    );
114                    qq|<select title="$attr_type" name="$name">$options</select>| if $options;
115            }
116    
117          foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) {          foreach my $name ( grep { ! $class->meta->get_attribute($_)->is_lazy } $self->attributes ) {
118                  my $attr_type = '';                  my $attr_type = '';
119                  my $type = $name =~ m/^pass/ ? 'password' : 'text';                  my $type = $name =~ m/^pass/ ? 'password' : 'text';
# Line 110  sub params_form { Line 121  sub params_form {
121                  my $value = '';                  my $value = '';
122                  my $label_title = '';                  my $label_title = '';
123                  my $value_html = '';                  my $value_html = '';
124    
125                    my $attr = $class->meta->get_attribute( $name );
126                    $attr_type = $attr->type_constraint->name if $attr->has_type_constraint;
127    
128                  if ( ref($config_params) eq 'HASH' ) {                  if ( ref($config_params) eq 'HASH' ) {
129                          $value = $config_params->{$name};                          $value = $config_params->{$name};
130                  } elsif ( ref($config_params) eq 'ARRAY' ) {                  } elsif ( ref($config_params) eq 'ARRAY' ) {
131                          $value_html = qq|<select name="$name">| . join("\n",                          $value_html = select_values( $name, $attr_type, $config_params );
                                 map {  
                                         my $v = $_->{$name};  
                                         qq|<option value="$v">$v</option>|  
                                 } @$config_params  
                         ) . qq|</select>|;  
132                          $default->{$name} = $config_params->[0]->{$name};                          $default->{$name} = $config_params->[0]->{$name};
133                  } elsif ( my $attr = $class->meta->get_attribute( $name ) ) {                  } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) {
134                          if ( $attr->has_type_constraint ) {                                  $value_html = select_values( $name, $attr_type, $attr->type_constraint->values );
135                                  $attr_type = $attr->type_constraint->name;                  } elsif ( $attr_type !~ m{^(Str|Int)$} ) {
136                                  if ( $attr->type_constraint->can('values') ) {                                  $value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|;
                                         $value_html = qq|<select name="$name">| . join("\n",  
                                                 map { qq|<option value="$_">$_</option>| } @{ $attr->type_constraint->values }  
                                         ) . qq|</select>|;  
                                 } elsif ( $attr_type !~ m{^(Str|Int)$} ) {  
                                         $value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|;  
                                 }  
                         }  
                         $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";  
137                  }                  }
138                    $value = $attr->default( $name ) if ! $value && $attr->has_default;
139                    $label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation;
140    
141                  $default->{$name} = $value unless defined $default->{$name};                  $default->{$name} = $value unless defined $default->{$name};
142    

Legend:
Removed from v.480  
changed lines
  Added in v.504

  ViewVC Help
Powered by ViewVC 1.1.26