diff --git a/lib/WebGUI/Asset/EMSSubmission.pm b/lib/WebGUI/Asset/EMSSubmission.pm index 1a7d9f17c..df117efb8 100644 --- a/lib/WebGUI/Asset/EMSSubmission.pm +++ b/lib/WebGUI/Asset/EMSSubmission.pm @@ -96,8 +96,8 @@ sub definition { tab => "properties", fieldType => "HTMLArea", defaultValue => undef, - label => $i18n->get("description"), - hoverHelp => $i18n->get("description help") + label => $SKU_i18n->get("description"), + hoverHelp => $SKU_i18n->get("description help") }, sku => { tab => "shop", @@ -331,14 +331,41 @@ sub www_editSubmission { } my $url = ( $self | $parent )->getUrl('func=editSubmissionSave'); my $newform = WebGUI::HTMLForm->new($session,action => $url); - # DOING - # get the description from the parent + my $formDescription = $parent->getFormDescription; + my @defs = reverse @{__PACKAGE__->definition($session)}; + my $fields; + for my $def ( @defs ) { + my $properties = $def->{properties}; + for my $fieldName ( %$properties ) { + if( defined $formDescription->{$fieldName} ) { + $fields->{$fieldName} = { %{$properties->{$fieldName}} }; # a simple first level copy + $fields->{$fieldName}{fieldId} = $fieldName; + } + } + } + # add the meta field + for my $metaField ( @{$parent->getEventMetaFields} ) { + if( defined $formDescription->{$metaField->{fieldId}} ) { + $fields->{$metaField->{fieldId}} = { %$metaField }; # a simple first level copy + # meta fields call it data type, we copy it to simplify later on + $fields->{$metaField->{fieldId}}{fieldType} = $metaField->{dataType}; + } + } + # for each field - # if field is active - # create a usable control - # else - # create a readonly control -- be sure to convert data where appropriate - # add the comment form + for my $field ( keys %$fields ) { + if( $formDescription->{$field->{fieldId}} ) { + $newform->dynamicField(%$field); + } else { + # TODO see that the data gets formatted + $newform->readonly( + label => $field->{label}, + value => $field->{value}, + fieldId => $field->{fieldId}, + ); + } + } + # TODO add the comment form $newform->submit; return $parent->processStyle( $parent->processTemplate({ diff --git a/lib/WebGUI/Asset/EMSSubmissionForm.pm b/lib/WebGUI/Asset/EMSSubmissionForm.pm index e0c72068b..b58e99aad 100644 --- a/lib/WebGUI/Asset/EMSSubmissionForm.pm +++ b/lib/WebGUI/Asset/EMSSubmissionForm.pm @@ -261,7 +261,7 @@ sub www_editSubmissionForm { $session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $assetId"); } } - my url = ( $self || $parent )->getUrl('func=editSubmissionFormSave'); + my $url = ( $self || $parent )->getUrl('func=editSubmissionFormSave'); my $newform = WebGUI::HTMLForm->new( $session, action => $url ); $newform->hidden(name => 'assetId', value => $assetId); my @fieldNames = qw/title description startDate duration seatsAvailable location/; @@ -489,7 +489,7 @@ calls WebGUI::Asset::EMSSubmission->editSubmission sub www_editSubmission { my $self = shift; return $self->session->privilege->insufficient() unless $self->canEdit; - return WebGUI::Asset::EMSSubmission->editSubmission($self,shift); + return WebGUI::Asset::EMSSubmission->www_editSubmission($self,shift); } #------------------------------------------------------------------- @@ -554,57 +554,9 @@ dav::dump 'processForm::params:', $params; return $params; } -#---------------------------------------------------------------- - -=head2 submitForm (... ) - -this is going away, I am saving the code as an example of what the correct function in the emssubmission module will do - -creates the form for the submitter to enter data - -returns a form object - -=cut - -sub submitForm { -# add the default items, then add items based on the fields in the def... - =head TODO work on this code # this is a bunch of code that will likely be useful for this function... { - my @fieldNames = qw/startDate duration seatsAvailable location /; - my @defs = reverse @{WebGUI::Asset::EMSSubmission->definition($session)}; -dav::dump 'editSubmissionForm::definition:', [@defs]; - for my $def ( @defs ) { - foreach my $fieldName ( @fieldNames ) { - my $properties = $def->{properties}; - if( defined $properties->{$fieldName} ) { - $fields->{$fieldName} = { %{$properties->{$fieldName}} }; # a simple first level copy - # field definitions don't contain their own name, we will need it later on - $fields->{$fieldName}{fieldId} = $fieldName; - }; - } - } - # add the meta field tabs - for my $metaField ( @{$parent->getEventMetaFields} ) { - push @fieldNames, $metaField->{fieldId}; - $fields->{$metaField->{fieldId}} = { %$metaField }; # a simple first level copy - # meta fields call it data type, we copy it to simplify later on - $fields->{$metaField->{fieldId}}{fieldType} = $metaField->{dataType}; - } - unshift @fieldNames, 'main'; - $fields->{main} = { label => $i18n->get('main tab label'), fieldId => 'main' }; - # create tabs - for my $tabname ( @fieldNames ) { - $tabform->addTab($tabname, $fields->{$tabname}{label}, $0 ); - } - my $maintab = $tabform->getTab('main'); - $maintab->hidden(name => 'fieldList', value => join( ' ', @fieldNames ) ); - my @fieldNames = qw/startDate duration seatsAvailable location/; - @defs = reverse @{WebGUI::Asset::EMSSubmissionForm->definition($session)}; -dav::dump 'editSubmissionForm::dump submission form def', \@defs ; - for my $def ( @defs ) { - my $properties = $def->{properties}; for my $fieldName ( qw/title menuTitle url description canSubmitGroupId daysBeforeCleanup deleteCreatedItems submissionDeadline pastDeadlineMessage/ ) { if( defined $properties->{$fieldName} ) { diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index 2fa7454e3..cea56a7d8 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -635,6 +635,53 @@ sub www_addRibbonToBadge { #------------------------------------------------------------------- +=head2 www_addSubmission () + +display a form or links to forms to create a new submission + +=cut + +sub www_addSubmission { + my $self = shift; + my $params = shift || {}; + my $assetId = $params->{assetId} || $self->session->form->get('assetId'); + my $parent = $self->getParent; + my $session = $self->session; + my $i18n = WebGUI::International->new($session,'Asset_EventManagementSystem'); + my $asset; + + if( ! defined $assetId ) { + my $res = $parent->getLineage(['children'],{ returnObjects => 1, + includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'], + } ); + my @new = map { $_->canSubmit ? $_ : () } ( @$res); + if( scalar(@new) == 1 ) { + $asset = $new[0]; + $assetId = $asset->getId; + } else { + my $makeAnchorList =sub{ my $u=shift; my $n=shift; my $d=shift; + return qq{