all tests pass, manual testing passes

This commit is contained in:
daviddelikat 2009-11-04 09:41:24 -06:00
parent c8b97d83fe
commit 6b24783385
10 changed files with 256 additions and 176 deletions

View file

@ -1,6 +1,5 @@
package WebGUI::Asset::EMSSubmission;
use lib '/root/pb/lib'; use dav;
=head1 LEGAL
-------------------------------------------------------------------
@ -20,6 +19,7 @@ use strict;
use Tie::IxHash;
use base qw(WebGUI::AssetAspect::Comments WebGUI::Asset);
use WebGUI::Utility;
use WebGUI::Inbox;
=head1 NAME
@ -292,7 +292,7 @@ sub drawRelatedRibbonsField {
sub drawStatusField {
my ($self, $params) = @_;
return WebGUI::Form::SelectBox($self->session, {
name => 'location',
name => 'submissionStatus',
value => $self->get('submissionStatus'),
options => $self->ems->getSubmissionStatus,
});
@ -341,12 +341,12 @@ sub sendEmailUpdate {
my $session = $self->session;
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmission" );
if( $self->get('sendEmailOnChange') ) {
WebGUI::Inbox->addMessage( $session,{
WebGUI::Inbox->new($session)->addMessage( $session,{
status => 'unread',
message => $i18n->get('your submission has been updated') . "\n\n" .
$self->get('title'),
userId => $self->createdBy,
sentBy => $session->userId,
userId => $self->get('createdBy'),
sentBy => $session->user->userId,
});
}
}
@ -374,19 +374,17 @@ sub www_editSubmission {
my $parent;
if( $this eq __PACKAGE__ ) { # called as a constructor
$parent = shift;
dav::log 'EMSSubmission::www_editSubmission: got class/parent params';
} else {
$self = $this;
$parent = $self->getParent;
dav::log 'EMSSubmission::www_editSubmission: got self param';
}
my $params = shift || { };
my $session = $parent->session;
my $i18n = WebGUI::International->new($parent->session,'Asset_EventManagementSystem');
my $i18n_WG = WebGUI::International->new($parent->session,'WebGUI');
my $assetId = $self ? $self->getId : $params->{assetId} || $session->form->get('assetId') || 'new';
if( $assetId ne 'new' ) {
dav::log 'EMSSubmission::www_editSubmission: asseId ne new';
$self ||= WebGUI::Asset->newByDynamicClass($session,$assetId);
if (!defined $self) {
$session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $assetId");
@ -398,27 +396,39 @@ dav::log 'EMSSubmission::www_editSubmission: asseId ne new';
$newform->hidden(name => 'assetId', value => $assetId);
my $formDescription = $parent->getFormDescription;
my @defs = reverse @{__PACKAGE__->definition($session)};
my @fieldNames = qw/title submissionStatus startDate duration seatsAvailable location description/;
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
if( $fieldName eq 'description' ) {
$fields->{description}{height} = 200;
$fields->{description}{width} = 350;
}
$fields->{$fieldName}{fieldId} = $fieldName;
$fields->{$fieldName}{name} = $fieldName;
$fields->{$fieldName}{value} = $self->get($fieldName) if $self;
}
}
}
# add the meta field
for my $metaField ( @{$parent->getParent->getEventMetaFields} ) {
if( defined $formDescription->{$metaField->{fieldId}} ) {
$fields->{$metaField->{fieldId}} = { %$metaField }; # a simple first level copy
my $fieldId = $metaField->{fieldId};
if( defined $formDescription->{$fieldId} ) {
push @fieldNames, $fieldId;
$fields->{$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};
$fields->{$fieldId}{fieldType} = $metaField->{dataType};
$fields->{$fieldId}{name} = $fieldId;
$fields->{$fieldId}{value} = $self->get($fieldId) if $self;
}
}
# for each field
for my $field ( values %$fields ) {
for my $fieldId ( @fieldNames ) {
my $field = $fields->{$fieldId};
if( $formDescription->{$field->{fieldId}} || $asset->ems->isRegistrationStaff ) {
my $drawMethod = __PACKAGE__ . '::' . $field->{customDrawMethod};
if ($asset->can( $drawMethod )) {
@ -437,18 +447,21 @@ dav::log 'EMSSubmission::www_editSubmission: asseId ne new';
);
}
}
# TODO add the comment form
$newform->submit;
my $title = $assetId eq 'new' ? $i18n->get('new submission') || 'new' : $asset->get('submissionId');
my $title = $assetId eq 'new' ? $i18n_WG->get(99) : $asset->get('title');
my $content = $asset->processStyle(
$asset->processTemplate({
errors => $params->{errors} || [],
backUrl => $parent->getUrl,
pageTitle => $title,
pageForm => $newform->print,
commentForm => $self ? $self->getFormattedComments : '',
commentFlag => $self ? 1 : 0 ,
},$parent->getParent->get('eventSubmissionTemplateId')));
WebGUI::Macro::process( $session, \$content );
if( $session->form->get('asJson') ) {
$session->http->setMimeType( 'application/json' );
return JSON->new->encode( { text => $content, title => $title } );
return JSON->new->encode( { text => $content, title => $title, id => $assetId ne 'new' ? $assetId : 'new' . rand } );
} else {
$session->http->setMimeType( 'text/html' );
return $content;
@ -465,14 +478,14 @@ sub www_editSubmissionSave {
my $self = shift;
my $session = $self->session;
return $session->privilege->insufficient() unless $self->canEdit;
my $formParams = WebGUI::Asset::EMSSubmission->processForm($self);
my $formParams = $self->processForm;
if( $formParams->{_isValid} ) {
delete $formParams->{_isValid};
$self->addRevision($formParams);
WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { override => 1, allowComments => 0 });
$self = $self->cloneFromDb;
$self->sendEmailUpdate;
return $self->www_view;
return $self->ems->www_viewSubmissionQueue;
} else {
return $self->www_editSubmission($formParams);
}
@ -486,7 +499,7 @@ calles ems->view
=cut
sub www_view { $_[0]->ems->www_view }
sub www_view { $_[0]->ems->www_viewSubmissionQueue }
#-------------------------------------------------------------------
@ -505,9 +518,10 @@ sub getEditForm {
my $comments = $tabform->getTab( 'comments' );
#add the comments...
$comments->div({name => 'comments',
contentCallback => sub { $self->getFormattedComments },
});
# TODO once comments can be submitted using AJAX this will work...
# $comments->div({name => 'comments',
# contentCallback => sub { $self->getFormattedComments },
# });
return $tabform;
}
@ -585,24 +599,36 @@ reference to the EMS asset that is parent to the new submission form asset
=cut
use lib '/root/pb/lib'; use dav;
sub processForm {
my $this = shift;
my $form;
my $asset;
my $parent;
my $self;
if( $this eq __PACKAGE__ ) {
my $parent = shift;
$parent = shift;
$form = $parent->session->form;
} elsif( ref $this eq __PACKAGE__ ) {
$form = $this->session->form;
$asset = $parent;
} else {
return {_isValid => 0, errors => [ { text => 'invalid function call' } ] };
$self = $this;
$parent = $self->getParent;
$form = $self->session->form;
$asset = $self;
}
my $params = {_isValid=>1};
# TODO
# get description from parent
# for each active field
# get data from session->form
my $formDescription = $parent->getFormDescription;
my @idList;
if( $asset->ems->isRegistrationStaff ) {
@idList = ( 'submissionStatus', keys %$formDescription );
} else {
@idList = @{$formDescription->{_fieldList}} ;
}
for my $fieldId ( @idList ) {
next if $fieldId =~ /^_/;
$params->{$fieldId} = $form->get($fieldId);
}
return $params;
}
#-------------------------------------------------------------------
@ -655,6 +681,7 @@ This method is called when data is purged by the system.
=head2 view ( )
method called by the container www_view method.
NOTE: this should net get called, all views are redirected elsewhere.
=cut

View file

@ -1,6 +1,5 @@
package WebGUI::Asset::EMSSubmissionForm;
use lib '/root/pb/lib'; use dav;
=head1 LEGAL
@ -22,11 +21,6 @@ use base 'WebGUI::Asset';
use JSON;
use WebGUI::Utility;
# TODO:
# To get an installer for your wobject, add the Installable AssetAspect
# See WebGUI::AssetAspect::Installable and sbin/installClass.pl for more
# details
=head1 NAME
Package WebGUI::Asset::EMSSubmissionForm
@ -47,7 +41,6 @@ These methods are available from this class:
=cut
use lib '/root/pb/lib'; use dav;
#-------------------------------------------------------------------
@ -257,15 +250,14 @@ sub www_editSubmissionForm {
)
} ( @$res ) );
my $title = $i18n->get('select form to edit') ;
my $content = $parent->processStyle( '<h1>' . $title .
'</h1><ul>' . $listOfLinks . '</ul>' );
if( $session->form->get('asJson') ) {
$session->http->setMimeType( 'application/json' );
return JSON->new->encode( { text => $content, title => $title } );
} else {
$session->http->setMimeType( 'text/html' );
return $content;
}
my $content = '<h1>' . $title . '</h1><ul>' . $listOfLinks . '</ul>' ;
if( $session->form->get('asJson') ) {
$session->http->setMimeType( 'application/json' );
return JSON->new->encode( { text => $content, title => $title, id => 'list' . rand } );
} else {
$session->http->setMimeType( 'text/html' );
return $parent->ems->processStyle( $content );
}
}
} elsif( $assetId ne 'new' ) {
$self ||= WebGUI::Asset->newByDynamicClass($session,$assetId);
@ -280,7 +272,6 @@ sub www_editSubmissionForm {
my @fieldNames = qw/title description startDate duration seatsAvailable location/;
my $fields;
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};
@ -300,7 +291,6 @@ dav::dump 'editSubmissionForm::definition:', [@defs];
}
$newform->hidden( name => 'fieldNames', value => join( ' ', @fieldNames ) );
@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
@ -309,15 +299,14 @@ dav::dump 'editSubmissionForm::dump submission form def', \@defs ;
my %fieldParams = %{$properties->{$fieldName}};
$fieldParams{name} = $fieldName;
$fieldParams{value} = $params->{$fieldName} || $self ? $self->get($fieldName) : undef ;
dav::dump 'editSubmissionForm::properties for ', $fieldName, \%fieldParams ;
$newform->dynamicField(%fieldParams);
}
}
}
dav::dump 'editSubmissionForm::dump before generate:',$fields;
my $formDescription = $params->{formDescription} || $self ? $self->getFormDescription : { };
for my $fieldId ( @fieldNames ) {
next if $fieldId eq 'submissionStatus';
my $field = $fields->{$fieldId};
$newform->yesNo(
label => $field->{label},
@ -328,19 +317,23 @@ dav::dump 'editSubmissionForm::dump before generate:',$fields;
}
$newform->submit;
my $title = $assetId eq 'new' ? $i18n->get('new form') || 'new' : $asset->get('title');
my $content = $asset->processStyle(
$asset->processTemplate({
if( $session->form->get('asJson') ) {
$session->http->setMimeType( 'application/json' );
} else {
$session->http->setMimeType( 'text/html' );
}
my $content = $asset->processTemplate({
errors => $params->{errors} || [],
backUrl => $parent->getUrl,
pageTitle => $title,
pageForm => $newform->print,
},$parent->get('eventSubmissionTemplateId')));
if( $session->form->get('asJson') ) {
$session->http->setMimeType( 'application/json' );
return JSON->new->encode( { text => $content, title => $title } );
} else {
$session->http->setMimeType( 'text/html' );
return $content;
}
},$parent->get('eventSubmissionTemplateId'));
WebGUI::Macro::process( $session, \$content );
if( $session->form->get('asJson') ) {
return JSON->new->encode( { text => $content, title => $title, id => $assetId ne 'new' ? $assetId : 'new' . rand } );
} else {
return $asset->ems->processStyle( $content );
}
}
@ -375,7 +368,7 @@ calls ems->view
=cut
sub www_view { $_[0]->ems->www_view }
sub www_view { $_[0]->ems->www_viewSubmissionQueue }
#-------------------------------------------------------------------
@ -483,6 +476,7 @@ This method is called when data is purged by the system.
=head2 view ( )
method called by the container www_view method.
Note: this really shouldn't get called, all views are redirected elsewhere
=cut
@ -504,7 +498,6 @@ calls www_editSubmission with assetId == new
=cut
sub www_addSubmission {
dav::log __PACKAGE__ . '::www_addSubmission';
my $self = shift;
$self->www_editSubmission( { assetId => 'new' } );
}
@ -537,7 +530,6 @@ calls WebGUI::Asset::EMSSubmission->editSubmission
=cut
sub www_editSubmission {
dav::log __PACKAGE__ . '::www_editSubmission';
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return WebGUI::Asset::EMSSubmission->www_editSubmission($self,shift);
@ -576,16 +568,18 @@ reference to the EMS asset that is parent to the new submission form asset
=cut
use lib '/root/pb/lib'; use dav;
sub processForm {
my $this = shift;
my $form;
my $session;
if( $this eq __PACKAGE__ ) {
my $parent = shift;
$form = $parent->session->form;
$session = $parent->session;
$form = $session->form;
} elsif( ref $this eq __PACKAGE__ ) {
$form = $this->session->form;
$session = $this->session;
$form = $session->form;
} else {
return {_isValid => 0, errors => [ { text => 'invalid function call' } ] };
}
@ -597,11 +591,12 @@ sub processForm {
my @fieldNames = split( ' ', $form->get('fieldNames') );
$params->{formDescription} = { map { $_ => $form->get($_ . '_yesNo') } ( @fieldNames ) };
$params->{formDescription}{_fieldList} = [ map { $params->{formDescription}{$_} ? $_ : () } ( @fieldNames ) ];
$params->{formDescription}{submissionStatus} = 0;
if( scalar( @{$params->{formDescription}{_fieldList}} ) == 0 ) {
$params->{_isValid} = 0;
push @{$params->{errors}}, {text => 'you should turn on at least one entry field' }; # TODO internationalize this
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmissionForm" );
push @{$params->{errors}}, {text => $i18n->get('turn on one field') };
}
dav::dump 'processForm::params:', $params;
return $params;
}

View file

@ -1,6 +1,5 @@
package WebGUI::Asset::Wobject::EventManagementSystem;
use lib '/root/pb/lib'; use dav;
=head1 LEGAL
@ -47,7 +46,8 @@ adds the parameter to eventSubmissionGroups
sub addGroupToSubmitList {
my $self = shift;
my $groupId = shift;
my @ids = split(' ', $self->get('eventSubmissionGroups'));
my ($idString) = $self->session->db->read('select eventSubmissionGroups from EventManagementSystem where assetId = ?', [ $self->getId ] )->array;
my @ids = split(' ', $idString);
my %h;
@ids = map { $h{$_}++ == 0 ? $_ : () } ( $groupId, @ids );
$self->update({eventSubmissionGroups => join( ' ', @ids ) });
@ -302,6 +302,21 @@ sub deleteEventMetaField {
}
#-------------------------------------------------------------------
=head2 ems
this is called by the submission sub-system
it is for compatability and ensures that the ems
object is used for certain calls
=cut
sub ems {
my $self = shift;
return $self;
}
#-------------------------------------------------------------------
=head2 getBadges ()
@ -443,7 +458,6 @@ get a sequence number for the submission id
sub getNextSubmissionId {
my $self = shift;
#my $submissionId = $self->get('nextSubmissionId');
my ($submissionId) = $self->session->db->read('select nextSubmissionId from EventManagementSystem where assetId = ?', [ $self->getId ] )->array;
$self->update( { nextSubmissionId => ($submissionId + 1) } );
return $submissionId;
@ -489,7 +503,6 @@ retuns an arrayref of the locations found in the submission location list
sub getSubmissionLocations {
my $self = shift;
my $text = $self->get('submittedLocationsList');
dav::log 'getSubmissionLocations:"', $text, '"';
return undef if $text eq '';
return [ split( /\s+/, $text ) ];
}
@ -745,7 +758,6 @@ display a form or links to forms to create a new submission
=cut
sub www_addSubmission {
dav::log __PACKAGE__ . '::www_addSubmission';
my $self = shift;
my $params = shift || {};
my $session = $self->session;
@ -765,20 +777,31 @@ dav::log __PACKAGE__ . '::www_addSubmission';
$formId = $form->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>} } ;
return qq{<li><a href='$u' onclick='WebGUI.EMS.loadItemFromAnchor(this)' title='$d'>$n</a></li>} } ;
my $listOfLinks = join '', ( map {
$makeAnchorList->(
$_->getUrl('func=addSubmission' ),
$self->getUrl('func=viewSubmissionQueue#' . $_->getId . '_new' ), # _new has to match same in sub www_viewSubmissionQueue in this module
$_->get('title'),
WebGUI::HTML::filter($_->get('description'),'all')
)
} ( @new ) );
return $self->processStyle( '<h1>' . $i18n->get('select form to submit') .
'</h1><ul>' . $listOfLinks . '</ul>' );
my $title = $i18n->get('select form to submit') ;
my $asJson = $session->form->get('asJson');
if( $asJson ) {
$session->http->setMimeType( 'application/json' );
} else {
$session->http->setMimeType( 'text/html' );
}
my $content = '<h1>' . $title . '</h1><ul>' . $listOfLinks . '</ul>' ;
use lib '/root/pb/lib'; use dav; dav::log $content;
if( $asJson ) {
return JSON->new->encode( { text => $content, title => $title, id => 'list' . rand } );
} else {
return $self->ProcessStyle( $content );
}
}
} else {
$form = WebGUI::Asset->newByDynamicClass($session,$formId);
}
$form = WebGUI::Asset->newByDynamicClass($session,$formId);
if (!defined $form) {
$session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $formId");
}
@ -1010,7 +1033,6 @@ sub www_editSubmissionForm {
return WebGUI::Asset::EMSSubmissionForm->www_editSubmissionForm($self,shift);
}
#-------------------------------------------------------------------
=head2 www_editSubmissionFormSave
@ -1254,7 +1276,6 @@ sub www_getAllSubmissions {
my $session = $self->session;
my $datetime = $session->datetime;
my $form = $session->form;
my $rowsPerPage = 25;
my $tableInfo = {};
return $session->privilege->insufficient unless $self->canSubmit || $self->isRegistrationStaff;
@ -1385,6 +1406,7 @@ sub www_getSubmissionById {
} else {
$result->{text} = $res->[0]->www_editSubmission;
$result->{title} = $submissionId;
$result->{id} = $submissionId;
}
$self->session->http->setMimeType('application/json');
return JSON->new->encode($result);
@ -2633,11 +2655,17 @@ sub www_viewSubmissionQueue {
return $self->session->privilege->insufficient() unless $canSubmit || $isRegistrationStaff;
# this map returns an array of hash refs with an id,url pair to describe the submissionForm assets
my @submissionFormUrls = map { {
my @submissionFormUrls = map { { # edit form
id => $_->getId,
edit => 1,
title => $_->get('title'),
linkUrl => $self->getUrl('func=viewSubmissionQueue#' . $_->getId ),
ajaxUrl => $_->getUrl('func=editSubmissionForm'),
},{ # new submission ( _new has to match same in sub www_addSubmission in this module
id => $_->getId . '_new',
title => $_->get('title') . ' - ' . $i18n->get('add submission'),
linkUrl => $self->getUrl('func=viewSubmissionQueue#' . $_->getId . '_new' ),
ajaxUrl => $_->getUrl('func=addSubmission'),
} } (
@{$self->getLineage( ['children'],{ returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],

View file

@ -79,26 +79,29 @@ dav::log __PACKAGE__ . " executing\n";
# keep track of how much time it's taking
my $start = time;
my $limit = 2_500;
my $timeLimit = 120;
my $timeLimit = 60;
my $list = $root->getLineage( ['children'], { returnObjects => 1,
my $list = $root->getLineage( ['descendants'], { returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
for my $emsf ( @$list ) {
my $daysBeforeCleanup = $emsf->get('daysBeforeCleanup') ;
for my $emsForm ( @$list ) {
dav::log __PACKAGE__ . "::executing::emsForm loop\n";
my $daysBeforeCleanup = $emsForm->get('daysBeforeCleanup') ;
next if ! $daysBeforeCleanup;
my $whereClause = q{ submissionStatus='denied' };
if( $emsf->get('deleteCreatedItems') ) {
if( $emsForm->get('deleteCreatedItems') ) {
$whereClause = ' ( ' . $whereClause . q{ or submissionStatus='created' } . ' ) ';
}
my $checkDate = time - ( 60*60*24* $daysBeforeCleanup );
$whereClause .= q{ and lastModifiedDate < } . $checkDate;
my $res = $emsf->getLineage(['children'],{
$whereClause .= q{ and assetData.lastModified < } . $checkDate;
my $res = $emsForm->getLineage(['children'],{ returnObjects => 1,
joinClass => 'WebGUI::Asset::EMSSubmission',
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
whereClause => $whereClause,
} );
for my $submission ( @$res ) {
dav::log __PACKAGE__ . "::executing::submission loop\n";
$submission->purge;
$limit--;
return $self->WAITING(1) if ! $limit or time > $start + $timeLimit;

View file

@ -19,6 +19,7 @@ use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::Asset;
use WebGUI::International;
use WebGUI::VersionTag;
=head1 NAME
@ -68,48 +69,52 @@ See WebGUI::Workflow::Activity::execute() for details.
=cut
use lib '/root/pb/lib'; use dav;
sub execute {
my $self = shift;
my $session = $self->session;
my $root = WebGUI::Asset->getRoot($session);
dav::log __PACKAGE__ . " executing\n";
# keep track of how much time it's taking
my $start = time;
my $limit = 2_500;
my $timeLimit = 120;
my $timeLimit = 60;
my $list = $root->getLineage( ['descendants'], { returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
for my $emsf ( @$list ) {
for my $emsForm ( @$list ) {
my $whereClause = q{ submissionStatus='approved' };
my $res = $emsf->getLineage(['children'],{ returnObjects => 1,
my $res = $emsForm->getLineage(['children'],{ returnObjects => 1,
joinClass => 'WebGUI::Asset::EMSSubmission',
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
whereClause => $whereClause,
} );
for my $submission ( @$res ) {
my %properties = $submission->get;
delete $properties{submissionId};
delete $properties{submissionStatus};
delete $properties{sendEmailOnChange};
delete $properties{ticketId};
my $newAsset = $emsf->ems->addChild(
className => 'WebGUI::Asset::Sku::EMSTicket',
%properties,
);
if( defined $newAsset ) {
my $properties = { className => 'WebGUI::Asset::Sku::EMSTicket' };
for my $name ( qw{title description seatsAvailable price vendorId
synopsis location duration startDate sku relatedRibbons
relatedBadgeGroups eventMetaData shipsSeparately} ) {
$properties->{$name} = $submission->get($name);
}
$properties->{eventNumber} = $self->session->db->quickScalar(
"select max(eventNumber)+1
from EMSTicket left join asset using (assetId)
where parentId=?",[$emsForm->ems->getId]) || 0;
my $newAsset = $emsForm->ems->addChild( $properties );
if( $newAsset ) {
# TODO this should be addRevision
$submission->update({ ticketId => $newAsset->getId, submissionStatus => 'created' });
WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { override => 1, allowComments => 0 });
} else {
$submission->addComment($@) if $@;
$submission->update({ submissionStatus => 'failed' });
}
$limit--;
return $self->WAITING(1) if ! $limit or time > $start + $timeLimit;
last if ! $limit or time > $start + $timeLimit;
}
}
return $self->WAITING(1) if ! $limit or time > $start + $timeLimit;
return $self->COMPLETE;
}

View file

@ -87,6 +87,18 @@ our $I18N = { ##hashref of hashes
context => q|Help text for the submission deadline field. After this date this submission form will not accept any more entries.|
},
'new form' => {
message => q|New Form|,
lastUpdated => 1131394072,
context => q|This is the label for the tab when creating a new submission form.|
},
'turn on one field' => {
message => q|You should turn on at least one entry field.|,
lastUpdated => 1131394072,
context => q|Remind the registrar to allow at least one field to be editted by the event submitter.|
},
# 'TODO' => {
# message => q|TODO|,
# lastUpdated => 1131394072,

View file

@ -1915,6 +1915,12 @@ normal templates.|,
context => q|Label for link to view submission queue.|,
},
'add submission' => {
message => q|New|,
lastUpdated => 1147050475,
context => q|This is appended to the title of a submission form when user is submitting a new event.|,
},
'new submission' => {
message => q|New Submission|,
lastUpdated => 1147050475,

View file

@ -18,6 +18,7 @@ use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use Test::Deep;
use Test::Warn;
use JSON;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Test::Activity;
@ -33,12 +34,11 @@ use WebGUI::Asset::Sku::EMSToken;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my @cleanup = ();
#----------------------------------------------------------------------------
# Tests
plan tests => 60; # Increment this number for each test you create
plan tests => 52; # Increment this number for each test you create
(my $submitGroupA = WebGUI::Group->new($session,'new'))->name('groupA');
(my $submitGroupB = WebGUI::Group->new($session,'new'))->name('groupB');
@ -165,8 +165,6 @@ my $formAdesc = {
location => 0,
};
use lib '/root/pb/lib'; use dav;
dav::dump $session;
my $frmA = $ems->addSubmissionForm({
title => 'test A -- long',
@ -216,7 +214,7 @@ my $submission = {
};
$session->request->setup_body($submission);
my $sub1 = $frmA->addSubmission;
push @cleanup, sub { $sub1->puge; };
WebGUI::Test->assetsToPurge( $sub1 );
print join( "\n", @{$sub1->{errors}} ),"\n" if defined $sub1->{errors};
my $isa1 = isa_ok( $sub1, 'WebGUI::Asset::EMSSubmission', "userA/formA valid submission succeeded" );
ok( $ems->hasSubmissions, 'UserA has submissions on this ems' );
@ -227,14 +225,14 @@ ok( $ems->canSubmit, 'UserB can submit to this ems' );
ok( !$frmA->canSubmit, 'UserB cannot submit to formA' );
ok( $frmB->canSubmit, 'UserB can submit to formB' );
my $submission = {
$submission = {
title => 'why i like to be important',
description => 'the description',
mfRequiredUrl => 'http://google.com',
};
$session->request->setup_body($submission);
my $sub2 = $frmB->addSubmission;
push @cleanup, sub { $sub2->purge; };
WebGUI::Test->assetsToPurge( $sub2 );
my $isa2 = isa_ok( $sub2, 'WebGUI::Asset::EMSSubmission', "userB/FormB valid submission succeeded" );
loginUserC;
@ -267,6 +265,7 @@ cmp_deeply( from_json($ems->www_getAllSubmissions), {
$session->request->setup_body({submissionId => 3});
cmp_deeply( from_json($ems->www_getSubmissionById), {
title => 3,
id => 3,
text => ignore(),
}, 'test getSubmissionById');
@ -313,7 +312,6 @@ cmp_deeply( from_json($ems->www_getAllSubmissions), {
dir => 'DESC',
}, 'test getAllSubmissions for Registrar' );
# TODO fix num tests
SKIP: { skip 'create submission failed', 8 unless $isa1 && $isa2;
loginUserA;
@ -353,48 +351,30 @@ my $cleanupSubmissions = WebGUI::Test::Activity->create( $session,
"WebGUI::Workflow::Activity::CleanupEMSSubmissions"
);
push @cleanup, sub { $approveSubmissions->purge; $cleanupSubmissions->purge; };
is($approveSubmissions->run, 'complete', 'approval complete');
is($approveSubmissions->run, 'done', 'approval done');
$sub1 = $sub1->cloneFromDb;
is( $sub1->get('submissionStatus'),'failed','submission failed to create');
# TODO fill in the rest of the data required by EMSTicket
print "1\n";
$approveSubmissions->rerun;
print "2\n";
is($approveSubmissions->run, 'complete', 'approval complete');
is($approveSubmissions->run, 'done', 'approval done');
print "3\n";
$sub1 = $sub1->cloneFromDb;
print "4\n";
is( $sub1->get('submissionStatus'),'created','approval successfull');
print "5\n";
my $ticket = WebGUI::Asset->newByDynamicClass($session, $sub1->get('ticketId'));
print "6\n";
isa_ok( $ticket, 'WebGUI::Asset::Sku::EMSTicket', 'approval created a ticket');
print "7\n";
push @cleanup, sub { $ticket->purge; };
print "8\n";
WebGUI::Test->assetsToPurge( $ticket ) if $ticket ;
my $newDate = time - ( 60 * 60 * 24 * ( $sub2->getParent->get('daysBeforeCleanup') + 1 ) ),
$sub2->update({
lastModified => time - ( 60 * 60 * 72 ), # last modified 3 days ago
submissionStatus => 'denied',
# lastModified => $newDate, -- update overrides this...
});
my $submissionId = $sub2->get('assetId');
my $sub2Id = $sub2->getId;
$session->db->write('update assetData set lastModified = ' . $newDate . ' where assetId = "' . $sub2Id . '"' );
$cleanupSubmissions->rerun;
is($cleanupSubmissions->run, 'complete', 'cleanup complete');
is($cleanupSubmissions->run, 'done', 'cleanup done');
$sub2 = WebGUI::Asset->newByDynamicClass($session, $submissionId);
is( $sub2, undef, 'ticket deleted');
# TODO add a test to cleanup created entries
$sub2 = WebGUI::Asset->newByDynamicClass($session, $sub2Id);
is( $sub2, undef, 'submission deleted');
} # end of workflow skip
@ -439,6 +419,7 @@ my $expected = {
'title' => '1',
'startDate' => '1',
'description' => '1',
'submissionStatus' => '0',
'_fieldList' => [
'title',
'description',
@ -470,14 +451,15 @@ cmp_deeply( $result, $expected , 'test process form' );
$expected = {
'errors' => [
{
'text' => 'you should turn on at least one entry field'
'text' => ignore(),
}
],
'submissionDeadline' => undef,
'menuTitle' => undef,
'pastDeadlineMessage' => undef,
'formDescription' => {
'_fieldList' => []
'_fieldList' => [],
'submissionStatus' => 0,
},
'description' => undef,
'_isValid' => 0,
@ -490,12 +472,13 @@ $expected = {
};
$session->request->setup_body( { } );
$result = WebGUI::Asset::EMSSubmissionForm->processForm($ems);
dav::dump $result;
cmp_deeply( $result, $expected , 'test process form' );
} # end of skip HTML::Form
# these run code to see that it runs, but do not check for correctness
warnings_are {
$ems->www_viewSubmissionQueue;
$ems->www_addSubmission;
$ems->www_addSubmissionForm;
@ -513,6 +496,10 @@ $sub1->drawStatusField;
$sub1->www_editSubmission;
$sub1->www_editSubmissionSave;
$sub1->processForm;
# test comments
$sub1->getFormattedComments;
} [], 'no warnings from calling a bunch of functions';
} # end of use packages skip
}; # end of eval
@ -523,6 +510,7 @@ print $@ if $@;
#----------------------------------------------------------------------------
# Cleanup
END {
map { eval { $_->() } } ( @cleanup );
}
#vim:ft=perl

View file

@ -2,6 +2,8 @@ package WebGUI::Test::Activity;
use WebGUI::Workflow;
my @cleanup; # TODO fix WebGUI::Text::assetsToPurge so that it works with workflows and activities
=head Name
package WebGUI::Test::Activity;
@ -70,6 +72,8 @@ sub create {
my $tag = WebGUI::VersionTag->getWorking($session);
$tag->commit;
WebGUI::Test->tagsToRollback($tag);
# WebGUI::Test->assetsToPurge($instance,$workflow); -- does not work...
push @cleanup, $instance, $workflow,
return bless { instance => $instance,
session => $session,
@ -82,14 +86,15 @@ sub run {
sub rerun {
my $self = shift;
my $session = $self->{session};
$self->{instance}->delete;
my $session = $self->{session};
$self->{instance} = WebGUI::Workflow::Instance->create($session,
{
workflowId => $self->{workflow}->getId,
skipSpectreNotification => 1,
}
);
# WebGUI::Test->assetsToPurge($self->{instance}); -- does not work
push @cleanup, $self->{instance};
my $tag = WebGUI::VersionTag->getWorking($session, 1);
if( $tag ) {
$tag->commit;
@ -98,10 +103,10 @@ my $session = $self->{session};
}
sub delete {
my $self = shift;
$self->{instance}->delete;
$self->{workflow}->delete;
END {
map { $_->delete; } ( @cleanup );
}
1;

View file

@ -39,7 +39,7 @@ WebGUI.EMS = function (configs) {
WebGUI.EMS.url = configs.url;
WebGUI.EMS.tabContent = configs.tabContent;
}
WebGUI.EMS.Items = new Object();
WebGUI.EMS.items = new Object();
if(!this._configs.initRequestString) {
this._configs.initRequestString = ';startIndex=0';
@ -55,6 +55,7 @@ WebGUI.EMS = function (configs) {
''
],
'Asset_EventManagementSystem' : [
'close tab',
''
]
}
@ -69,6 +70,18 @@ WebGUI.EMS = function (configs) {
// Protected Static Methods
///////////////////////////////////////////////////////////////
//***********************************************************************************
// This Method updates the window.location.hash when the user changes tabs
WebGUI.EMS.changeTab = function ( e ) {
alert('tab changed');
var index = WebGUI.EMS.tabs.getTabIndex( e.newValue );
if( index == 0 ) {
window.location.hash = '';
} else {
window.location.hash = WebGUI.EMS.Tabs[index].id;
}
};
//***********************************************************************************
// This method closes the active tab
//
@ -80,20 +93,20 @@ WebGUI.EMS = function (configs) {
var index;
if( typeof(e) == "string" || typeof(e) == "number" ) {
index = e;
myTab = WebGUI.EMS.Items[index].Tab;
myTab = WebGUI.EMS.items[index].tab;
} else {
if( typeof(e) != "undefined" ) {
YAHOO.util.Event.preventDefault(e);
}
if( typeof(myTab) == "undefined" ) {
myTab = WebGUI.EMS.Tabs.get('activeTab');
myTab = WebGUI.EMS.tabs.get('activeTab');
}
index = parseInt( myTab.get('label') );
index = WebGUI.EMS.tabs.getTabIndex(myTab);
}
delete WebGUI.EMS.Items[index];
WebGUI.EMS.Tabs.removeTab(myTab);
delete WebGUI.EMS.items[index];
WebGUI.EMS.tabs.removeTab(myTab);
if( WebGUI.EMS.lastTab ) {
WebGUI.EMS.Tabs.set('activeTab',WebGUI.EMS.lastTab);
WebGUI.EMS.tabs.set('activeTab',WebGUI.EMS.lastTab);
}
};
@ -155,25 +168,29 @@ WebGUI.EMS = function (configs) {
alert(message);
return;
// currently only one tab exists, so instead of checking we just delete it and recreate
} else { // if( typeof(WebGUI.EMS.Items[response.title]) == "undefined"
// || WebGUI.EMS.Items[response.title] == null ) {
// this condition is going to have to search for the id in the list
} else { // if( typeof(WebGUI.EMS.items[response.title]) == "undefined"
// || WebGUI.EMS.items[response.title] == null ) { // }
// if there is a tab .. close it,
// at least until I can get the JS/HTML re-written to handle multiple tabs
// there should only be one
for( var item in WebGUI.EMS.Items ) { WebGUI.EMS.closeTab(item) }
for( var item in WebGUI.EMS.items ) { WebGUI.EMS.closeTab(item) }
var myContent = document.createElement("div");
myContent.innerHTML = response.text;
myTab = new YAHOO.widget.Tab({
label: response.title + '<span class="close"><img src="/extras/wobject/EMS/close12_1.gif" alt="X" title="' +
WebGUI.EMS.i18n.get('Asset_EMSSubmission','close tab') + '" /></span>',
WebGUI.EMS.i18n.get('Asset_EventManagementSystem','close tab') + '" /></span>',
contentEl: myContent
});
WebGUI.EMS.Tabs.addTab( myTab );
WebGUI.EMS.tabs.addTab( myTab );
var index = WebGUI.EMS.tabs.getTabIndex(myTab);
YAHOO.util.Event.on(myTab.getElementsByClassName('close')[0], 'click', WebGUI.EMS.closeTab , myTab);
WebGUI.EMS.Items[response.title] = new Object();
WebGUI.EMS.Items[response.title].Tab = myTab;
WebGUI.EMS.items[index] = new Object();
WebGUI.EMS.items[index].tab = myTab;
WebGUI.EMS.items[index].id = response.id;
WebGUI.EMS.items[index].title = response.title;
//} else {
//myTab = WebGUI.EMS.Items[response.title].Tab;
//myTab = WebGUI.EMS.items[response.title].tab;
//myTab.set('content', response.text);
}
// make sure the script on the ticket has run
@ -182,8 +199,9 @@ WebGUI.EMS = function (configs) {
// }
// delete WebGUI.ticketJScriptRun;
WebGUI.EMS.loadingIndicator.hide();
WebGUI.EMS.lastTab = WebGUI.EMS.Tabs.get('activeTab');
WebGUI.EMS.Tabs.set('activeTab',myTab);
WebGUI.EMS.lastTab = WebGUI.EMS.tabs.get('activeTab');
//initHoverHelp(myTab);
WebGUI.EMS.tabs.set('activeTab',myTab);
},
failure: function(o) {
WebGUI.EMS.loadingIndicator.hide();
@ -272,21 +290,14 @@ WebGUI.EMS = function (configs) {
// if the user pressed a modifier key we want to default
if( eventModifiers( evt ) ) { return }
var target = evt.target;
//let the default action happen if the user clicks the last reply column
var links = YAHOO.util.Dom.getElementsByClassName ("profile_link","a",target);
if (links.length == 0) {
YAHOO.util.Event.stopEvent(evt.event);
}
YAHOO.util.Event.stopEvent(evt.event);
var elCell = this.getTdEl(target);
if(elCell) {
var oRecord = this.getRecord(elCell);
var submissionId = oRecord.getData('submissionId');
if( typeof( WebGUI.EMS.Items[submissionId] ) != "undefined" ) {
WebGUI.EMS.Tabs.set('activeTab',WebGUI.EMS.Items[submissionId].Tab);
if( typeof( WebGUI.EMS.items[submissionId] ) != "undefined" ) {
WebGUI.EMS.tabs.set('activeTab',WebGUI.EMS.items[submissionId].tab);
WebGUI.EMS.loadingIndicator.hide();
} else {
WebGUI.EMS.loadItem( submissionId );