Finish reverting EMS Submissions.

This reverts commit aab3a74026.
This commit is contained in:
Colin Kuskie 2009-11-05 17:03:28 -08:00
parent 4597dac8b7
commit 3c985a5eed
17 changed files with 8 additions and 3695 deletions

View file

@ -1,717 +0,0 @@
package WebGUI::Asset::EMSSubmission;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use Class::C3;
use strict;
use Tie::IxHash;
use base qw(WebGUI::AssetAspect::Comments WebGUI::Asset);
use WebGUI::Utility;
use WebGUI::Inbox;
=head1 NAME
Package WebGUI::Asset::EMSSubmission
=head1 DESCRIPTION
Describe your New Asset's functionality and features here.
=head1 SYNOPSIS
use WebGUI::Asset::EMSSubmission;
=head1 TODO
the comments tab may need to be added in a getEditForm function like Sku::EMSTicket
make a button/link for the admin to view the submission as the owner sees it.
the www_edit function should see if the userid is the owner and call a seperate function
else if it is not in the admin group return insufitient priviledges
else call the getEditForm function like sku::EMSTicket does...
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 addRevision
This method exists for demonstration purposes only. The superclass
handles revisions to NewAsset Assets.
=cut
#sub addRevision {
# my $self = shift;
# my $newSelf = $self->next::method(@_);
# return $newSelf;
#}
#-------------------------------------------------------------------
=head2 definition ( session, definition )
defines asset properties for New Asset instances. You absolutely need
this method in your new Assets.
=head3 session
=head3 definition
A hash reference passed in from a subclass definition.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmission" );
my $EMS_i18n = WebGUI::International->new($session, "Asset_EventManagementSystem");
my $SKU_i18n = WebGUI::International->new($session, "Asset_Sku");
tie my %properties, 'Tie::IxHash', (
submissionId => {
noFormPost => 1,
fieldType => "hidden",
defaultValue => undef,
},
submissionStatus => {
fieldType =>"selectList",
defaultValue => 'pending',
customDrawMethod=> 'drawStatusField',
label => $i18n->get("submission status"),
hoverHelp => $i18n->get("submission status help")
},
description => {
tab => "properties",
fieldType => "HTMLArea",
defaultValue => undef,
label => $SKU_i18n->get("description"),
hoverHelp => $SKU_i18n->get("description help")
},
sku => {
tab => "shop",
fieldType => "text",
defaultValue => $session->id->generate,
label => $SKU_i18n->get("sku"),
hoverHelp => $SKU_i18n->get("sku help")
},
displayTitle => {
tab => "display",
fieldType => "yesNo",
defaultValue => 1,
label => $SKU_i18n->get("display title"),
hoverHelp => $SKU_i18n->get("display title help")
},
vendorId => {
tab => "shop",
fieldType => "vendor",
defaultValue => 'defaultvendor000000000',
label => $SKU_i18n->get("vendor"),
hoverHelp => $SKU_i18n->get("vendor help")
},
shipsSeparately => {
tab => 'shop',
fieldType => 'yesNo',
defaultValue => 0,
label => $SKU_i18n->get('shipsSeparately'),
hoverHelp => $SKU_i18n->get('shipsSeparately help'),
},
price => {
tab => "shop",
fieldType => "float",
defaultValue => 0.00,
label => $EMS_i18n->get("price"),
hoverHelp => $EMS_i18n->get("price help"),
},
seatsAvailable => {
tab => "shop",
fieldType => "integer",
defaultValue => 25,
label => $EMS_i18n->get("seats available"),
hoverHelp => $EMS_i18n->get("seats available help"),
},
startDate => {
noFormPost => 1,
fieldType => "dateTime",
defaultValue => '',
label => $EMS_i18n->get("add/edit event start date"),
hoverHelp => $EMS_i18n->get("add/edit event start date help"),
autoGenerate => 0,
},
duration => {
tab => "properties",
fieldType => "float",
defaultValue => 1.0,
subtext => $EMS_i18n->get('hours'),
label => $EMS_i18n->get("duration"),
hoverHelp => $EMS_i18n->get("duration help"),
},
location => {
fieldType => "combo",
tab => "properties",
customDrawMethod=> 'drawLocationField',
label => $EMS_i18n->get("location"),
hoverHelp => $EMS_i18n->get("location help"),
},
relatedBadgeGroups => {
tab => "properties",
fieldType => "checkList",
customDrawMethod=> 'drawRelatedBadgeGroupsField',
label => $EMS_i18n->get("related badge groups"),
hoverHelp => $EMS_i18n->get("related badge groups ticket help"),
},
relatedRibbons => {
tab => "properties",
fieldType => "checkList",
customDrawMethod=> 'drawRelatedRibbonsField',
label => $EMS_i18n->get("related ribbons"),
hoverHelp => $EMS_i18n->get("related ribbons help"),
},
eventMetaData => {
noFormPost => 1,
fieldType => "hidden",
defaultValue => '{}',
},
sendEmailOnChange => {
tab => "properties",
fieldType => "yesNo",
defaultValue => 1,
label => $i18n->get("send email label"),
hoverHelp => $i18n->get("send email label help")
},
ticketId => {
noFormPost => 1,
fieldType => "hidden",
defaultValue => '',
},
);
push @{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'EMSSubmission.gif',
autoGenerateForms => 1,
tableName => 'EMSSubmission',
className => 'WebGUI::Asset::EMSSubmission',
properties => \%properties,
};
return $class->next::method( $session, $definition );
} ## end sub definition
#-------------------------------------------------------------------
=head2 drawLocationField ()
Draws the field for the location property.
=cut
sub drawLocationField {
my ($self, $params) = @_;
my $ems = $self->ems;
my $options = { map { $_ => $_ } ( @{ $ems->getSubmissionLocations || [ $ems->getLocations ] } ) } ;
if( $ems->isRegistrationStaff ) {
return WebGUI::Form::combo($self->session, {
name => 'location',
value => $self->get('location'),
options => $options,
});
} else {
return WebGUI::Form::selectBox($self->session, {
name => 'location',
value => $self->get('location'),
options => $options,
});
}
}
#-------------------------------------------------------------------
=head2 drawRelatedBadgeGroupsField ()
Draws the field for the relatedBadgeGroups property.
=cut
sub drawRelatedBadgeGroupsField {
my ($self, $params) = @_;
return WebGUI::Form::checkList($self->session, {
name => $params->{name},
value => $self->get($params->{name}),
vertical => 1,
options => $self->getParent->getParent->getBadgeGroups,
});
}
#-------------------------------------------------------------------
=head2 drawRelatedRibbonsField ()
Draws the field for the relatedRibbons property.
=cut
sub drawRelatedRibbonsField {
my ($self, $params) = @_;
my %ribbons = ();
foreach my $ribbon (@{$self->getParent->getParent->getRibbons}) {
$ribbons{$ribbon->getId} = $ribbon->getTitle;
}
return WebGUI::Form::checkList($self->session, {
name => $params->{name},
value => $self->get($params->{name}),
vertical => 1,
options => \%ribbons,
});
}
#-------------------------------------------------------------------
=head2 drawStatusField
=cut
sub drawStatusField {
my ($self, $params) = @_;
return WebGUI::Form::SelectBox($self->session, {
name => 'submissionStatus',
value => $self->get('submissionStatus'),
options => $self->ems->getSubmissionStatus,
});
}
#-------------------------------------------------------------------
=head2 duplicate
This method exists for demonstration purposes only. The superclass
handles duplicating NewAsset Assets. This method will be called
whenever a copy action is executed
=cut
#sub duplicate {
# my $self = shift;
# my $newAsset = $self->next::method(@_);
# return $newAsset;
#}
#-------------------------------------------------------------------
=head2 ems
returns the ems ansestor of this asset
=cut
sub ems {
my $self = shift;
$self->getParent->getParent
}
#-------------------------------------------------------------------
=head2 sendEmailUpdate
if the sendEmail on change is turned on then send email to the owner
=cut
sub sendEmailUpdate {
my $self = shift;
my $session = $self->session;
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmission" );
if( $self->get('sendEmailOnChange') ) {
WebGUI::Inbox->new($session)->addMessage( $session,{
status => 'unread',
message => $i18n->get('your submission has been updated') . "\n\n" .
$self->get('title'),
userId => $self->get('createdBy'),
sentBy => $session->user->userId,
});
}
}
#-------------------------------------------------------------------
=head2 www_editSubmission ( parent, params )
edit a submission
=head3 parent
ref to the EMSSubmissionForm that is parent to the new submission
=head3 params
parameters for the submission
=cut
sub www_editSubmission {
my $this = shift;
my $self;
my $parent;
if( $this eq __PACKAGE__ ) { # called as a constructor
$parent = shift;
} else {
$self = $this;
$parent = $self->getParent;
}
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' ) {
$self ||= WebGUI::Asset->newByDynamicClass($session,$assetId);
if (!defined $self) {
$session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $assetId");
}
}
my $asset = $self || $parent;
my $url = $asset->getUrl('func=editSubmissionSave');
my $newform = WebGUI::HTMLForm->new($session,action => $url);
$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} ) {
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->{$fieldId}{fieldType} = $metaField->{dataType};
$fields->{$fieldId}{name} = $fieldId;
$fields->{$fieldId}{value} = $self->get($fieldId) if $self;
}
}
# for each field
for my $fieldId ( @fieldNames ) {
my $field = $fields->{$fieldId};
if( $formDescription->{$field->{fieldId}} || $asset->ems->isRegistrationStaff ) {
my $drawMethod = __PACKAGE__ . '::' . $field->{customDrawMethod};
if ($asset->can( $drawMethod )) {
$field->{value} = $asset->$drawMethod($field);
delete $field->{name}; # don't want readOnly to generate a hidden field
$field->{fieldType} = "readOnly";
}
$newform->dynamicField(%$field);
} else {
# TODO see that the data gets formatted
$newform->readOnly(
label => $field->{label},
value => $field->{value} || '[ ]',
fieldId => $field->{fieldId},
);
}
}
$newform->submit;
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, id => $assetId ne 'new' ? $assetId : 'new' . rand } );
} else {
$session->http->setMimeType( 'text/html' );
return $content;
}
}
#-------------------------------------------------------------------
=head2 www_editSubmissionSave
=cut
sub www_editSubmissionSave {
my $self = shift;
my $session = $self->session;
return $session->privilege->insufficient() unless $self->canEdit;
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->ems->www_viewSubmissionQueue;
} else {
return $self->www_editSubmission($formParams);
}
}
#-------------------------------------------------------------------
=head2 www_view
calles ems->view
=cut
sub www_view { $_[0]->ems->www_viewSubmissionQueue }
#-------------------------------------------------------------------
=head2 getEditForm ( )
Extends the base class to add Tax information for the Sku, in a new tab.
=cut
sub getEditForm {
my $self = shift;
my $session = $self->session;
my $tabform = $self->SUPER::getEditForm;
my $comments = $tabform->getTab( 'comments' );
#add the comments...
# TODO once comments can be submitted using AJAX this will work...
# $comments->div({name => 'comments',
# contentCallback => sub { $self->getFormattedComments },
# });
return $tabform;
}
#-------------------------------------------------------------------
=head2 getEditTabs ( )
defines 2 new tabs.
the shop tab is created here to mimic the function of the sku-created
shop tab. this class holds data like Sku assets so that they can be assigned
in the future when the sku asset is created from this data.
=cut
sub getEditTabs {
my $self = shift;
my $i18n = WebGUI::International->new($self->session,"Asset_EMSSubmission");
my $sku_i18n = WebGUI::International->new($self->session,"Asset_Sku");
return ($self->SUPER::getEditTabs(), ['shop', $sku_i18n->get('shop'), 9], ['comments', $i18n->get('comments'), 9]);
}
#-------------------------------------------------------------------
=head2 getQueueUrl
returns the URL for the submission queue page with the submisison id in the hash part
=cut
sub getQueueUrl {
my $self = shift;
return $self->ems->getUrl('func=viewSubmissionQueue#' . $self->get('submissionId') );
}
#-------------------------------------------------------------------
=head2 indexContent ( )
Making private. See WebGUI::Asset::indexContent() for additonal details.
=cut
sub indexContent {
my $self = shift;
my $indexer = $self->next::method;
$indexer->setIsPublic(0);
}
#-------------------------------------------------------------------
=head2 prepareView ( )
See WebGUI::Asset::prepareView() for details.
=cut
sub prepareView {
my $self = shift;
$self->ems->prepareView;
#$self->next::method();
#my $template = WebGUI::Asset::Template->new( $self->session, $self->get("templateId") );
#$template->prepare($self->getMetaDataAsTemplateVariables);
#$self->{_viewTemplate} = $template;
}
#----------------------------------------------------------------
=head2 processForm ( $parent )
pull data componenets out of $session->form
=head3 parent
reference to the EMS asset that is parent to the new submission form asset
=cut
sub processForm {
my $this = shift;
my $form;
my $asset;
my $parent;
my $self;
if( $this eq __PACKAGE__ ) {
$parent = shift;
$form = $parent->session->form;
$asset = $parent;
} else {
$self = $this;
$parent = $self->getParent;
$form = $self->session->form;
$asset = $self;
}
my $params = {_isValid=>1};
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;
}
#-------------------------------------------------------------------
=head2 processPropertiesFromFormPost ( )
Used to process properties from the form posted. Do custom things with
noFormPost fields here, or do whatever you want. This method is called
when /yourAssetUrl?func=editSave is requested/posted.
=cut
sub processPropertiesFromFormPost {
my $self = shift;
$self->next::method;
}
#-------------------------------------------------------------------
=head2 purge ( )
This method is called when data is purged by the system.
removes collateral data associated with a NewAsset when the system
purges it's data. This method is unnecessary, but if you have
auxiliary, ancillary, or "collateral" data or files related to your
asset instances, you will need to purge them here.
=cut
#sub purge {
# my $self = shift;
# return $self->next::method;
#}
#-------------------------------------------------------------------
=head2 purgeRevision ( )
This method is called when data is purged by the system.
=cut
#sub purgeRevision {
# my $self = shift;
# return $self->next::method;
#}
#-------------------------------------------------------------------
=head2 view ( )
method called by the container www_view method.
NOTE: this should net get called, all views are redirected elsewhere.
=cut
sub view {
my $self = shift;
return $self->ems->view;
#my $var = $self->get; # $var is a hash reference.
#$var->{controls} = $self->getToolbar;
#return $self->processTemplate( $var, undef, $self->{_viewTemplate} );
}
#-------------------------------------------------------------------
=head2 www_edit ( )
Web facing method which is the default edit page. Unless the method needs
special handling or formatting, it does not need to be included in
the module.
=cut
sub www_edit {
my $self = shift;
my $session = $self->session;
return $session->privilege->insufficient() unless $self->canEdit;
return $session->privilege->locked() unless $self->canEditIfLocked;
my $i18n = WebGUI::International->new( $session, 'Asset_EMSSubmission' );
return $self->getAdminConsole->render( $self->getEditForm->print, $i18n->get('edit asset') );
}
1;
#vim:ft=perl

