working on www_addSubmission

This commit is contained in:
daviddelikat 2009-10-23 10:04:47 -05:00
parent 945017d762
commit 1e16ea2972
5 changed files with 96 additions and 60 deletions

View file

@ -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({

View file

@ -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} ) {

View file

@ -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{<li><a href='$u' title='$d'>$n</a></li>} } ;
my $listOfLinks = join '', ( map {
$makeAnchorList->(
$self->getUrl('func=addSubmission;assetId=' . $_->getId ),
$_->get('title'),
WebGUI::HTML::filter($_->get('description'),'all')
)
} ( @new ) );
return $parent->processStyle( '<h1>' . $i18n->get('select form to submit') .
'</h1><ul>' . $listOfLinks . '</ul>' );
}
} else {
$asset = WebGUI::Asset->newByDynamicClass($session,$assetId);
}
if (!defined $asset) {
$session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $assetId");
}
return $asset->www_addSubmission;
}
#-------------------------------------------------------------------
=head2 www_addSubmissionForm ()
call www_editSubmissionForm with assetId == new
@ -833,7 +880,7 @@ calls editSubmissionForm in WebGUI::Asset::EMSSubmissionForm
sub www_editSubmissionForm {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return WebGUI::Asset::EMSSubmissionForm->editSubmissionForm($self,shift);
return WebGUI::Asset::EMSSubmissionForm->www_editSubmissionForm($self,shift);
}

View file

@ -1944,6 +1944,12 @@ normal templates.|,
context => q|Label for list of submission forms; user must choose one to edit.|,
},
'select form to submit' => {
message => q|Select a Form to Submit|,
lastUpdated => 1147050475,
context => q|Label for list of submission forms; user must choose one to proceed to a submission form.|,
},
'main tab label' => {
message => q|Main|,
lastUpdated => 1147050475,

View file

@ -258,6 +258,8 @@ is($sub1->get('status'),'approved','set status to approved');
$sub2->update({ status => 'denied' });
is($sub2->get('status'),'denied','set status to denied');
SKIP: { skip "workflow activities not coded yet", 10 unless 0;
# create the workflows/activities for processing
my $approveSubmissions = WebGUI::Test::Activity->create( $session,
"WebGUI::Workflow::Activity::ProcessEMSApprovals"
@ -297,6 +299,8 @@ is( $sub2, undef, 'approval created a ticket');
# TODO add a test to cleanup denied and created entries
} # end of workflow skip
} # end of create submission skip
$versionTag->commit;