Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
Show First 20 Lines • Show All 867 Lines • ▼ Show 20 Lines | final public function addActionToCrumbs(PHUICrumbsView $crumbs) { | ||||
if ($dropdown) { | if ($dropdown) { | ||||
$action->setDropdownMenu($dropdown); | $action->setDropdownMenu($dropdown); | ||||
} | } | ||||
$crumbs->addAction($action); | $crumbs->addAction($action); | ||||
} | } | ||||
final public function buildEditEngineCommentView($object) { | final public function buildEditEngineCommentView($object) { | ||||
$config = $this->loadEditEngineConfiguration(null); | |||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$object_phid = $object->getPHID(); | $object_phid = $object->getPHID(); | ||||
$header_text = $this->getCommentViewHeaderText($object); | $header_text = $this->getCommentViewHeaderText($object); | ||||
$button_text = $this->getCommentViewButtonText($object); | $button_text = $this->getCommentViewButtonText($object); | ||||
$comment_uri = $this->getEditURI($object, 'comment/'); | $comment_uri = $this->getEditURI($object, 'comment/'); | ||||
$view = id(new PhabricatorApplicationTransactionCommentView()) | $view = id(new PhabricatorApplicationTransactionCommentView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setObjectPHID($object_phid) | ->setObjectPHID($object_phid) | ||||
->setHeaderText($header_text) | ->setHeaderText($header_text) | ||||
->setAction($comment_uri) | ->setAction($comment_uri) | ||||
->setSubmitButtonName($button_text); | ->setSubmitButtonName($button_text); | ||||
$draft = PhabricatorVersionedDraft::loadDraft( | $draft = PhabricatorVersionedDraft::loadDraft( | ||||
$object_phid, | $object_phid, | ||||
$viewer->getPHID()); | $viewer->getPHID()); | ||||
if ($draft) { | if ($draft) { | ||||
$view->setVersionedDraft($draft); | $view->setVersionedDraft($draft); | ||||
} | } | ||||
$view->setCurrentVersion($this->loadDraftVersion($object)); | $view->setCurrentVersion($this->loadDraftVersion($object)); | ||||
$fields = $this->buildEditFields($object); | |||||
$all_types = array(); | |||||
foreach ($fields as $field) { | |||||
// TODO: Load draft stuff. | |||||
$types = $field->getCommentEditTypes(); | |||||
foreach ($types as $type) { | |||||
$all_types[] = $type; | |||||
} | |||||
} | |||||
$view->setEditTypes($all_types); | |||||
return $view; | return $view; | ||||
} | } | ||||
protected function loadDraftVersion($object) { | protected function loadDraftVersion($object) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
if (!$viewer->isLoggedIn()) { | if (!$viewer->isLoggedIn()) { | ||||
return null; | return null; | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | private function buildCommentResponse($object) { | ||||
$controller = $this->getController(); | $controller = $this->getController(); | ||||
$request = $controller->getRequest(); | $request = $controller->getRequest(); | ||||
if (!$request->isFormPost()) { | if (!$request->isFormPost()) { | ||||
return new Aphront400Response(); | return new Aphront400Response(); | ||||
} | } | ||||
$config = $this->loadEditEngineConfiguration(null); | |||||
$fields = $this->buildEditFields($object); | |||||
$is_preview = $request->isPreviewRequest(); | $is_preview = $request->isPreviewRequest(); | ||||
$view_uri = $this->getObjectViewURI($object); | $view_uri = $this->getObjectViewURI($object); | ||||
$template = $object->getApplicationTransactionTemplate(); | $template = $object->getApplicationTransactionTemplate(); | ||||
$comment_template = $template->getApplicationTransactionCommentObject(); | $comment_template = $template->getApplicationTransactionCommentObject(); | ||||
$comment_text = $request->getStr('comment'); | $comment_text = $request->getStr('comment'); | ||||
Show All 10 Lines | if ($is_preview) { | ||||
// TODO: This is just a proof of concept. | // TODO: This is just a proof of concept. | ||||
$draft->setProperty('temporary.comment', $comment_text); | $draft->setProperty('temporary.comment', $comment_text); | ||||
$draft->save(); | $draft->save(); | ||||
} | } | ||||
} | } | ||||
$xactions = array(); | $xactions = array(); | ||||
$actions = $request->getStr('editengine.actions'); | |||||
if ($actions) { | |||||
$type_map = array(); | |||||
foreach ($fields as $field) { | |||||
$types = $field->getCommentEditTypes(); | |||||
foreach ($types as $type) { | |||||
$type_map[$type->getEditType()] = $type; | |||||
} | |||||
} | |||||
$actions = phutil_json_decode($actions); | |||||
foreach ($actions as $action) { | |||||
$type = idx($action, 'type'); | |||||
if (!$type) { | |||||
continue; | |||||
} | |||||
$edit_type = idx($type_map, $type); | |||||
if (!$edit_type) { | |||||
continue; | |||||
} | |||||
$type_xactions = $edit_type->generateTransactions( | |||||
$template, | |||||
array( | |||||
'value' => idx($action, 'value'), | |||||
)); | |||||
foreach ($type_xactions as $type_xaction) { | |||||
$xactions[] = $type_xaction; | |||||
} | |||||
} | |||||
} | |||||
if (strlen($comment_text) || !$xactions) { | |||||
$xactions[] = id(clone $template) | $xactions[] = id(clone $template) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ||||
->attachComment( | ->attachComment( | ||||
id(clone $comment_template) | id(clone $comment_template) | ||||
->setContent($comment_text)); | ->setContent($comment_text)); | ||||
} | |||||
$editor = $object->getApplicationTransactionEditor() | $editor = $object->getApplicationTransactionEditor() | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContinueOnNoEffect($request->isContinueRequest()) | ->setContinueOnNoEffect($request->isContinueRequest()) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setIsPreview($is_preview); | ->setIsPreview($is_preview); | ||||
try { | try { | ||||
▲ Show 20 Lines • Show All 239 Lines • Show Last 20 Lines |