started adding functionality, somethings look OK still long ways to go for base functionality

This commit is contained in:
daviddelikat 2009-10-07 10:41:03 -05:00
parent ccc9e36e25
commit 03a0279040
8 changed files with 443 additions and 60 deletions

View file

@ -85,6 +85,7 @@ sub definition {
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,
@ -102,29 +103,29 @@ sub definition {
tab => "shop",
fieldType => "text",
defaultValue => $session->id->generate,
label => $i18n->get("sku"),
hoverHelp => $i18n->get("sku help")
label => $SKU_i18n->get("sku"),
hoverHelp => $SKU_i18n->get("sku help")
},
displayTitle => {
tab => "display",
fieldType => "yesNo",
defaultValue => 1,
label => $i18n->get("display title"),
hoverHelp => $i18n->get("display title help")
label => $SKU_i18n->get("display title"),
hoverHelp => $SKU_i18n->get("display title help")
},
vendorId => {
tab => "shop",
fieldType => "vendor",
defaultValue => 'defaultvendor000000000',
label => $i18n->get("vendor"),
hoverHelp => $i18n->get("vendor help")
label => $SKU_i18n->get("vendor"),
hoverHelp => $SKU_i18n->get("vendor help")
},
shipsSeparately => {
tab => 'shop',
fieldType => 'yesNo',
defaultValue => 0,
label => $i18n->get('shipsSeparately'),
hoverHelp => $i18n->get('shipsSeparately help'),
label => $SKU_i18n->get('shipsSeparately'),
hoverHelp => $SKU_i18n->get('shipsSeparately help'),
},
price => {
@ -185,8 +186,8 @@ sub definition {
},
sendEmailOnChange => {
tab => "properties",
fieldType => "text",
defaultValue => undef,
fieldType => "yesNo",
defaultValue => 1,
label => $i18n->get("send email label"),
hoverHelp => $i18n->get("send email label help")
},
@ -209,6 +210,71 @@ sub definition {
#-------------------------------------------------------------------
=head2 drawLocationField ()
Draws the field for the location property.
TODO: check form params for additional options
=cut
sub drawLocationField {
my ($self, $params) = @_;
my $options = $self->session->db->buildHashRef("select distinct(location) from EMSTicket left join asset using (assetId)
where parentId=? order by location",[$self->get('parentId')]);
return WebGUI::Form::combo($self->session, {
name => 'location',
value => $self->get('location'),
options => $options,
});
}
#-------------------------------------------------------------------
=head2 drawRelatedBadgeGroupsField ()
Draws the field for the relatedBadgeGroups property.
TODO: check form params for additional options
=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->getBadgeGroups,
});
}
#-------------------------------------------------------------------
=head2 drawRelatedRibbonsField ()
Draws the field for the relatedRibbons property.
TODO: check form params for additional options
=cut
sub drawRelatedRibbonsField {
my ($self, $params) = @_;
my %ribbons = ();
foreach my $ribbon (@{$self->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 duplicate
This method exists for demonstration purposes only. The superclass
@ -223,6 +289,49 @@ whenever a copy action is executed
# return $newAsset;
#}
#-------------------------------------------------------------------
=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...
$comments->div({name => 'comments',
contentCallback => sub { $self->getFormattedComments },
});
return $tabform;
}
#-------------------------------------------------------------------
=head2 getEditTabs ( )
Not to be modified, just 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 indexContent ( )

View file

@ -17,6 +17,7 @@ package WebGUI::Asset::EMSSubmissionForm;
use strict;
use Tie::IxHash;
use base 'WebGUI::Asset';
use JSON;
use WebGUI::Utility;
# TODO:
@ -55,21 +56,22 @@ These methods are available from this class:
=head2 addSubmission
Creates an EMSSubmission object based on the params
( called by www_saveSubmission )
=cut
sub addSubmission {
my $self = shift;
my $parent = $self->getParent;
my $session = $self->session;
my $params = shift || {};
$self->validateSubmission($params);
$parent->addChild({
className => 'WebGUI::Asset::EMSSubmission',
status => 'pending',
title => $params->{title},
# TODO add all the fields...
});
return undef if $self->canSubmit;
return undef unless $self->validateSubmission($params);
for my $param ( keys %{$self->getFormDefinition()} ) {
}
$params->{className} = 'WebGUI::Asset::EMSSubmission';
$params->{status} = 'pending';
$self->addChild($params);
}
#-------------------------------------------------------------------
@ -89,6 +91,20 @@ handles revisions to NewAsset Assets.
#-------------------------------------------------------------------
=head2 canSubmit
returns true if current user can submit using this form
=cut
sub canSubmit {
my $self = shift;
return $session->user->isInGroup($self->get('canSubmitGroupId');
}
#-------------------------------------------------------------------
=head2 definition ( session, definition )
defines asset properties for New Asset instances. You absolutely need
@ -117,8 +133,8 @@ sub definition {
},
canSubmitGroupId => {
tab => "security",
fieldType => "groupid",
defaultValue => undef,
fieldType => "group",
defaultValue => 2,
label => $i18n->get("can submit group label"),
hoverHelp => $i18n->get("can submit group label help")
},
@ -131,22 +147,29 @@ sub definition {
},
deleteCreatedItems => {
tab => "properties",
fieldType => "yesno",
defaultValue => 'no',
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 => undef,
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 => "text",
defaultValue => undef,
fieldType => "textarea",
defaultValue => '{ }',
label => $i18n->get("form dscription label"),
hoverHelp => $i18n->get("form dscription label help")
},
@ -158,7 +181,7 @@ sub definition {
tableName => 'EMSSubmissionForm',
className => 'WebGUI::Asset::EMSSubmissionForm',
properties => \%properties,
};
};
return $class->SUPER::definition( $session, $definition );
} ## end sub definition
@ -180,17 +203,31 @@ whenever a copy action is executed
#-------------------------------------------------------------------
=head2 getFormDefinition
returns a hash ref decoded from the JSON in the form description field
=cut
sub getFormDefinition {
my $self = shift;
return JSON->new->decode($self->get('formDescription'));
}
#-------------------------------------------------------------------
=head2 indexContent ( )
Making private. See WebGUI::Asset::indexContent() for additonal details.
=cut
sub indexContent {
my $self = shift;
my $indexer = $self->SUPER::indexContent;
$indexer->setIsPublic(0);
}
#sub indexContent {
# my $self = shift;
# my $indexer = $self->SUPER::indexContent;
# $indexer->setIsPublic(0);
#}
#-------------------------------------------------------------------

View file

@ -36,6 +36,59 @@ use Tie::IxHash;
use Data::Dumper;
#-------------------------------------------------------------------
=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 t0 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
TODO: write a comprehensive doc for this field
=cut
sub addSubmissionForm {
my $self = shift;
my $params = shift;
$params{className} = 'WebGUI::Asset::EMSSubmissionForm';
$params{canSubmitGroupId} ||= 2;
$self->addGroupToSubmitList($params{canSubmitGroupId});
# DOING -- add previous function and finish adding operations to this function
# TODO re-edit the Badge view template and save it, see that it gets added after resets
# TODO see how hard it would be to dump the whole template class to the file system
# also how hard is it to sync it?
# perhaps there is a way to write a module based on the test system that would be simple enough
# to look for new versions of the templates and save it off to the file system -- also notice
# when the file system is newer than the database ad load the file.
#-- ultimate goal is to figure out what is failing in the test battery...
# also add tests for Form_Div
}
#-------------------------------------------------------------------
=head2 canSubmit
@ -427,7 +480,12 @@ returns true if the EMS has subission forms attached
=cut
sub hasForms {
return 0;
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);
}
#-------------------------------------------------------------------
@ -438,7 +496,13 @@ returns true if the current user has submission forms in this EMS
=cut
sub hasSubmissions {
return 0;
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);
}
#-------------------------------------------------------------------
@ -2157,5 +2221,28 @@ sub www_viewSchedule {
}
#---------------------------------------------
=head2 www_viewSubmission
=cut
sub www_viewSubmission {
# fill the view submission template
}
#---------------------------------------------
=head2 www_viewSubmissionQueue
=cut
sub www_viewSubmissionQueue {
# fill the view submission queue template
}
1;

