Refactor out the getEditForm code from WebGUI::Workflow::Activity and
put it into HTMLForm. Now HTMLForm can generate dynamic, definition based forms for WebGUI.
This commit is contained in:
parent
95b8244ce0
commit
b1990836d0
3 changed files with 74 additions and 22 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
Commerce merge
|
||||||
|
- The getEditForm code was refactored out of WebGUI::Workflow::Activity and
|
||||||
|
put into WebGUI::HTMLForm. Now any WebGUI code can dynamically generate
|
||||||
|
tabless forms.
|
||||||
|
|
||||||
7.5.3
|
7.5.3
|
||||||
- prevent HTML and Macro injection in usernames
|
- prevent HTML and Macro injection in usernames
|
||||||
- fixed: Running WebGUI Tests on Windows (William McKee, Knowmad Technologies)
|
- fixed: Running WebGUI Tests on Windows (William McKee, Knowmad Technologies)
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,67 @@ sub DESTROY {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 dynamicForm ( $formDefinition, $who )
|
||||||
|
|
||||||
|
Build a form dynamically from an array of hash refs. The format is
|
||||||
|
based on the definition sub from Asset, Workflow::Activity and
|
||||||
|
elements of the ShipDriver and PaymentDriver.
|
||||||
|
|
||||||
|
=head3 $formDefinition
|
||||||
|
|
||||||
|
An arrayref of hashrefs. The arrays are processed in order, but the only
|
||||||
|
way to guarantee the order of the hashes to tie them with Tie::IxHash.
|
||||||
|
|
||||||
|
These fields are allowed in each sub hash
|
||||||
|
|
||||||
|
=head4 label
|
||||||
|
|
||||||
|
A readable, probably internationalized label.
|
||||||
|
|
||||||
|
=head4 hoverHelp
|
||||||
|
|
||||||
|
A tooltip that will activate when the label is hovered over.
|
||||||
|
|
||||||
|
=head4 fieldType
|
||||||
|
|
||||||
|
The kind of HTML form field to build. This is a lower case version of
|
||||||
|
any WebGUI::Form plugin.
|
||||||
|
|
||||||
|
=head4 defaultValue
|
||||||
|
|
||||||
|
The default value the form field should have if the caller has no value
|
||||||
|
for this field.
|
||||||
|
|
||||||
|
=head3 $who
|
||||||
|
|
||||||
|
In order to populate the form with current information from an object,
|
||||||
|
you need to it the object. dynamicForm expects each object to have
|
||||||
|
a C<get> method to provide that information.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub dynamicForm {
|
||||||
|
my ($self, $formDefinition, $parent) = @_;
|
||||||
|
foreach my $definition (reverse @{$formDefinition}) {
|
||||||
|
my $properties = $definition->{properties};
|
||||||
|
foreach my $fieldname (keys %{$properties}) {
|
||||||
|
my %params;
|
||||||
|
foreach my $key (keys %{$properties->{$fieldname}}) {
|
||||||
|
$params{$key} = $properties->{$fieldname}{$key};
|
||||||
|
if ($fieldname eq "title" && lc($params{$key}) eq "untitled") {
|
||||||
|
$params{$key} = $formDefinition->[0]{name};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$params{value} = $parent->get($fieldname);
|
||||||
|
$params{name} = $fieldname;
|
||||||
|
$self->dynamicField(%params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 fieldSetEnd ( )
|
=head2 fieldSetEnd ( )
|
||||||
|
|
|
||||||
|
|
@ -224,28 +224,14 @@ Returns the form that will be used to edit the properties of an activity.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub getEditForm {
|
sub getEditForm {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $form = WebGUI::HTMLForm->new($self->session);
|
my $form = WebGUI::HTMLForm->new($self->session);
|
||||||
$form->submit;
|
$form->submit;
|
||||||
$form->hidden(name=>"activityId", value=>$self->getId);
|
$form->hidden(name=>"activityId", value=>$self->getId);
|
||||||
$form->hidden(name=>"className", value=>$self->get("className"));
|
$form->hidden(name=>"className", value=>$self->get("className"));
|
||||||
my $fullDefinition = $self->definition($self->session);
|
my $fullDefinition = $self->definition($self->session);
|
||||||
foreach my $definition (reverse @{$fullDefinition}) {
|
$form->dynamicForm($fullDefinition, $self);
|
||||||
my $properties = $definition->{properties};
|
return $form;
|
||||||
foreach my $fieldname (keys %{$properties}) {
|
|
||||||
my %params;
|
|
||||||
foreach my $key (keys %{$properties->{$fieldname}}) {
|
|
||||||
$params{$key} = $properties->{$fieldname}{$key};
|
|
||||||
if ($fieldname eq "title" && lc($params{$key}) eq "untitled") {
|
|
||||||
$params{$key} = $fullDefinition->[0]{name};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$params{value} = $self->get($fieldname);
|
|
||||||
$params{name} = $fieldname;
|
|
||||||
$form->dynamicField(%params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $form;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue