diff --git a/lib/WebGUI/Asset/EMSSubmission.pm b/lib/WebGUI/Asset/EMSSubmission.pm index c9ad97016..bc8b2d45d 100644 --- a/lib/WebGUI/Asset/EMSSubmission.pm +++ b/lib/WebGUI/Asset/EMSSubmission.pm @@ -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 ( ) diff --git a/lib/WebGUI/Asset/EMSSubmissionForm.pm b/lib/WebGUI/Asset/EMSSubmissionForm.pm index dd2de5d7f..a01365481 100644 --- a/lib/WebGUI/Asset/EMSSubmissionForm.pm +++ b/lib/WebGUI/Asset/EMSSubmissionForm.pm @@ -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); +#} #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index 97e0410eb..bbaec3ff5 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -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; diff --git a/lib/WebGUI/Form/Div.pm b/lib/WebGUI/Form/Div.pm new file mode 100644 index 000000000..7e38abe85 --- /dev/null +++ b/lib/WebGUI/Form/Div.pm @@ -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 '