114
lib/WebGUI/Form/Div.pm Normal file
View file

@ -0,0 +1,114 @@
package WebGUI::Form::Div;
=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 base 'WebGUI::Form::Control';
use WebGUI::International;
=head1 NAME
Package WebGUI::Form::Div
=head1 DESCRIPTION
dreates a HTML div element with contents provided by caller
=head1 SEE ALSO
This is a subclass of WebGUI::Form::Control.
=head1 METHODS
The following methods are specifically available from this class. Check the superclass for additional methods.
=cut
#-------------------------------------------------------------------
=head2 definition ( [ additionalTerms ] )
See the super class for additional details.
=head3 usage
$form->div({
contentCallback => sub { $self->getDivContents(shift); }
});
=head3 additionalTerms
The following additional parameters have been added via this sub class.
=head4 contentCallback
A code enclosure which returns the html text to insert into the div element. The divId is passed as parameter 0 when it is called. This function MUST return good html text, it is NOT processed here at all.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift || [];
push(@{$definition}, {
contentCallback=>{
defaultValue=> sub { return '' },
},
});
return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
=head2 getName ( session )
Returns the name of the form control.
=cut
sub getName {
my ($class, $session) = @_;
return WebGUI::International->new($session, "Form_Div")->get("topicName");
}
#-------------------------------------------------------------------
=head2 getValue ( [ value ] )
Does some special processing.
=cut
sub getValue {
my $self = shift;
return $self->get('contentCallback')->($self->get('id'));
}
#-------------------------------------------------------------------
=head2 toHtml ( )
Renders an input tag of type text.
=cut
sub toHtml {
my $self = shift;
return '<div id="'.$self->get('id').'" name="'.$self->get("name").'" '.$self->get("extras").'>' . $self->getValue . '</div>' ;
}
1;
#vim:ft=perl