View file

@ -1,549 +0,0 @@
package WebGUI::Asset::EMSSubmissionForm;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Tie::IxHash;
use base 'WebGUI::Asset';
use JSON;
use WebGUI::Utility;
=head1 NAME
Package WebGUI::Asset::EMSSubmissionForm
=head1 DESCRIPTION
This Asset describes and builds a form which provides an interface for submitting a custom
subset of the EMSTicket asset. Users create submissions which can be editted by admins
and then become EMSTicket's.
=head1 SYNOPSIS
use WebGUI::Asset::EMSSubmissionForm;
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 addSubmission
Creates an EMSSubmission object based on the params
( called by www_saveSubmission )
=cut
sub addSubmission {
my $self = shift;
my $form = $self->session->form;
my $newParams = {};
my $fieldList = $self->getFormDescription->{_fieldList};
for my $field ( @$fieldList ) {
$newParams->{$field} = $form->get($field);
}
$newParams->{className} = 'WebGUI::Asset::EMSSubmission';
$newParams->{submissionStatus} = 'pending';
$newParams->{submissionId} = $self->ems->getNextSubmissionId;
my $newAsset = $self->addChild($newParams);
WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session, { override => 1, allowComments => 0 });
$self = $self->cloneFromDb;
return $newAsset;
}
#-------------------------------------------------------------------
=head2 addRevision
This me>thod exists for demonstration purposes only. The superclass
handles revisions to NewAsset Assets.
=cut
#sub addRevision {
# my $self = shift;
# my $newSelf = $self->SUPER::addRevision(@_);
# return $newSelf;
#}
#-------------------------------------------------------------------
=head2 canSubmit
returns true if current user can submit using this form
=cut
sub canSubmit {
my $self = shift;
return $self->session->user->isInGroup($self->get('canSubmitGroupId'));
}
#-------------------------------------------------------------------
=head2 definition ( session, definition )
defines asset properties for New Asset instances. You absolutely need
this method in your new Assets.
=head3 session
=head3 definition
A hash reference passed in from a subclass definition.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmissionForm" );
tie my %properties, 'Tie::IxHash', (
canSubmitGroupId => {
tab => "security",
fieldType => "group",
defaultValue => 2,
label => $i18n->get("can submit group label"),
hoverHelp => $i18n->get("can submit group label help")
},
daysBeforeCleanup => {
tab => "properties",
fieldType => "integer",
defaultValue => 7,
label => $i18n->get("days before cleanup label"),
hoverHelp => $i18n->get("days before cleanup label help")
},
deleteCreatedItems => {
tab => "properties",
fieldType => "yesNo",
defaultValue => undef,
label => $i18n->get("delete created items label"),
hoverHelp => $i18n->get("delete created items label help")
},
submissionDeadline => {
tab => "properties",
fieldType => "Date",
defaultValue => '677496912', # far in the future...
label => $i18n->get("submission deadline label"),
hoverHelp => $i18n->get("submission deadline label help")
},
pastDeadlineMessage => {
tab => "properties",
fieldType => "HTMLArea",
defaultValue => $i18n->get('past deadline message'),
label => $i18n->get("past deadline label"),
hoverHelp => $i18n->get("past deadline label help")
},
formDescription => {
tab => "properties",
fieldType => "textarea",
defaultValue => '{ }',
label => $i18n->get("form dscription label"),
hoverHelp => $i18n->get("form dscription label help")
},
);
push @{$definition}, {
assetName => $i18n->get('assetName'),
icon => 'EMSSubmissionForm.gif',
autoGenerateForms => 1,
tableName => 'EMSSubmissionForm',
className => 'WebGUI::Asset::EMSSubmissionForm',
properties => \%properties,
};
return $class->SUPER::definition( $session, $definition );
} ## end sub definition
#-------------------------------------------------------------------
=head2 duplicate
This method exists for demonstration purposes only. The superclass
handles duplicating NewAsset Assets. This method will be called
whenever a copy action is executed
=cut
#sub duplicate {
# my $self = shift;
# my $newAsset = $self->SUPER::duplicate(@_);
# return $newAsset;
#}
#-------------------------------------------------------------------
=head2 ems
returns the ems ansestor of this asset
=cut
sub ems {
my $self = shift;
$self->getParent
}
#-------------------------------------------------------------------
=head2 www_editSubmissionForm ( [ parent, ] [ params ] )
create an html form for user to enter params for a new submissionForm asset
=head3 parent
the parent ems object -- needs to be passed only if this is a class level call
=head3 params
optional set of possibly incorrect submission form params
=cut
sub www_editSubmissionForm {
my $this = shift;
my $self;
my $parent;
if( $this eq __PACKAGE__ ) { # called as constructor or menu
$parent = shift;
} else {
$self = $this;
$parent = $self->getParent;
}
my $params = shift || { };
my $session = $parent->session;
my $i18n = WebGUI::International->new($session,'Asset_EventManagementSystem');
my $assetId = $self ? $self->getId : $params->{assetId} || $session->form->get('assetId');
if( ! defined( $assetId ) ) {
my $res = $parent->getLineage(['children'],{ returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
if( scalar(@$res) == 1 ) {
$self = $res->[0];
$assetId = $self->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->(
$_->getQueueUrl,
$_->get('title'),
WebGUI::HTML::filter($_->get('description'),'all')
)
} ( @$res ) );
my $title = $i18n->get('select form to edit') ;
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);
if (!defined($self)) {
$session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $assetId");
}
}
my $asset = $self || $parent;
my $url = $asset->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/;
my $fields;
my @defs = reverse @{WebGUI::Asset::EMSSubmission->definition($session)};
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;
};
}
}
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};
$fields->{$metaField->{fieldId}}{hoverHelp} = $metaField->{helpText};
}
$newform->hidden( name => 'fieldNames', value => join( ' ', @fieldNames ) );
@defs = reverse @{WebGUI::Asset::EMSSubmissionForm->definition($session)};
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} ) {
my %fieldParams = %{$properties->{$fieldName}};
$fieldParams{name} = $fieldName;
$fieldParams{value} = $params->{$fieldName} || $self ? $self->get($fieldName) : undef ;
$newform->dynamicField(%fieldParams);
}
}
}
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},
name => $field->{fieldId} . '_yesNo',
defaultValue => 0,
value => $formDescription->{$field->{fieldId}},
);
}
$newform->submit;
my $title = $assetId eq 'new' ? $i18n->get('new form') || 'new' : $asset->get('title');
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'));
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 );
}
}
#-------------------------------------------------------------------
=head2 www_editSubmissionFormSave
test and save new params
=cut
sub www_editSubmissionFormSave {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
my $formParams = $self->processForm();
if( $formParams->{_isValid} ) {
delete $formParams->{_isValid};
$self->addRevision($formParams);
WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session);
$self = $self->cloneFromDb;
return $self->getParent->www_viewSubmissionQueue;
} else {
return $self->www_editSubmissionForm($formParams);
}
}
#-------------------------------------------------------------------
=head2 www_view
calls ems->view
=cut
sub www_view { $_[0]->ems->www_viewSubmissionQueue }
#-------------------------------------------------------------------
=head2 getFormDescription
returns a hash ref decoded from the JSON in the form description field
=cut
sub getFormDescription {
my $self = shift;
return JSON->new->decode($self->get('formDescription'));
}
#-------------------------------------------------------------------
=head2 getQueueUrl
returns the URL for the submission queue page with the submisison id in the hash part
=cut
sub getQueueUrl {
my $self = shift;
return $self->ems->getUrl('func=viewSubmissionQueue#' . $self->getId );
}
#-------------------------------------------------------------------
=head2 view ( )
method called by the container www_view method.
Note: this really shouldn't get called, all views are redirected elsewhere
=cut
sub view {
my $self = shift;
return $self->ems->view;
#my $var = $self->get; # $var is a hash reference.
#$var->{controls} = $self->getToolbar;
#return $self->processTemplate( $var, undef, $self->{_viewTemplate} );
}
#----------------------------------------------------------------
=head2 www_addSubmission ( )
calls www_editSubmission with assetId == new
=cut
sub www_addSubmission {
my $self = shift;
$self->www_editSubmission( { assetId => 'new' } );
}
#-------------------------------------------------------------------
=head2 www_edit ( )
Web facing method which is the default edit page. Unless the method needs
special handling or formatting, it does not need to be included in
the module.
=cut
sub www_edit {
my $self = shift;
my $session = $self->session;
return $session->privilege->insufficient() unless $self->canEdit;
return $session->privilege->locked() unless $self->canEditIfLocked;
my $i18n = WebGUI::International->new( $session, 'Asset_EMSSubmissionForm' );
return $self->getAdminConsole->render( $self->getEditForm->print, $i18n->get('edit asset') );
}
#-------------------------------------------------------------------
=head2 www_editSubmission { params }
calls WebGUI::Asset::EMSSubmission->editSubmission
=cut
sub www_editSubmission {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return WebGUI::Asset::EMSSubmission->www_editSubmission($self,shift);
}
#-------------------------------------------------------------------
=head2 www_editSubmissionSave
validate and create a new submission
=cut
sub www_editSubmissionSave {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
my $formParams = WebGUI::Asset::EMSSubmission->processForm($self);
if( $formParams->{_isValid} ) {
delete $formParams->{_isValid};
$self->addSubmission($formParams);
return $self->getParent->www_viewSubmissionQueue;
} else {
return $self->www_editSubmission($formParams);
}
}
#----------------------------------------------------------------
=head2 processForm ( $parent )
pull data componenets out of $session->form
=head3 parent
reference to the EMS asset that is parent to the new submission form asset
=cut
sub processForm {
my $this = shift;
my $form;
my $session;
if( $this eq __PACKAGE__ ) {
my $parent = shift;
$session = $parent->session;
$form = $session->form;
} elsif( ref $this eq __PACKAGE__ ) {
$session = $this->session;
$form = $session->form;
} else {
return {_isValid => 0, errors => [ { text => 'invalid function call' } ] };
}
my $params = {_isValid=>1};
for my $fieldName ( qw/assetId title menuTitle url description canSubmitGroupId daysBeforeCleanup
deleteCreatedItems submissionDeadline pastDeadlineMessage/ ) {
$params->{$fieldName} = $form->get($fieldName);
}
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;
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmissionForm" );
push @{$params->{errors}}, {text => $i18n->get('turn on one field') };
}
return $params;
}
#-------------------------------------------------------------------
=head2 update ( )
We overload the update method from WebGUI::Asset in order to handle file system privileges.
=cut
sub update {
my $self = shift;
my $properties = shift;
if( ref $properties->{formDescription} eq 'HASH' ) {
$properties->{formDescription} = JSON->new->encode($properties->{formDescription});
}
$self->SUPER::update({%$properties, isHidden => 1});
}
1;
#vim:ft=perl

