From d114084a76516fbc5f4e767a0938a56a3001582f Mon Sep 17 00:00:00 2001 From: daviddelikat Date: Thu, 22 Oct 2009 11:11:18 -0500 Subject: [PATCH] started submission queue --- lib/WebGUI/Asset/EMSSubmission.pm | 97 ++++- lib/WebGUI/Asset/EMSSubmissionForm.pm | 319 +++++++++------ .../Asset/Wobject/EventManagementSystem.pm | 52 ++- t/Asset/EMSSubmissionForm.t | 4 +- www/extras/wobject/EMS/close12_1.gif | Bin 0 -> 85 bytes www/extras/wobject/EMS/indicator.gif | Bin 0 -> 1553 bytes www/extras/wobject/EMS/submission.js | 381 ++++++++++++++++++ 7 files changed, 697 insertions(+), 156 deletions(-) create mode 100644 www/extras/wobject/EMS/close12_1.gif create mode 100644 www/extras/wobject/EMS/indicator.gif create mode 100644 www/extras/wobject/EMS/submission.js diff --git a/lib/WebGUI/Asset/EMSSubmission.pm b/lib/WebGUI/Asset/EMSSubmission.pm index 8df62c682..1a7d9f17c 100644 --- a/lib/WebGUI/Asset/EMSSubmission.pm +++ b/lib/WebGUI/Asset/EMSSubmission.pm @@ -219,14 +219,13 @@ sub definition { 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')]); +# TODO get additional params from the EMS location list return WebGUI::Form::combo($self->session, { name => 'location', value => $self->get('location'), @@ -240,8 +239,6 @@ sub drawLocationField { Draws the field for the relatedBadgeGroups property. -TODO: check form params for additional options - =cut sub drawRelatedBadgeGroupsField { @@ -260,8 +257,6 @@ sub drawRelatedBadgeGroupsField { Draws the field for the relatedRibbons property. -TODO: check form params for additional options - =cut sub drawRelatedRibbonsField { @@ -296,6 +291,65 @@ whenever a copy action is executed #------------------------------------------------------------------- +=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 $assetId = $self ? $self->getId : $params->{assetId} || $session->form->get('assetId'); + + if( ! defined( $assetId ) ) { + # if somebody calls without an assetId then display the queue for the EMS (grandparent) + return $parent->getParent->www_viewSubmissionQueue; + } 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 $url = ( $self | $parent )->getUrl('func=editSubmissionSave'); + my $newform = WebGUI::HTMLForm->new($session,action => $url); + # DOING + # get the description from the parent + # for each field + # if field is active + # create a usable control + # else + # create a readonly control -- be sure to convert data where appropriate + # add the comment form + $newform->submit; + return $parent->processStyle( + $parent->processTemplate({ + errors => $params->{errors} || [], + backUrl => $parent->getUrl, + pageForm => $newform->print, + },$parent->get('eventSubmissionFormTemplateId'))); +} + +#------------------------------------------------------------------- + =head2 getEditForm ( ) Extends the base class to add Tax information for the Sku, in a new tab. @@ -367,6 +421,37 @@ sub prepareView { $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 + +use lib '/root/pb/lib'; use dav; + +sub processForm { + my $this = shift; + my $form; + if( $this eq __PACKAGE__ ) { + my $parent = shift; + $form = $parent->session->form; + } elsif( ref $this eq __PACKAGE__ ) { + $form = $this->session->form; + } else { + return {_isValid => 0, errors => [ { text => 'invalid function call' } ] }; + } + my $params = {_isValid=>1}; + # get description from parent + # for each active field + # get data from session->form +} + #------------------------------------------------------------------- =head2 processPropertiesFromFormPost ( ) diff --git a/lib/WebGUI/Asset/EMSSubmissionForm.pm b/lib/WebGUI/Asset/EMSSubmissionForm.pm index b990ee06c..e0c72068b 100644 --- a/lib/WebGUI/Asset/EMSSubmissionForm.pm +++ b/lib/WebGUI/Asset/EMSSubmissionForm.pm @@ -206,6 +206,144 @@ whenever a copy action is executed #------------------------------------------------------------------- +=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($parent->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{
  • $n
  • } } ; + my $listOfLinks = join '', ( map { + $makeAnchorList->( + $parent->getUrl('func=editSubmissionForm;assetId=' . $_->getId ), + $_->get('title'), + WebGUI::HTML::filter($_->get('description'),'all') + ) + } ( @$res ) ); + return $parent->processStyle( '

    ' . $i18n->get('select form to edit') . + '

    ' ); + } + } 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 url = ( $self || $parent )->getUrl('func=editSubmissionFormSave'); + my $newform = WebGUI::HTMLForm->new( $session, action => $url ); + $newform->hidden(name => 'assetId', value => $assetId); + my @fieldNames = qw/title description startDate duration seatsAvailable location/; + 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}; + 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}; + } + $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 + deleteCreatedItems submissionDeadline pastDeadlineMessage/ ) { + if( defined $properties->{$fieldName} ) { + 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 ) { + my $field = $fields->{$fieldId}; + $newform->yesNo( + label => $field->{label}, + name => $field->{fieldId} . '_yesNo', + defaultValue => 0, + value => $formDescription->{$field->{fieldId}}, + ); + } + $newform->submit; + return $parent->processStyle( + $parent->processTemplate({ + errors => $params->{errors} || [], + backUrl => $parent->getUrl, + pageForm => $newform->print, + },$parent->get('eventSubmissionFormTemplateId'))); +} + +#------------------------------------------------------------------- + +=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->update($formParams); + return $self->getParent->www_viewSubmissionQueue; + } else { + return $self->www_editSubmissionForm($formParams); + } +} + +#------------------------------------------------------------------- + =head2 getFormDescription returns a hash ref decoded from the JSON in the form description field @@ -308,6 +446,19 @@ sub view { } +#---------------------------------------------------------------- + +=head2 www_addSubmission ( ) + +calls www_editSubmission with assetId == new + +=cut + +sub www_addSubmission { + my $self = shift; + $self->www_editSubmission( { assetId => 'new' } ); +} + #------------------------------------------------------------------- =head2 www_edit ( ) @@ -329,112 +480,37 @@ sub www_edit { #------------------------------------------------------------------- -=head2 editSubmissionForm { parent, params } +=head2 www_editSubmission { params } -create an html form for user to enter params for a new submissionForm asset - -=head3 parent - -the parent ems object - -=head3 params - -optional set of possibly incorrect submission form params +calls WebGUI::Asset::EMSSubmission->editSubmission =cut -sub editSubmissionForm { - my $class = shift; - my $parent = shift; - my $params = shift || { }; - my $session = $parent->session; - my $i18n = WebGUI::International->new($parent->session,'Asset_EventManagementSystem'); - my $assetId = $params->{assetId} || $session->form->get('assetId'); - my $self; +sub www_editSubmission { + my $self = shift; + return $self->session->privilege->insufficient() unless $self->canEdit; + return WebGUI::Asset::EMSSubmission->editSubmission($self,shift); +} - 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{
  • $n
  • } } ; - my $listOfLinks = join '', ( map { - $makeAnchorList->( - $parent->getUrl('func=editSubmissionForm;assetId=' . $_->getId ), - $_->get('title'), - WebGUI::HTML::filter($_->get('description'),'all') - ) - } ( @$res ) ); - return $parent->processStyle( '

    ' . $i18n->get('select form to edit') . - '

    ' ); - } - } 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 $newform = WebGUI::HTMLForm->new($session,action => $parent->getUrl('func=editSubmissionFormSave')); - $newform->submit; - $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)}; -dav::dump 'editSubmissionForm::definition:', [@defs]; - for my $def ( @defs ) { - foreach my $fieldName ( @fieldNames ) { - my $properties = $def->{properties}; - if( defined $properties->{$fieldName} ) { - $fields->{$fieldName} = { %{$properties->{$fieldName}} }; # a simple first level copy - # field definitions don't contain their own name, we will need it later on - $fields->{$fieldName}{fieldId} = $fieldName; - }; - } - } - 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}; - } - $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 - deleteCreatedItems submissionDeadline pastDeadlineMessage/ ) { - if( defined $properties->{$fieldName} ) { - 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 ) { - my $field = $fields->{$fieldId}; - $newform->yesNo( - label => $field->{label}, - name => $field->{fieldId} . '_yesNo', - defaultValue => 0, - value => $formDescription->{$field->{fieldId}}, - ); - } - return $parent->processStyle( - $parent->processTemplate({ - errors => $params->{errors} || [], - backUrl => $parent->getUrl, - pageForm => $newform->print, - },$parent->get('eventSubmissionFormTemplateId'))); +=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->www_viewSubmissionQueue; + } else { + return $self->www_editSubmission($formParams); + } } #---------------------------------------------------------------- @@ -452,33 +528,38 @@ reference to the EMS asset that is parent to the new submission form asset use lib '/root/pb/lib'; use dav; sub processForm { - my $class = shift; - my $parent = shift; - my $form = $parent->session->form; + my $this = shift; + my $form; + if( $this eq __PACKAGE__ ) { + my $parent = shift; + $form = $parent->session->form; + } elsif( ref $this eq __PACKAGE__ ) { + $form = $this->session->form; + } else { + return {_isValid => 0, errors => [ { text => 'invalid function call' } ] }; + } my $params = {_isValid=>1}; - #if( $form->validToken ) { - 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 ) ]; - 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 - } + 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 ) ]; + 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 + } dav::dump 'processForm::params:', $params; - return $params; - #} else { - #return {_isValid => 0, errors => [ { text => 'invalid form token' } ] }; - #} + return $params; } #---------------------------------------------------------------- =head2 submitForm (... ) +this is going away, I am saving the code as an example of what the correct function in the emssubmission module will do + creates the form for the submitter to enter data returns a form object diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index 69c7d8faf..2fa7454e3 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -89,7 +89,6 @@ a JSON description of the form data fields -- a hash of the names of fields (eac sub addSubmissionForm { my $self = shift; my $params = shift; - delete $params->{_isValid} if exists $params->{_isValid}; $params->{className} = 'WebGUI::Asset::EMSSubmissionForm'; $params->{canSubmitGroupId} ||= 2; $self->addGroupToSubmitList($params->{canSubmitGroupId}); @@ -469,13 +468,13 @@ sub getTokens { } #------------------------------------------------------------------- -=head2 hasForms +=head2 hasSubmissionForms returns true if the EMS has subission forms attached =cut -sub hasForms { +sub hasSubmissionForms { my $self = shift; # are there ~any~ forms attached to this ems? my $res = $self->getLineage(['children'],{ limit => 1, @@ -605,7 +604,7 @@ sub view { canEdit => $self->canEdit, canSubmit => $self->canSubmit, hasSubmissions => $self->hasSubmissions, - hasForms => $self->hasForms, + hasSubmissionForms => $self->hasSubmissionForms, lookupRegistrantUrl => $self->getUrl('func=lookupRegistrant'), ); @@ -849,11 +848,11 @@ test and save data posted from editSubmissionForm... sub www_editSubmissionFormSave { my $self = shift; return $self->session->privilege->insufficient() unless $self->canEdit; - my $form = $self->session->form; my $formParams = WebGUI::Asset::EMSSubmissionForm->processForm($self); if( $formParams->{_isValid} ) { + delete $formParams->{_isValid}; $self->addSubmissionForm($formParams); - return $self->www_view; + return $self->www_viewSubmissionQueue; } else { return $self->www_editSubmissionForm($formParams); } @@ -1441,6 +1440,17 @@ sub www_getScheduleDataJSON { +#------------------------------------------------------------------- +=head2 www_getSubmissionQueueData + +returns JSON data to fill a YUI table. + +=cut + +sub www_getSubmissionQueueData { + +} + #------------------------------------------------------------------- =head2 www_getTicketsAsJson () @@ -2268,7 +2278,6 @@ 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'); @@ -2289,26 +2298,6 @@ sub www_viewSchedule { } -#--------------------------------------------- -=head2 www_viewSubmission - -=cut - -sub www_viewSubmission { - -# fill the view submission template - my $self = shift; - return $self->session->privilege->insufficient() unless $self->canSubmit or $self->canEdit; - my $db = $self->session->db; - - return $self->processStyle( - $self->processTemplate({ - backUrl => $self->getUrl, - },$self->get('eventSubmissionTemplateId'))); - - -} - #--------------------------------------------- =head2 www_viewSubmissionQueue @@ -2316,14 +2305,19 @@ sub www_viewSubmission { sub www_viewSubmissionQueue { my $self = shift; - return $self->session->privilege->insufficient() unless $self->canView; + return $self->session->privilege->insufficient() unless $self->canSubmit || $self->canEdit; return $self->processStyle( $self->processTemplate({ backUrl => $self->getUrl, + canEdit => $self->canEdit, + hasSubmissionForms => $self->hasSubmissionForms, + getSubmissionQueueDateUrl => $self->getUrl('func=getSubmissionQueueData'), + addSumissionFormUrl => $self->getUrl('func=addSubmissionForm'), + editSubmissionFormUrl => self->getUrl('func=editSubmissionForm'), + addSumissionUrl => $self->getUrl('func=addSubmission'), },$self->get('eventSubmissionQueueTemplateId'))); } - 1; diff --git a/t/Asset/EMSSubmissionForm.t b/t/Asset/EMSSubmissionForm.t index f0e2c9c27..8867dea80 100644 --- a/t/Asset/EMSSubmissionForm.t +++ b/t/Asset/EMSSubmissionForm.t @@ -137,7 +137,7 @@ WebGUI::Test->tagsToRollback($versionTag); loginRgstr; -is( $ems->hasForms, 0, 'ems currently has no forms' ); +is( $ems->hasSubmissionForms, 0, 'ems currently has no forms' ); #print 'press return to continue test' ; <>; @@ -161,7 +161,7 @@ my $frmA = $ems->addSubmissionForm({ formDescription => $formAdesc, }); isa_ok( $frmA, 'WebGUI::Asset::EMSSubmissionForm' ); -is( $ems->hasForms, 1, 'ems now has forms' ); +is( $ems->hasSubmissionForms, 1, 'ems now has forms' ); is_deeply( $frmA->getFormDescription, $formAdesc, 'form description matches' ); my $formBdesc = { diff --git a/www/extras/wobject/EMS/close12_1.gif b/www/extras/wobject/EMS/close12_1.gif new file mode 100644 index 0000000000000000000000000000000000000000..e2f67d72efc158da4e069822cbe338915761e396 GIT binary patch literal 85 zcmZ?wbhEHbz lf$Gy9znh?Y?^x%Bps9Cfw!UsJn!aoAS>7kV)`>G%0|4uCA&me4 literal 0 HcmV?d00001 diff --git a/www/extras/wobject/EMS/indicator.gif b/www/extras/wobject/EMS/indicator.gif new file mode 100644 index 0000000000000000000000000000000000000000..085ccaecaf5fa5c34bc14cd2c2ed5cbbd8e25dcb GIT binary patch literal 1553 zcma)+TTl~c6vwlh>nb99Af5rT)t{mCEg5urg=A(g z{C|6SPb~9Xage|wB`SrZk2FOMYM!buln2sX?5Y+T78iB(Zu9cS7|LZyZ++}u$^oi1 z_j@S}bW9OzU2R+RMy&~OT>X-oZ98$jq#ogNfJ!BM-42wHGZk*6s2KD}U*IA%epmxb zm}|6BK9YoIF;*xSL!+z@<64lB7->LTW2Vi4ostCA(z&2XniwNIv}fFo-`MbG;)u4G z^p@F!)|9HhZprHd_vXjDoxs6WkK-6P0@lfxnGT>*p(QHoUV=u1FAqb@b%*W=a3{`LsH5k^AvQNL>6fPpy#oU(&MuH(*aEX4b35*} zn4n7)`I2U%=+Z=?BVZQ?vjQFW4gD@~XSOO6b{qu81`4&LFuU2(ilxW+1|ZkNMnWe79C$gs zWT?Ele|HR{JGPe)5BTW>0Ey?-Ls6S#GoV0tbt6ku7B&*0 z;i9QM$W1Rj*rRIdceL)rAOSl+sDe3LkB87<%){;ZdHp6|SNlopDXRx< zxBDF9-lTo&v`8$humFygUij@qgT=Qzhj8{ym2-{Xciwqq_Xwk%=O3B-MNAL_6e`3U zyxwmXex4`g0^1RYw~Dth3av3Dl^AAlpO3mG!nLr#&ZZ7c_wUboI+deC+&%TFjK2Lm z!Y&f1h|T_On%RCV&=4bx`!>(YezqGVhl&QpED?N6GV)HmzJ9&rh$x*i?*@o9#6QI< z5ZI_MRX;0+pY8$`j)eF#TlUyG(eE%E7S!rj;mj^M5vhUicPm zVWQ2z+imFyg}SRABmOBY_@osR!>7Ov!ioK`NB6_Rv}7Ud?35ed5Sb@?yND?kv~RCa wqs^a3Sh>&&L4)!LKI?D2&k@))k(LESaga|C278ChSzn3NWVkcuNoY&{0f?~U_5c6? literal 0 HcmV?d00001 diff --git a/www/extras/wobject/EMS/submission.js b/www/extras/wobject/EMS/submission.js new file mode 100644 index 000000000..2b5027e2a --- /dev/null +++ b/www/extras/wobject/EMS/submission.js @@ -0,0 +1,381 @@ + +/*** The WebGUI Help Desk + * Requires: YAHOO, Dom, Event, DataSource, DataTable, Paginator, Container + * + */ + +var DataSource = YAHOO.util.DataSource, + DataTable = YAHOO.widget.DataTable, + Paginator = YAHOO.widget.Paginator; + +if ( typeof WebGUI == "undefined" ) { + WebGUI = {}; +} + +/*** WebGUI EMS Object + * + * This object renders the WebGUI EMS Submission datatable + * + * @method WebGUI.EMS.constructor + * @param configs {Object} object containing configuration necessary for creating the datatable. +TODO -- fix this to match what EMS really needs + * datasource {String} Required URL that returns the JSON data structure of data to be displayed. + * container {String} Required id of the HTML Element in which to render both the datatable and the pagination + * dtContainer {String} Required id of the HTML Element in which to render the datatable + * view {String} Required String which is passed to the ticket to properly return uses to the right view [all,my,search]. + * fields {ArrayRef} Required Array Reference of Objects used by the DataSource to configure and store data to be used by the data table + * columns {ArrayRef} Required Array Reference of Objects which define the columns for the datatable to render + * p_containers {ArrayRef} Required Array Reference containing the ids of the HTML Elements in which to render pagination. + * defaultSort {Object} Optional Custom object which defines which column and direction the paginator should sort by + * initRequestString {String} Optional Parameters to append to the end of the url when initializing the datatable + */ + + +WebGUI.EMS = function (configs) { + // Initialize configs + this._configs = {}; + if(configs) { + this._configs = configs; + } + + if(!this._configs.initiRequestString) { + this._configs.initRequestString = ';startIndex=0'; + } + + /////////////////////////////////////////////////////////////// + // Internationalization + // this comes first because it is used in other areas... + /////////////////////////////////////////////////////////////// + WebGUI.EMS.i18n = new WebGUI.i18n( { + namespaces : { + 'Asset_EMSSubmission' : [ + '' + ], + 'Asset_EventManagementSystem' : [ + '' + ] + } +// onpreload : { +// fn : this.initialize, +// obj : this, +// override : true, +// } + } ); + + /////////////////////////////////////////////////////////////// + // Protected Static Methods + /////////////////////////////////////////////////////////////// + + //*********************************************************************************** + // This method closes the active tab + // + // Parameters: ( integer ) -- if a ticket id is passed in then remove the tab for that ticket + // ( e, object ) -- cancel the event and close the tab associated with the object + // ( ) -- get the current tab from the tabview object and close it + // + WebGUI.EMS.closeTab = function ( e, myTab ) { + var index; + if( typeof(e) == "string" || typeof(e) == "number" ) { + index = e; + myTab = WebGUI.EMS.Tickets[index].Tab; + } else { + if( typeof(e) != "undefined" ) { + YAHOO.util.Event.preventDefault(e); + } + if( typeof(myTab) == "undefined" ) { + myTab = tabView.get('activeTab'); + } + index = parseInt( myTab.get('label') ); + } + delete WebGUI.EMS.Tickets[index]; + WebGUI.EMS.Tabs.removeTab(myTab); + if( WebGUI.EMS.lastTab ) { + WebGUI.EMS.Tabs.set('activeTab',WebGUI.EMS.lastTab); + } + }; + + //*********************************************************************************** + // Custom function to handle pagination requests + WebGUI.EMS.handlePagination = function (state,dt) { + var sortedBy = dt.get('sortedBy'); + // Define the new state + var newState = { + startIndex: state.startIndex, + sorting: { + key: sortedBy.key, + dir: ((sortedBy.dir === DataTable.CLASS_ASC) ? "asc" : "desc") + }, + pagination : { // Pagination values + startIndex: state.startIndex, // Go to the proper page offset + rowsPerPage: state.rowsPerPage // Return the proper rows per page + } + }; + + // Create callback object for the request + var oCallback = { + success: dt.onDataReturnSetRows, + failure: dt.onDataReturnSetRows, + scope: dt, + argument: newState // Pass in new state as data payload for callback function to use + }; + + // Send the request + dt.getDataSource().sendRequest(WebGUI.EMS.buildQueryString(newState, dt), oCallback); + }; + + //*********************************************************************************** + //This method is out here so it can be overridden. The datatable uses this method to sort it's columns + WebGUI.EMS.sortColumn = function(oColumn,sDir) { + // Default ascending + var sDir = "desc"; + + // If already sorted, sort in opposite direction + if(oColumn.key === this.get("sortedBy").key) { + sDir = (this.get("sortedBy").dir === DataTable.CLASS_ASC) ? "desc" : "asc"; + } + + // Define the new state + var newState = { + startIndex: 0, + sorting: { // Sort values + key: oColumn.key, + dir: (sDir === "asc") ? DataTable.CLASS_ASC : DataTable.CLASS_DESC + }, + pagination : { // Pagination values + startIndex: 0, // Default to first page when sorting + rowsPerPage: this.get("paginator").getRowsPerPage() // Keep current setting + } + }; + + // Create callback object for the request + var oCallback = { + success: this.onDataReturnSetRows, + failure: this.onDataReturnSetRows, + scope: this, + argument: newState // Pass in new state as data payload for callback function to use + }; + + // Send the request + this.getDataSource().sendRequest(WebGUI.EMS.buildQueryString(newState, this), oCallback); + }; + + //*********************************************************************************** + // This method checks for modifier keys pressed during the mouse click + function eventModifiers( e ) { + if( e.event.modifiers ) { + return e.event.modifiers & (Event.ALT_MASK | Event.CONTROL_MASK + | Event.SHIFT_MASK | Event.META_MASK); + } else { + return e.event.altKey | e.event.shiftKey | e.event.ctrlKey; + } + } + + //*********************************************************************************** + // This method is subscribed to by the DataTable and thus becomes a member of the DataTable + // class even though it is a member of the EMS Class. For this reason, a EMS instance + // is actually passed to the method as it's second parameter. + // + WebGUI.EMS.loadTicket = function ( evt, obj ) { + // if the user pressed a modifier key we want to default + if( eventModifiers( evt ) ) { return } + var target = evt.target; + if( typeof(WebGUI.EMS.Tickets) == "undefined" ) { + WebGUI.EMS.Tickets = new Object(); + } + + //let the default action happen if the user clicks the last reply column + var links = YAHOO.util.Dom.getElementsByClassName ("profile_link","a",target); + + // the 'loading' 'indicator' + if( typeof(WebGUI.EMS.ticketLoadingIndicator) == "undefined" ) { + WebGUI.EMS.ticketLoadingIndicator = new YAHOO.widget.Overlay( "ticketLoadingIndicator", { + fixedcenter : true, + visible : false + } ); + WebGUI.EMS.ticketLoadingIndicator.setBody( "Loading Ticket ..." + + "" + ); + WebGUI.EMS.ticketLoadingIndicator.render(document.body); + } + WebGUI.EMS.ticketLoadingIndicator.show(); + + if (links.length == 0) { + YAHOO.util.Event.stopEvent(evt.event); + } + + var elCell = this.getTdEl(target); + if(elCell) { + var oRecord = this.getRecord(elCell); + + if( typeof( WebGUI.EMS.Tickets[oRecord.ticketId] ) != "undefined" ) { + WebGUI.EMS.Tabs.set('activeTab',WebGUI.EMS.Tickets[oRecord.ticketId].Tab); + WebGUI.EMS.ticketLoadingIndicator.hide(); + } else { + var url = oRecord.getData('url') + "?func=view;caller=ticketMgr;view=" + obj._configs.view; + + // Create callback object for the request + var oCallback = { + success: function(o) { + var response = eval('(' + o.responseText + ')'); + var myTab; + if(response.hasError){ + var message = ""; + for(var i = 0; i < response.errors.length; i++) { + message += response.errors[i]; + } + alert(message); + return; + } else if( typeof(WebGUI.EMS.Tickets[response.ticketId]) == "undefined" + || WebGUI.EMS.Tickets[response.ticketId] == 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 ticketId in WebGUI.EMS.Tickets ) { WebGUI.EMS.closeTab(ticketId) } + var myContent = document.createElement("div"); + myContent.innerHTML = response.ticketText; + myTab = new YAHOO.widget.Tab({ + label: response.ticketId + 'X', + contentEl: myContent + }); + WebGUI.EMS.Tabs.addTab( myTab ); + YAHOO.util.Event.on(myTab.getElementsByClassName('close')[0], 'click', WebGUI.EMS.closeTab , myTab); + WebGUI.EMS.Tickets[response.ticketId] = new Object(); + WebGUI.EMS.Tickets[response.ticketId].Tab = myTab; + } else { + myTab = WebGUI.EMS.Tickets[response.ticketId].Tab; + myTab.set('content', response.ticketText); + } + // make sure the script on the ticket has run + if( typeof( WebGUI.ticketJScriptRun ) == "undefined" ) { + eval( document.getElementById("ticketJScript").innerHTML ); + } + delete WebGUI.ticketJScriptRun; + WebGUI.EMS.ticketLoadingIndicator.hide(); + WebGUI.EMS.lastTab = tabView.get('activeTab'); + WebGUI.EMS.Tabs.set('activeTab',myTab); + }, + failure: function(o) { + WebGUI.EMS.ticketLoadingIndicator.hide(); + } + }; + var request = YAHOO.util.Connect.asyncRequest('GET', url, oCallback); + } + } else { + alert("Could not get table cell for " + target); + } + }; + + + /////////////////////////////////////////////////////////////// + // Public Instance Methods + /////////////////////////////////////////////////////////////// + + //*********************************************************************************** + this.getDataTable = function() { + if(!this.EMSQ) { + return {}; + } + return this.EMSQ; + }; + + //*********************************************************************************** + this.getDefaultSort = function() { + if(this._configs.defaultSort) { + return this._configs.defaultSort; + } + return { + "key" : "creationDate", + "dir" : DataTable.CLASS_DESC + }; + }; + + //*********************************************************************************** + // Override this method if you want pagination to work differently + this.getPaginator = function () { + return new Paginator({ + containers : this._configs.p_containers, + pageLinks : 5, + rowsPerPage : 25, + rowsPerPageOptions : [25,50,100], + template : "{CurrentPageReport} {PreviousPageLink} {PageLinks} {NextPageLink} {RowsPerPageDropdown}" + }); + }; + + //*********************************************************************************** + this.initDataTable = function () { + var datasource = new DataSource(this._configs.datasource); + datasource.responseType = DataSource.TYPE_JSON; + datasource.responseSchema = { + resultsList : 'tickets', + fields : this._configs.fields, + metaFields : { totalRecords: 'totalRecords' } + }; + + // Initialize the data table + this.EMSQ = new DataTable( + this._configs.dtContainer, + this._configs.columns, + datasource, + { + initialRequest : this._configs.initRequestString, + paginationEventHandler : WebGUI.EMS.handlePagination, + paginator : this.getPaginator(), + dynamicData : true, + sortedBy : this.getDefaultSort() + } + ); + this.EMSQ.subscribe("rowMouseoverEvent", this.EMSQ.onEventHighlightRow); + this.EMSQ.subscribe("rowMouseoutEvent", this.EMSQ.onEventUnhighlightRow); + this.EMSQ.subscribe("cellClickEvent",WebGUI.EMS.loadTicket,this); + // Override function for custom server-side sorting + this.EMSQ.sortColumn = WebGUI.EMS.sortColumn; + this.EMSQ.handleDataReturnPayload = function (oReq, oRes, oPayload ) { + oPayload.totalRecords = parseInt( oRes.meta.totalRecords ); + return oPayload; + }; + this.EMSQ.generateRequest = WebGUI.EMS.buildQueryString; + + //Work around nested scoping for the callback + var myEMSQ = this.EMSQ; + //ensure no memory leaks with the datatable + }; + +}; + +/////////////////////////////////////////////////////////////// +// Public Static Methods +/////////////////////////////////////////////////////////////// + +//*********************************************************************************** +WebGUI.EMS.formatTitle = function ( elCell, oRecord, oColumn, orderNumber ) { + elCell.innerHTML = '' + + oRecord.getData( 'title' ) + + '' + ; +}; + +//*********************************************************************************** +WebGUI.EMS.formatLastReply = function ( elCell, oRecord, oColumn, orderNumber ) { + var lastReplyDate = oRecord.getData('lastReplyDate'); + if(lastReplyDate) { + elCell.innerHTML = oRecord.getData('lastReplyDate') + + ' by '+ '' + + oRecord.getData( 'lastReplyBy' ) + + ''; + } + else { + elCell.innerHTML = ""; + } +}; + +//*********************************************************************************** +WebGUI.EMS.buildQueryString = function ( state, dt ) { + var query = ";startIndex=" + state.pagination.startIndex + + ';orderByDirection=' + ((state.sortedBy.dir === DataTable.CLASS_ASC) ? "ASC" : "DESC") + + ';rowsPerPage=' + state.pagination.rowsPerPage + + ';orderByColumn=' + state.sortedBy.key + ; + return query; +}; +