114 |
qq|<select title="$attr_type" name="$name">$options</select>| if $options; |
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 $checkbox ( split(/\s+/, $default->{'frey-checkboxes'} ) ) { |
118 |
|
next if defined $default->{ $checkbox }; |
119 |
|
|
120 |
|
$default->{ $checkbox } = 0; |
121 |
|
$self->params->{ $checkbox } = 0; |
122 |
|
warn "# checkbox $checkbox not ticked"; |
123 |
|
} |
124 |
|
|
125 |
|
my @checkboxes; |
126 |
|
|
127 |
|
foreach my $name ( |
128 |
|
grep { |
129 |
|
! $class->meta->get_attribute($_)->is_lazy |
130 |
|
&& ! defined $default->{$_} |
131 |
|
} $self->attributes |
132 |
|
) { |
133 |
my $attr_type = ''; |
my $attr_type = ''; |
134 |
my $type = $name =~ m/^pass/ ? 'password' : 'text'; |
my $type = $name =~ m/^pass/ ? 'password' : 'text'; |
135 |
my $label = $name; |
my $label = $name; |
|
my $value = ''; |
|
136 |
my $label_title = ''; |
my $label_title = ''; |
137 |
my $value_html = ''; |
my $value_html = ''; |
138 |
|
|
139 |
my $attr = $class->meta->get_attribute( $name ); |
my $attr = $class->meta->get_attribute( $name ); |
140 |
$attr_type = $attr->type_constraint->name if $attr->has_type_constraint; |
$attr_type = $attr->type_constraint->name if $attr->has_type_constraint; |
141 |
|
|
142 |
|
my $value = |
143 |
|
defined $default->{$name} ? $default->{$name} : |
144 |
|
$attr->has_default ? $attr->default( $name ) : |
145 |
|
''; |
146 |
|
|
147 |
if ( ref($config_params) eq 'HASH' ) { |
if ( ref($config_params) eq 'HASH' ) { |
148 |
$value = $config_params->{$name}; |
$value = $config_params->{$name}; |
149 |
} elsif ( ref($config_params) eq 'ARRAY' ) { |
} elsif ( ref($config_params) eq 'ARRAY' ) { |
151 |
$default->{$name} = $config_params->[0]->{$name}; |
$default->{$name} = $config_params->[0]->{$name}; |
152 |
} elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) { |
} elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) { |
153 |
$value_html = select_values( $name, $attr_type, $attr->type_constraint->values ); |
$value_html = select_values( $name, $attr_type, $attr->type_constraint->values ); |
154 |
|
} elsif ( $attr_type =~ m{^Bool} ) { |
155 |
|
my $suffix = ''; |
156 |
|
$suffix = ' checked' if $value; |
157 |
|
$value_html = qq|<input type="checkbox" name="$name" title="$attr_type" value="$value"$suffix>|; |
158 |
|
push @checkboxes, $name; |
159 |
} elsif ( $attr_type !~ m{^(Str|Int)$} ) { |
} elsif ( $attr_type !~ m{^(Str|Int)$} ) { |
160 |
$value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|; |
$value_html = qq|<textarea name="$name" title="$attr_type">$value</textarea>|; |
161 |
} |
} |
162 |
|
|
|
$value = $attr->default( $name ) if ! $value && $attr->has_default; |
|
163 |
$label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation; |
$label_title = qq| title="| . $attr->documentation . qq|"| if $attr->has_documentation; |
164 |
|
|
165 |
$default->{$name} = $value unless defined $default->{$name}; |
$default->{$name} = $value unless defined $default->{$name}; |
166 |
|
|
167 |
if ( ! $value_html ) { |
$value_html = qq|<input type="$type" name="$name" title="$attr_type" value="$value">| unless $value_html; |
|
my $suffix = ''; |
|
|
if ( $attr_type =~ m{^Bool$} ) { |
|
|
$type = 'checkbox'; |
|
|
$suffix = ' checked' if $value; |
|
|
} |
|
|
$value_html = qq|<input type="$type" name="$name" title="$attr_type" value="$value"$suffix>|; |
|
|
} |
|
168 |
|
|
169 |
# warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 ); |
# warn "# required $name ", $class->meta->get_attribute( $name )->dump( 2 ); |
170 |
$form .= qq|<label for="$name"$label_title>$label</label>| . $value_html; |
$form .= qq|<label for="$name"$label_title>$label</label>| . $value_html; |
171 |
} |
} |
172 |
my $html = qq|<h1>$class params</h1><form method="post">$form<input type="submit" value="Run $class"></form>|; |
$form .= qq|<input type="hidden" name="frey-checkboxes" value="| . join(' ', @checkboxes) . qq|">| if @checkboxes; |
173 |
|
|
174 |
|
my $html; |
175 |
|
|
176 |
|
$html = qq| |
177 |
|
<h1>$class params</h1> |
178 |
|
<form method="post"> |
179 |
|
$form |
180 |
|
<input type="submit" value="Run $class"> |
181 |
|
</form> |
182 |
|
| if $form; |
183 |
|
|
184 |
$self->add_status({ |
$self->add_status({ |
185 |
$self->editor( $self->class ) => { |
$self->class => { |
186 |
params => $self->params, |
params => $self->params, |
187 |
config_params => $config_params, |
config_params => $config_params, |
188 |
default => $default |
default => $default |