View file

@ -1,6 +1,5 @@
package WebGUI::Asset::Wobject::EventManagementSystem;
=head1 LEGAL
-------------------------------------------------------------------
@ -36,89 +35,6 @@ use WebGUI::Workflow::Instance;
use Tie::IxHash;
use Data::Dumper;
#-------------------------------------------------------------------
=head2 addGroupToSubmitList ( groupId )
adds the parameter to eventSubmissionGroups
=cut
sub addGroupToSubmitList {
my $self = shift;
my $groupId = shift;
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 ) });
}
#-------------------------------------------------------------------
=head2 addSubmissionForm
creates a child of class WG::Asset::EMSSubmissionForm
=head3 params
parameters that define the form
=head4 title
the title for the form
=head4 canSubmitGroupId ( optional )
group id for the users that are allowed to submit via this form
defaults to 2 -- registered users
=head4 daysBeforeCleanup ( optional )
number fo days to leave denied/created status items in the database before deleting
defaults to 7
=head4 deleteCreatedItems ( optional )
1 indicates that items with status 'created' should be deleted as well as denied
default: 0
=head4 formDescription
a JSON description of the form data fields -- a hash of the names of fields (each is 1 for active, 0 for inactive) plus
'_fieldList' added as an ARRAYREF of the fields that are active
=cut
sub addSubmissionForm {
my $self = shift;
my $params = shift;
$params->{className} = 'WebGUI::Asset::EMSSubmissionForm';
$params->{canSubmitGroupId} ||= 2;
$self->addGroupToSubmitList($params->{canSubmitGroupId});
my $newAsset = $self->addChild($params);
WebGUI::VersionTag->autoCommitWorkingIfEnabled($self->session);
$self = $self->cloneFromDb;
return $newAsset;
}
#-------------------------------------------------------------------
=head2 canSubmit
returns true is the current user can submit to any form attached to this EMS
=cut
sub canSubmit {
my $self = shift;
my $user = $self->session->user;
return 0 if ! $self->hasSubmissionForms;
for my $groupId (split ' ', $self->get('eventSubmissionGroups')) {
return 1 if $user->isInGroup($groupId);
}
return 0;
}
#-------------------------------------------------------------------
sub definition {
@ -191,30 +107,6 @@ sub definition {
hoverHelp => $i18n->get('print ticket template help'),
namespace => 'EMS/PrintTicket',
},
eventSubmissionMainTemplateId => {
fieldType => 'template',
defaultValue => 'DoVNijm6lMDE0cYrtvEbDQ',
tab => 'display',
label => $i18n->get('event submission main template'),
hoverHelp => $i18n->get('event submission main template help'),
namespace => 'EMS/SubmissionMain',
},
eventSubmissionTemplateId => {
fieldType => 'template',
defaultValue => '8tqyQx-LwYUHIWOlKPjJrA',
tab => 'display',
label => $i18n->get('event submission template'),
hoverHelp => $i18n->get('event submission template help'),
namespace => 'EMS/Submission',
},
eventSubmissionQueueTemplateId => {
fieldType => 'template',
defaultValue => 'ktSvKU8riGimhcsxXwqvPQ',
tab => 'display',
label => $i18n->get('event submission queue template'),
hoverHelp => $i18n->get('event submission queue template help'),
namespace => 'EMS/SubmissionQueue',
},
printRemainingTicketsTemplateId => {
fieldType => 'template',
defaultValue => 'hreA_bgxiTX-EzWCSZCZJw',
@ -225,8 +117,8 @@ sub definition {
},
badgeInstructions => {
fieldType => 'HTMLArea',
defaultValue => $i18n->get('default badge instructions'),
tab => 'properties',
defaultValue => $i18n->get('default badge instructions'),
tab => 'properties',
label => $i18n->get('badge instructions'),
hoverHelp => $i18n->get('badge instructions help'),
},
@ -258,25 +150,6 @@ sub definition {
label => $i18n->get('registration staff group'),
hoverHelp => $i18n->get('registration staff group help'),
},
submittedLocationsList => {
fieldType => 'text',
tab => 'properties',
defaultValue => '',
label => $i18n->get('submitted location list label'),
hoverHelp => $i18n->get('submitted location list help'),
},
eventSubmissionGroups => {
fieldType => 'hidden',
defaultValue => '',
noFormPost => 1,
},
nextSubmissionId => {
tab => "properties",
fieldType => "integer",
defaultValue => 1,
label => $i18n->get("next submission id label"),
hoverHelp => $i18n->get("next submission id label help")
},
);
push(@{$definition}, {
assetName=>$i18n->get('assetName'),
@ -305,21 +178,6 @@ 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 ()
@ -418,7 +276,6 @@ sub getEventFieldsForImport {
type => $field->{dataType},
options => $field->{possibleValues},
defaultValue => $field->{defaultValues},
helpText => $field->{defaultValues},
});
}
return \@fields;
@ -435,7 +292,7 @@ may be SQL optimized for quick access
sub getLocations {
my $self = shift;
my $dateRef = shift;
my $dateRef = shift || [ ];
my %hash;
my %hashDate;
@ -444,30 +301,13 @@ sub getLocations {
# this is a really compact 'uniq' operation
my @locations = map { $h{$_}++ == 0 ? $_ : () } ( map { $_->get('location') } ( @$tickets ) );
# the dates have the time data removed with a pattern substitution
if( $dateRef ) {
push @$dateRef, map { s/\s*\d+:\d+(:\d+)?//; $h{$_}++ == 0 ? $_ : () } ( map { $_->get('startDate') } ( @$tickets ) );
}
push @$dateRef, map { s/\s*\d+:\d+(:\d+)?//; $h{$_}++ == 0 ? $_ : () } ( map { $_->get('startDate') } ( @$tickets ) );
return @locations;
}
#-------------------------------------------------------------------
=head2 getNextSubmissionId
get a sequence number for the submission id
=cut
sub getNextSubmissionId {
my $self = shift;
my ($submissionId) = $self->session->db->read('select nextSubmissionId from EventManagementSystem where assetId = ?', [ $self->getId ] )->array;
$self->update( { nextSubmissionId => ($submissionId + 1) } );
return $submissionId;
}
#-------------------------------------------------------------------
=head2 getRegistrant ( badgeId )
Returns a hash reference containing the properties of a registrant.
@ -498,49 +338,6 @@ sub getRibbons {
#-------------------------------------------------------------------
=head2 getSubmissionLocations
retuns an arrayref of the locations found in the submission location list
=cut
sub getSubmissionLocations {
my $self = shift;
my $text = $self->get('submittedLocationsList');
return undef if $text eq '';
return [ split( /\s+/, $text ) ];
}
#-------------------------------------------------------------------
sub getSubmissionStatus {
my $self = shift;
my $key = shift;
unless ($self->{_status}) {
tie my %hash, "Tie::IxHash";
my $i18n = $self->i18n;
for my $item (
'pending',
'feedback',
'denied',
'approved',
'created',
'failed',
) {
$hash{$item} = $i18n->get($item),
}
$self->{_status} = \%hash;
}
if($key) {
return $self->{_status}{$key};
}
return $self->{_status};
}
#-------------------------------------------------------------------
=head2 getTickets ()
Returns an array reference of ticket objects.
@ -576,54 +373,6 @@ sub getTokens {
#-------------------------------------------------------------------
=head2 hasSubmissionForms
returns true if the EMS has subission forms attached
=cut
sub hasSubmissionForms {
my $self = shift;
# are there ~any~ forms attached to this ems?
my $res = $self->getLineage(['children'],{ limit => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
return scalar(@$res);
}
#-------------------------------------------------------------------
=head2 hasSubmissions
returns true if the current user has submission forms in this EMS
=cut
sub hasSubmissions {
my $self = shift;
return 0 if ! $self->canSubmit;
my $res = $self->getLineage(['descendants'],{ limit => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
whereClause => q{createdBy='} . $self->session->user->userId . q/'/,
} );
return scalar(@$res);
}
#-------------------------------------------------------------------
=head2 i18n
returns the internationalisation object for this asset
=cut
sub i18n {
my $self = shift;
return $self->{_i18n} ||= WebGUI::International->new($self->session,'Asset_EventManagementSystem');
}
#-------------------------------------------------------------------
=head2 isRegistrationStaff ( [ user ] )
Returns a boolean indicating whether the user is a member of the registration staff.
@ -717,16 +466,9 @@ sub view {
addBadgeUrl => $self->getUrl('func=add;class=WebGUI::Asset::Sku::EMSBadge'),
buildBadgeUrl => $self->getUrl('func=buildBadge'),
viewScheduleUrl => $self->getUrl('func=viewSchedule'),
addSubmissionUrl => $self->getUrl('func=viewSubmissionQueue#addSubmission'),
viewSubmissionQueueUrl => $self->getUrl('func=viewSubmissionQueue'),
addSubmissionFormUrl => $self->getUrl('func=viewSubmissionQueue#addSubmissionForm'),
manageBadgeGroupsUrl=> $self->getUrl('func=manageBadgeGroups'),
getBadgesUrl => $self->getUrl('func=getBadgesAsJson'),
isRegistrationStaff => $self->isRegistrationStaff,
canEdit => $self->canEdit,
canSubmit => $self->canSubmit,
hasSubmissions => $self->hasSubmissions,
hasSubmissionForms => $self->hasSubmissionForms,
canEdit => $self->canEdit,
lookupRegistrantUrl => $self->getUrl('func=lookupRegistrant'),
);
@ -757,77 +499,6 @@ 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 $session = $self->session;
my $formId = $params->{formId} || $session->form->get('formId');
my $i18n = WebGUI::International->new($session,'Asset_EventManagementSystem');
my $form;
if( ! defined $formId ) {
my $res = $self->getLineage(['children'],{ returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
my @new = map { $_->canSubmit ? $_ : () } ( @$res);
if( scalar(@new) == 0 ) {
return $self->www_view;
} elsif( scalar(@new) == 1 ) {
$form = $new[0];
$formId = $form->getId;
} else {
my $makeAnchorList =sub{ my $u=shift; my $n=shift; my $d=shift;
return qq{<li><a href='$u' onclick='WebGUI.EMS.loadItemFromAnchor(this)' title='$d'>$n</a></li>} } ;
my $listOfLinks = join '', ( map {
$makeAnchorList->(
$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 ) );
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>' ;
if( $asJson ) {
return JSON->new->encode( { text => $content, title => $title, id => 'list' . rand } );
} else {
return $self->ProcessStyle( $content );
}
}
}
$form = WebGUI::Asset->newByDynamicClass($session,$formId);
if (!defined $form) {
$session->errorHandler->error(__PACKAGE__ . " - failed to instanciate asset with assetId $formId");
}
return $form->www_addSubmission;
}
#-------------------------------------------------------------------
=head2 www_addSubmissionForm ()
call www_editSubmissionForm with assetId == new
=cut
sub www_addSubmissionForm {
my $self = shift;
$self->www_editSubmissionForm( { assetId => 'new' } );
}
#-------------------------------------------------------------------
=head2 www_addTicketsToBadge ()
Adds selected tickets to a badge. Expects two form parameters, assetId (multiples fine) and badgeId, where assetId represents the ticket and badgeId represents the badge.
@ -1005,62 +676,6 @@ sub www_editBadgeGroupSave {
#-------------------------------------------------------------------
=head2 www_editSubmission
use getLineage to find the item to edit based on submissionId
then call www_editSubmission on it
=cut
sub www_editSubmission {
my $self = shift;
my $submissionId = $self->session->form->get('submissionId');
my $asset = $self->getLineage(['descendants'], { returnObjects => 1,
joinClass => "WebGUI::Asset::EMSSubmission",
whereClause => 'submissionId = ' . int($submissionId),
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
} );
return $asset->[0]->www_editSubmission;
}
#-------------------------------------------------------------------
=head2 www_editSubmissionForm
calls editSubmissionForm in WebGUI::Asset::EMSSubmissionForm
=cut
sub www_editSubmissionForm {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->isRegistrationStaff || $self->canEdit;
return WebGUI::Asset::EMSSubmissionForm->www_editSubmissionForm($self,shift);
}
#-------------------------------------------------------------------
=head2 www_editSubmissionFormSave
test and save data posted from editSubmissionForm...
=cut
sub www_editSubmissionFormSave {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->isRegistrationStaff;
my $formParams = WebGUI::Asset::EMSSubmissionForm->processForm($self);
if( $formParams->{_isValid} ) {
delete $formParams->{_isValid};
$self->addSubmissionForm($formParams);
return $self->www_viewSubmissionQueue;
} else {
return $self->www_editSubmissionForm($formParams);
}
}
#-------------------------------------------------------------------
=head2 www_editEventMetaField ( )
Displays the edit form for event meta fields.
@ -1087,7 +702,6 @@ sub www_editEventMetaField {
required => $self->session->form->process("required",'yesNo'),
possibleValues => $self->session->form->process("possibleValues",'textarea'),
defaultValues => $self->session->form->process("defaultValues",'textarea'),
helpText => $self->session->form->process("helpText",'textarea'),
};
$f->readOnly(
-name => 'error',
@ -1144,12 +758,6 @@ sub www_editEventMetaField {
-hoverHelp => $i18n->get('488 description'),
-value => $data->{defaultValues},
);
$f->textarea(
-name => "helpText",
-label => $i18n2->get('meta field help text'),
-hoverHelp => $i18n2->get('meta field help text description'),
-value => $data->{helpText},
);
$f->submit;
return $self->processStyle($f->print);
}
@ -1182,7 +790,6 @@ sub www_editEventMetaFieldSave {
required => $self->session->form->process("required",'yesNo'),
possibleValues => $self->session->form->process("possibleValues",'textarea'),
defaultValues => $self->session->form->process("defaultValues",'textarea'),
helpText => $self->session->form->process("helpText",'textarea'),
},1,1);
return $self->www_manageEventMetaFields();
}
@ -1267,90 +874,6 @@ sub www_exportEvents {
return "chunked";
}
#----------------------------------------------------------------------------
=head2 www_getAllSubmissions ( )
Get a page of Asset Manager data, ajax style. Returns a JSON array to be
formatted in a WebGUI submission queue data table.
=cut
sub www_getAllSubmissions {
my $self = shift;
my $session = $self->session;
my $datetime = $session->datetime;
my $form = $session->form;
my $tableInfo = {};
return $session->privilege->insufficient unless $self->canSubmit || $self->isRegistrationStaff;
my $orderByColumn = $form->get( 'orderByColumn' ) || $self->get("sortColumn");
my $dir = $form->get('orderByDirection') || $self->get('sortOrder');
my $orderByDirection = lc ($dir) eq "asc" ? "ASC" : "DESC";
my $whereClause ;
if(!$self->isRegistrationStaff) {
my $userId = $session->user->userId;
$whereClause .= qq{ createdBy='$userId'};
}
my $rules;
$rules->{'joinClass' } = "WebGUI::Asset::EMSSubmission";
$rules->{'whereClause' } = $whereClause;
$rules->{'includeOnlyClasses'} = ['WebGUI::Asset::EMSSubmission'];
$rules->{'orderByClause' } = $session->db->dbh->quote_identifier( $orderByColumn ) . ' ' . $orderByDirection if $orderByColumn;
my $sql = "";
$sql = $self->getLineageSql(['descendants'], $rules);
my $startIndex = $form->get( 'startIndex' ) || 1;
my $rowsPerPage = $form->get( 'rowsPerPage' ) || 25;
my $currentPage = int ( $startIndex / $rowsPerPage ) + 1;
my $p = WebGUI::Paginator->new( $session, '', $rowsPerPage, 'pn', $currentPage );
$p->setDataByQuery($sql);
$tableInfo->{'recordsReturned'} = $rowsPerPage;
$tableInfo->{'totalRecords' } = $p->getRowCount;
$tableInfo->{'startIndex' } = $startIndex;
$tableInfo->{'sort' } = $orderByColumn;
$tableInfo->{'dir' } = $orderByDirection;
$tableInfo->{'records' } = [];
for my $record ( @{ $p->getPageData } ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $record->{assetId} );
my $lastReplyBy = $asset->get("lastReplyBy");
if ($lastReplyBy) {
$lastReplyBy = WebGUI::User->new($session,$lastReplyBy)->username;
}
# Populate the required fields to fill in
my $lastReplyDate = $asset->get("lastReplyDate");
if($lastReplyDate) {
$lastReplyDate = $datetime->epochToHuman($lastReplyDate,"%y-%m-%d @ %H:%n %p");
}
my %fields = (
submissionId => $asset->get("submissionId"),
url => $asset->getQueueUrl,
title => $asset->get( "title" ),
createdBy => WebGUI::User->new($session,$asset->get( "createdBy" ))->username,
creationDate => $datetime->epochToSet($asset->get( "creationDate" )),
submissionStatus => $self->getSubmissionStatus($asset->get( "submissionStatus" ) || 'pending' ),
lastReplyDate => $lastReplyDate || '',
lastReplyBy => $lastReplyBy || '',
);
push @{ $tableInfo->{ records } }, \%fields;
}
$session->http->setMimeType( 'application/json' );
return JSON->new->encode( $tableInfo );
}
#-------------------------------------------------------------------
=head2 www_getBadgesAsJson ()
@ -1389,36 +912,6 @@ sub www_getBadgesAsJson {
#-------------------------------------------------------------------
=head2 www_getSubmissionById
returns a JSON dataset with info about the requested submission
=cut
sub www_getSubmissionById {
my $self = shift;
my $submissionId = $self->session->form->get('submissionId');
my $result;
my $res = $self->getLineage(['descendants'],{ limit => 1, returnObjects=>1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
joinClass => "WebGUI::Asset::EMSSubmission",
whereClause => q{submissionId='} . $submissionId . q/'/,
} );
if( scalar(@$res) == 0 ) {
$result->{hasError} = 1;
$result->{errors} = [ 'failed to load submission' ];
} else {
$result->{text} = $res->[0]->www_editSubmission;
$result->{title} = $submissionId;
$result->{id} = $submissionId;
}
$self->session->http->setMimeType('application/json');
return JSON->new->encode($result);
}
#-------------------------------------------------------------------
=head2 www_getRegistrantAsJson ( )
Retrieves the properties of a specific badge and the items attached to it. Expects badgeId to be one of the form params.
@ -1761,6 +1254,8 @@ sub www_getScheduleDataJSON {
return JSON->new->encode(\%results);
}
#-------------------------------------------------------------------
=head2 www_getTicketsAsJson ()
@ -2640,6 +2135,7 @@ View the schedule table.
sub www_viewSchedule {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canView;
my $db = $self->session->db;
my $rowsPerPage = 25;
my $locationsPerPage = $self->get('scheduleColumnsPerPage');
@ -2660,60 +2156,5 @@ sub www_viewSchedule {
}
#---------------------------------------------
=head2 www_viewSubmissionQueue
=cut
sub www_viewSubmissionQueue {
my $self = shift;
my $isRegistrationStaff = $self->isRegistrationStaff;
my $canSubmit = $self->canSubmit;
my $canEdit = $self->canEdit;
my $i18n = $self->i18n;
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 { { # 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'],
} ) }
);
my $params = {
backUrl => $self->getUrl,
isRegistrationStaff => $isRegistrationStaff,
canEdit => $canEdit,
canSubmit => $canSubmit,
hasSubmissionForms => $self->hasSubmissionForms,
getSubmissionQueueDataUrl => $self->getUrl('func=getAllSubmissions'),
editSubmissionUrl => $self->getUrl('func=viewSubmissionQueue#editSubmission'),
editSubmissionFormUrl => $self->getUrl('func=viewSubmissionQueue#editSubmissionForm'),
addSubmissionFormUrl => $self->getUrl('func=viewSubmissionQueue#addSubmissionForm'),
addSubmissionUrl => $self->getUrl('func=viewSubmissionQueue#addSubmission'),
editSubmissionAjaxUrl => $self->getUrl('func=editSubmission'),
editSubmissionFormAjaxUrl => $self->getUrl('func=editSubmissionForm'),
addSubmissionFormAjaxUrl => $self->getUrl('func=addSubmissionForm'),
addSubmissionAjaxUrl => $self->getUrl('func=addSubmission'),
submissionFormUrls => \@submissionFormUrls,
queueTabTitle => $isRegistrationStaff ? $i18n->get('submission queue') : $i18n->get('my submissions'),
};
$params->{QueueTabData} = $self->processTemplate($params,$self->get('eventSubmissionQueueTemplateId'));
return $self->processStyle(
$self->processTemplate( $params, $self->get('eventSubmissionMainTemplateId')));
}
1;