View file

@ -20,6 +20,12 @@ our $I18N = { ##hashref of hashes
context => q|This is the help text for the 'send email' flag. If set to 'Yes', the user will recieve email for every change made to the submission.|
},
'comments' => {
message => q|Comments|,
lastUpdated => 1131394072,
context => q|Label for the comments tab.|
},
# 'TODO' => {
# message => q|TODO|,
# lastUpdated => 1131394072,

View file

@ -75,7 +75,7 @@ our $I18N = { ##hashref of hashes
context => q|This is the default message for informing the user that the submission deadline is past.|
},
'past deadline label' => {
message => q|Post SUbmission Deadline Text|,
message => q|Past Submission Deadline Text|,
lastUpdated => 1131394072,
context => q|This is the label for the message indicating that the deadline for submissions has past.|
},
@ -85,6 +85,18 @@ our $I18N = { ##hashref of hashes
context => q|This help text should describe how the user tells submitters that the submission deadline has past.|
},
'submission deadline label' => {
message => q|Submission Deadline|,
lastUpdated => 1131394072,
context => q|Label for the submission deadline field|
},
'submission deadline label help' => {
message => q|Enter a date after which no more new submissions will be taken.|,
lastUpdated => 1131394072,
context => q|Help text for the submission deadline field. After this date this submission form will not accept any more entries.|
},
# 'TODO' => {
# message => q|TODO|,
# lastUpdated => 1131394072,

View file

@ -0,0 +1,15 @@
package WebGUI::i18n::English::Form_Div;
use strict; ##Required for all good Perl::Critic compliant code
our $I18N = {
'topicName' => {
message => q|Form Control Div Element|,
lastUpdated => 1131394070, #seconds from the epoch
context => q|Name of the form control that generates HTML Div elements|
},
};
1;
#vim:ft=perl

View file

