Differential D14789 Diff 35772 src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php
Show All 14 Lines | class PhabricatorApplicationTransactionCommentView extends AphrontView { | ||||
private $commentID; | private $commentID; | ||||
private $draft; | private $draft; | ||||
private $requestURI; | private $requestURI; | ||||
private $showPreview = true; | private $showPreview = true; | ||||
private $objectPHID; | private $objectPHID; | ||||
private $headerText; | private $headerText; | ||||
private $noPermission; | private $noPermission; | ||||
private $currentVersion; | private $currentVersion; | ||||
private $versionedDraft; | private $versionedDraft; | ||||
private $editTypes; | private $commentActions; | ||||
private $transactionTimeline; | private $transactionTimeline; | ||||
public function setObjectPHID($object_phid) { | public function setObjectPHID($object_phid) { | ||||
$this->objectPHID = $object_phid; | $this->objectPHID = $object_phid; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getObjectPHID() { | public function getObjectPHID() { | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | public function getAction() { | ||||
return $this->action; | return $this->action; | ||||
} | } | ||||
public function setHeaderText($text) { | public function setHeaderText($text) { | ||||
$this->headerText = $text; | $this->headerText = $text; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setEditTypes($edit_types) { | public function setCommentActions(array $comment_actions) { | ||||
$this->editTypes = $edit_types; | assert_instances_of($comment_actions, 'PhabricatorEditEngineCommentAction'); | ||||
$this->commentActions = $comment_actions; | |||||
return $this; | return $this; | ||||
} | } | ||||
public function getEditTypes() { | public function getCommentActions() { | ||||
return $this->editTypes; | return $this->commentActions; | ||||
} | } | ||||
public function setNoPermission($no_permission) { | public function setNoPermission($no_permission) { | ||||
$this->noPermission = $no_permission; | $this->noPermission = $no_permission; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getNoPermission() { | public function getNoPermission() { | ||||
Show All 39 Lines | public function render() { | ||||
$comment = $this->renderCommentPanel(); | $comment = $this->renderCommentPanel(); | ||||
if ($this->getShowPreview()) { | if ($this->getShowPreview()) { | ||||
$preview = $this->renderPreviewPanel(); | $preview = $this->renderPreviewPanel(); | ||||
} else { | } else { | ||||
$preview = null; | $preview = null; | ||||
} | } | ||||
if (!$this->getEditTypes()) { | if (!$this->getCommentActions()) { | ||||
Javelin::initBehavior( | Javelin::initBehavior( | ||||
'phabricator-transaction-comment-form', | 'phabricator-transaction-comment-form', | ||||
array( | array( | ||||
'formID' => $this->getFormID(), | 'formID' => $this->getFormID(), | ||||
'timelineID' => $this->getPreviewTimelineID(), | 'timelineID' => $this->getPreviewTimelineID(), | ||||
'panelID' => $this->getPreviewPanelID(), | 'panelID' => $this->getPreviewPanelID(), | ||||
'showPreview' => $this->getShowPreview(), | 'showPreview' => $this->getShowPreview(), | ||||
'actionURI' => $this->getAction(), | 'actionURI' => $this->getAction(), | ||||
Show All 36 Lines | $form = id(new AphrontFormView()) | ||||
array( | array( | ||||
'objectPHID' => $this->getObjectPHID(), | 'objectPHID' => $this->getObjectPHID(), | ||||
)) | )) | ||||
->setAction($this->getAction()) | ->setAction($this->getAction()) | ||||
->setID($this->getFormID()) | ->setID($this->getFormID()) | ||||
->addHiddenInput('__draft__', $draft_key) | ->addHiddenInput('__draft__', $draft_key) | ||||
->addHiddenInput($version_key, $version_value); | ->addHiddenInput($version_key, $version_value); | ||||
$edit_types = $this->getEditTypes(); | $comment_actions = $this->getCommentActions(); | ||||
if ($edit_types) { | if ($comment_actions) { | ||||
$action_map = array(); | $action_map = array(); | ||||
$type_map = array(); | $type_map = array(); | ||||
foreach ($edit_types as $edit_type) { | |||||
$key = $edit_type->getEditType(); | $comment_actions = mpull($comment_actions, null, 'getKey'); | ||||
$draft_actions = array(); | |||||
$draft_keys = array(); | |||||
if ($versioned_draft) { | |||||
$draft_actions = $versioned_draft->getProperty('actions', array()); | |||||
if (!is_array($draft_actions)) { | |||||
$draft_actions = array(); | |||||
} | |||||
foreach ($draft_actions as $action) { | |||||
$type = idx($action, 'type'); | |||||
$comment_action = idx($comment_actions, $type); | |||||
if (!$comment_action) { | |||||
continue; | |||||
} | |||||
$value = idx($action, 'value'); | |||||
$comment_action->setValue($value); | |||||
$draft_keys[] = $type; | |||||
} | |||||
} | |||||
foreach ($comment_actions as $key => $comment_action) { | |||||
$key = $comment_action->getKey(); | |||||
$action_map[$key] = array( | $action_map[$key] = array( | ||||
'key' => $key, | 'key' => $key, | ||||
'label' => $edit_type->getLabel(), | 'label' => $comment_action->getLabel(), | ||||
'type' => $edit_type->getPHUIXControlType(), | 'type' => $comment_action->getPHUIXControlType(), | ||||
'spec' => $edit_type->getPHUIXControlSpecification(), | 'spec' => $comment_action->getPHUIXControlSpecification(), | ||||
'initialValue' => $comment_action->getInitialValue(), | |||||
); | ); | ||||
$type_map[$key] = $edit_type; | $type_map[$key] = $comment_action; | ||||
} | } | ||||
$options = array(); | $options = array(); | ||||
$options['+'] = pht('Add Action...'); | $options['+'] = pht('Add Action...'); | ||||
foreach ($action_map as $key => $item) { | foreach ($action_map as $key => $item) { | ||||
$options[$key] = $item['label']; | $options[$key] = $item['label']; | ||||
} | } | ||||
Show All 20 Lines | if ($comment_actions) { | ||||
// new actions. | // new actions. | ||||
$form->appendChild( | $form->appendChild( | ||||
phutil_tag( | phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'id' => $place_id, | 'id' => $place_id, | ||||
))); | ))); | ||||
$draft_actions = array(); | |||||
if ($versioned_draft) { | |||||
$draft_actions = $versioned_draft->getProperty('actions', array()); | |||||
foreach ($draft_actions as $key => $action) { | |||||
$type = idx($action, 'type'); | |||||
if (!$type) { | |||||
unset($draft_actions[$key]); | |||||
continue; | |||||
} | |||||
$edit_type = idx($type_map, $type); | |||||
if (!$edit_type) { | |||||
unset($draft_actions[$key]); | |||||
continue; | |||||
} | |||||
$value = idx($action, 'value'); | |||||
$value = $edit_type->getCommentActionValueFromDraftValue($value); | |||||
$draft_actions[$key]['value'] = $value; | |||||
} | |||||
} | |||||
Javelin::initBehavior( | Javelin::initBehavior( | ||||
'comment-actions', | 'comment-actions', | ||||
array( | array( | ||||
'actionID' => $action_id, | 'actionID' => $action_id, | ||||
'inputID' => $input_id, | 'inputID' => $input_id, | ||||
'formID' => $this->getFormID(), | 'formID' => $this->getFormID(), | ||||
'placeID' => $place_id, | 'placeID' => $place_id, | ||||
'panelID' => $this->getPreviewPanelID(), | 'panelID' => $this->getPreviewPanelID(), | ||||
'timelineID' => $this->getPreviewTimelineID(), | 'timelineID' => $this->getPreviewTimelineID(), | ||||
'actions' => $action_map, | 'actions' => $action_map, | ||||
'showPreview' => $this->getShowPreview(), | 'showPreview' => $this->getShowPreview(), | ||||
'actionURI' => $this->getAction(), | 'actionURI' => $this->getAction(), | ||||
'drafts' => $draft_actions, | 'drafts' => $draft_keys, | ||||
)); | )); | ||||
} | } | ||||
$form | $form | ||||
->appendChild( | ->appendChild( | ||||
id(new PhabricatorRemarkupControl()) | id(new PhabricatorRemarkupControl()) | ||||
->setID($this->getCommentID()) | ->setID($this->getCommentID()) | ||||
->setName('comment') | ->setName('comment') | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |