From 9a86e99710675d76110941e22ec8fe3f49ac5e8c Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 6 Dec 2006 22:38:41 +0000 Subject: [PATCH] Updated Event to use new autocommit interface --- lib/WebGUI/Asset/Event.pm | 161 +++++++++++---------------- lib/WebGUI/Asset/Wobject/Calendar.pm | 55 +++++++-- 2 files changed, 112 insertions(+), 104 deletions(-) diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index a7d9bb867..c8dcc0d65 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -230,7 +230,7 @@ sub generateRecurringEvents $properties->{endDate} = $dt->clone->add(days => $duration_days)->strftime('%F'); - $parent->addChild($properties)->requestCommit; + $parent->addChild($properties); } return 1; @@ -240,6 +240,23 @@ sub generateRecurringEvents +#################################################################### + +=head2 getAutoCommitWorkflowId + +Gets the WebGUI::VersionTag workflow to use to automatically commit Events. +By specifying this method, you activate this feature. + +=cut + +sub getAutoCommitWorkflowId { + my $self = shift; + return "pbworkflow000000000003"; +} + + + + #################################################################### @@ -1458,59 +1475,13 @@ sub processPropertiesFromFormPost $properties->{endDate} = $event->get("endDate"); $event->addRevision($self->get); - - # Request the commit - $event->requestCommit; } } } - - - $self->requestCommit; } -#################################################################### - -=head2 requestCommit - -Requests that this event (and all events with the same recurId) are committed -using the parent element's approval workflow. - -If the user is already working under a version tag, will remove the events from -the version tag and place them under a new version tag, then try to commit using -the parent element's approval workflow. - -=cut - -sub requestCommit -{ - my $self = shift; - my $currentTag = WebGUI::VersionTag->getWorking($self->session); - my $workflowId = "pbworkflow000000000003"; ###!!TODO: make a config value for this - - if ($currentTag->getAssetCount <= 1) - { - $currentTag->set({workflowId=>$workflowId}); - $currentTag->requestCommit; - } - else - { - my $newTag = WebGUI::VersionTag->create($self->session, - { - name => $self->getTitle." / ".$self->session->user->username, - workflowId => $workflowId, - }); - $self->session->db->write("update assetData set tagId=? where assetId=? and tagId=?",[$newTag->getId, $self->getId, $currentTag->getId]); - $self->purgeCache; - $newTag->requestCommit; - } -} - - - - #################################################################### @@ -1679,7 +1650,8 @@ sub www_edit my $tz = $session->user->profileField("timeZone"); my $func = lc $session->form->param("func"); my $var = {}; - + + return $self->session->privilege->noAccess() unless $self->getParent->canAddEvent(); if ($func eq "add" || $form->param("assetId") eq "new") { @@ -1803,22 +1775,7 @@ sub www_edit
| .q|Start: |.$var->{"formStartTime"} .q|
End: |.$var->{"formEndTime"} - .q|
- |; + .q||; # related links $var->{"formRelatedLinks"} = WebGUI::Form::textarea($session, @@ -1962,35 +1919,6 @@ sub www_edit

- - - |; @@ -2042,6 +1970,53 @@ sub www_edit }); + $var->{"script"} = <<'ENDJS'; + +ENDJS + + + ### Show any errors if necessary if ($self->session->stow->get("editFormErrors")) { diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index 757a6212b..7bc0974dd 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -13,7 +13,6 @@ $VERSION = "0.0.0"; #################################################################### use strict; -use warnings; use Tie::IxHash; @@ -265,7 +264,9 @@ sub addChild $self->session->errorHandler->security("add a ".$properties->{className}." to a ".$self->get("className")); return undef; } + + return $self->SUPER::addChild($properties, @other); } @@ -290,20 +291,52 @@ sub canEdit my $form = $self->session->form; my $user = $self->session->user; - no warnings qw(uninitialized); - return 1 if ($form->param("assetId") eq "new" - && $form->param("func") eq "editSave" - && $form->param("class") eq "WebGUI::Asset::Event" - && $user->isInGroup($self->get("groupIdEventEdit")) - ); - use warnings qw(all); - - return $self->SUPER::canEdit; + return ( + ( + ( + $form->process("func") eq "add" || + ( + $form->process("assetId") eq "new" && + $form->process("func") eq "editSave" && + $form->process("class") eq "WebGUI::Asset::Post::Thread" + ) + ) && + $self->canAddEvent + ) || # account for new events + $self->SUPER::canEdit() + ); } +#################################################################### + +=head2 canAddEvent + +Returns true if able to add events. Checks to make sure that the +Calendar has been committed at least once. Checks to make sure that +the user is in the appropriate group. + +=cut + +sub canAddEvent +{ + my $self = shift; + + return ( + ( + $self->get("status") eq "approved" || + $self->getTagCount > 1 # checks to make sure that the cs has been committed at least once + ) && ( + $self->session->user->isInGroup($self->get("groupIdEventEdit")) + || $self->SUPER::canEdit + ) + ); +} + + + #################################################################### @@ -861,7 +894,7 @@ sub view } # Event editor - if ($self->session->user->isInGroup(3)) + if ($self->canAddEvent) { $var->{'editor'} = 1; }