@ -18,6 +18,7 @@ use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use Test::Deep;
use JSON;
use WebGUI::Group;
use WebGUI::User;
use WebGUI::Test; # Must use this before any other WebGUI modules
@ -38,15 +39,15 @@ my $session = WebGUI::Test->session;
plan tests => 30; # Increment this number for each test you create
my $submitGroupA = WebGUI::Group->new($session,'new');
my $submitGroupB = WebGUI::Group->new($session,'new');
my $registrars = WebGUI::Group->new($session, 'new');
my $attendees = WebGUI::Group->new($session, 'new');
my $submitGroupA = WebGUI::Group->new($session,'new',{groupName=>'groupA'});
my $submitGroupB = WebGUI::Group->new($session,'new',{groupName=>'groupB'});
my $registrars = WebGUI::Group->new($session, 'new',{groupName=>'registrars'});
my $attendees = WebGUI::Group->new($session, 'new',{groupName=>'attendees'});
my $registrar = WebGUI::User->create($session);
my $userA = WebGUI::User->create($session);
my $userB = WebGUI::User->create($session);
my $userC = WebGUI::User->create($session);
my $registrar = WebGUI::User->create($session,{username=>'registrar'});
my $userA = WebGUI::User->create($session,{username=>'userA'});
my $userB = WebGUI::User->create($session,{username=>'userB'});
my $userC = WebGUI::User->create($session,{username=>'userC'});
$registrars->addUsers([$registrar->getId]);
$submitGroupA->addUsers([$userA->userId,$userC->userId]);
@ -121,21 +122,27 @@ loginRgstr;
is( $ems->hasForms, 0, 'ems currently has no forms' );
my $frmA = $ems->addChild({
#print 'press return to continue test' ; <>;
my $formAdesc = {
title => { type => 'text' },
descrition => { type => 'textarea' },
duration => { default => 2.0 },
startDate => { type => 'selectList',
options => [ '1255150800', '1255237200', '1255323600' ],
},
};
my $frmA = $ems->addSubmissionForm({
className => 'WebGUI::Asset::EMSSubmissionForm',
title => 'test A -- long',
canSubmitGroup => $submitGroupA->getId,
canSubmitGroupId => $submitGroupA->getId,
daysBeforeCleanup => 1,
formDescription => q{ {
'title' : { 'type' : 'text' },
'description' : { 'type' : 'textarea' },
'duration' : { 'default' : 2.0 },
'startDate' : { 'type' : 'selectList', 'options' :
[ '1255150800', '1255237200', '1255323600' ] },
} },
formDescription => to_json( $formAdesc ),
});
isa_ok( $frmA, 'WebGUI::Asset::EMSSubmissionForm' );
is( $ems->hasForms, 1, 'ems now has forms' );
is_deeply( $frmA->getFormDescription, $formAdesc, 'form description matches' );
ok( $frmA->validateSubmission({
title => 'titlea',
description => 'the description',
@ -146,12 +153,6 @@ ok( !$frmA->validateSubmission({
description => 'the description',
startDate => '1205150800',
}), 'not a valid submission: invalid value' );
ok( !$frmA->validateSubmission({
title => 'titlea',
price => 300.0,
description => 'the description',
startDate => '1255150800',
}), 'not a valid submission: invalid field' );
ok( !$frmA->validateSubmission({
title => 'titlea',
duration => 3.0,
@ -167,7 +168,7 @@ ok( $frmA->validateSubmission({
}), 'valid submission: field value override by admin' );
my $frmB = $ems->addChild({
my $frmB = $ems->addSubmissionForm({
className => 'WebGUI::Asset::EMSSubmissionForm',
title => 'test B -- short',
daysBeforeCleanup => 0,
@ -180,7 +181,6 @@ my $frmB = $ems->addChild({
'metaField1' : { 'type' : 'Url' },
} },
});
is( $ems->hasForms, 1, 'ems still has forms' );
ok( $frmA->validateSubmission({
title => 'title',
description => 'description',
@ -195,10 +195,13 @@ ok( !$frmA->validateSubmission({
logout;
is( $ems->canSubmit, 0, 'current user cannot submit to this ems' );
is( $frmA->canSubmit, 0, 'current user cannot submit to form' );
loginUserA;
is( $ems->canSubmit, 1, 'current user can submit to this ems' );
is( $frmA->canSubmit, 1, 'current user can submit to formA' );
is( $frmB->canSubmit, 0, 'current user cannot submit to formB' );
is( $ems->hasSubmissions, 0, 'current user has no submissions' );
# this one should work
my $sub1 = $frmA->addSubmission({
@ -286,7 +289,7 @@ run submission cleanup activity
$versionTag->commit;
#done_testing();
print 'press return to complete test' ; <>;
#----------------------------------------------------------------------------
# Cleanup
END {