diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7b822e1f3..4d4084ece 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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 - prevent HTML and Macro injection in usernames - fixed: Running WebGUI Tests on Windows (William McKee, Knowmad Technologies) diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 1bdd64c05..3b01f913b 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -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 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 ( ) diff --git a/lib/WebGUI/Workflow/Activity.pm b/lib/WebGUI/Workflow/Activity.pm index 7d57c5863..73b7a83b3 100644 --- a/lib/WebGUI/Workflow/Activity.pm +++ b/lib/WebGUI/Workflow/Activity.pm @@ -224,28 +224,14 @@ Returns the form that will be used to edit the properties of an activity. =cut sub getEditForm { - my $self = shift; - my $form = WebGUI::HTMLForm->new($self->session); - $form->submit; - $form->hidden(name=>"activityId", value=>$self->getId); - $form->hidden(name=>"className", value=>$self->get("className")); - my $fullDefinition = $self->definition($self->session); - foreach my $definition (reverse @{$fullDefinition}) { - 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} = $fullDefinition->[0]{name}; - } - } - $params{value} = $self->get($fieldname); - $params{name} = $fieldname; - $form->dynamicField(%params); - } - } - return $form; + my $self = shift; + my $form = WebGUI::HTMLForm->new($self->session); + $form->submit; + $form->hidden(name=>"activityId", value=>$self->getId); + $form->hidden(name=>"className", value=>$self->get("className")); + my $fullDefinition = $self->definition($self->session); + $form->dynamicForm($fullDefinition, $self); + return $form; } #-------------------------------------------------------------------