diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e55ceb28b5..4ceb86c2c8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1527,9 +1527,11 @@ phutil_register_library_map(array( 'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php', 'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php', 'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php', + 'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php', 'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php', 'PhabricatorSlowvoteCreateController' => 'applications/slowvote/controller/PhabricatorSlowvoteCreateController.php', 'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php', + 'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php', 'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php', 'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php', 'PhabricatorSlowvotePoll' => 'applications/slowvote/storage/PhabricatorSlowvotePoll.php', @@ -3486,9 +3488,11 @@ phutil_register_library_map(array( 'PhabricatorSetupIssueView' => 'AphrontView', 'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO', 'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO', + 'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController', 'PhabricatorSlowvoteController' => 'PhabricatorController', 'PhabricatorSlowvoteCreateController' => 'PhabricatorSlowvoteController', 'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO', + 'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorSlowvoteListController' => array( 0 => 'PhabricatorSlowvoteController', diff --git a/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php b/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php index bec1a90743..35c7c78fa2 100644 --- a/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php +++ b/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php @@ -44,6 +44,7 @@ final class PhabricatorApplicationSlowvote extends PhabricatorApplication { => 'PhabricatorSlowvoteListController', 'create/' => 'PhabricatorSlowvoteCreateController', '(?P[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController', + 'comment/(?P[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController', ), ); } diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteCommentController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteCommentController.php new file mode 100644 index 0000000000..a0b0a52051 --- /dev/null +++ b/src/applications/slowvote/controller/PhabricatorSlowvoteCommentController.php @@ -0,0 +1,70 @@ +id = $data['id']; + } + + public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + if (!$request->isFormPost()) { + return new Aphront400Response(); + } + + $poll = id(new PhabricatorSlowvoteQuery()) + ->setViewer($user) + ->withIDs(array($this->id)) + ->executeOne(); + if (!$poll) { + return new Aphront404Response(); + } + + $is_preview = $request->isPreviewRequest(); + $draft = PhabricatorDraft::buildFromRequest($request); + + $view_uri = '/V'.$poll->getID(); + + $xactions = array(); + $xactions[] = id(new PhabricatorSlowvoteTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) + ->attachComment( + id(new PhabricatorSlowvoteTransactionComment()) + ->setContent($request->getStr('comment'))); + + $editor = id(new PhabricatorSlowvoteEditor()) + ->setActor($user) + ->setContinueOnNoEffect($request->isContinueRequest()) + ->setContentSourceFromRequest($request) + ->setIsPreview($is_preview); + + try { + $xactions = $editor->applyTransactions($poll, $xactions); + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { + return id(new PhabricatorApplicationTransactionNoEffectResponse()) + ->setCancelURI($view_uri) + ->setException($ex); + } + + if ($draft) { + $draft->replaceOrDelete(); + } + + if ($request->isAjax()) { + return id(new PhabricatorApplicationTransactionResponse()) + ->setViewer($user) + ->setTransactions($xactions) + ->setIsPreview($is_preview) + ->setAnchorOffset($request->getStr('anchor')); + } else { + return id(new AphrontRedirectResponse()) + ->setURI($view_uri); + } + } + +} diff --git a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php index 35264f5cd5..008bc5c204 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php @@ -140,6 +140,7 @@ final class PhabricatorSlowvotePollController $panel); $xactions = $this->buildTransactions($poll); + $add_comment = $this->buildCommentForm($poll); return $this->buildApplicationPage( array( @@ -147,6 +148,7 @@ final class PhabricatorSlowvotePollController $header, $content, $xactions, + $add_comment, ), array( 'title' => 'V'.$poll->getID().' '.$poll->getQuestion(), @@ -384,4 +386,34 @@ final class PhabricatorSlowvotePollController return $timeline; } + private function buildCommentForm(PhabricatorSlowvotePoll $poll) { + $viewer = $this->getRequest()->getUser(); + + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); + + $add_comment_header = id(new PhabricatorHeaderView()) + ->setHeader( + $is_serious + ? pht('Add Comment') + : pht('Enter Deliberations')); + + $submit_button_name = $is_serious + ? pht('Add Comment') + : pht('Perhaps'); + + $draft = PhabricatorDraft::newFromUserAndKey($viewer, $poll->getPHID()); + + $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) + ->setUser($viewer) + ->setDraft($draft) + ->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/')) + ->setSubmitButtonName($submit_button_name); + + return array( + $add_comment_header, + $add_comment_form, + ); + } + + } diff --git a/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php b/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php new file mode 100644 index 0000000000..c1c4441af1 --- /dev/null +++ b/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php @@ -0,0 +1,44 @@ +getTransactionType()) { + } + } + + protected function getCustomTransactionNewValue( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + switch ($xaction->getTransactionType()) { + } + } + + protected function applyCustomInternalTransaction( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + switch ($xaction->getTransactionType()) { + } + } + + protected function applyCustomExternalTransaction( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + return; + } + +}