Changeset View
Changeset View
Standalone View
Standalone View
src/view/widget/hovercard/PhabricatorHovercardView.php
Show All 35 Lines | final class PhabricatorHovercardView extends AphrontView { | ||||
public function addField($label, $value) { | public function addField($label, $value) { | ||||
$this->fields[] = array( | $this->fields[] = array( | ||||
'label' => $label, | 'label' => $label, | ||||
'value' => $value, | 'value' => $value, | ||||
); | ); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function addAction($label, $uri, $workflow = false) { | public function addAction($label, $uri, $workflow = false, $form = false) { | ||||
$this->actions[] = array( | $this->actions[] = array( | ||||
'label' => $label, | 'label' => $label, | ||||
'uri' => $uri, | 'uri' => $uri, | ||||
'workflow' => $workflow, | 'workflow' => $workflow, | ||||
'form' => $form, | |||||
); | ); | ||||
return $this; | return $this; | ||||
} | } | ||||
epriestley: Maybe this should just be a PhabricatorActionView? Not sure how messy that would be. Would… | |||||
public function addTag(PHUITagView $tag) { | public function addTag(PHUITagView $tag) { | ||||
$this->tags[] = $tag; | $this->tags[] = $tag; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setColor($color) { | public function setColor($color) { | ||||
$this->color = $color; | $this->color = $color; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function render() { | public function render() { | ||||
if (!$this->handle) { | if (!$this->handle) { | ||||
throw new Exception("Call setObjectHandle() before calling render()!"); | throw new Exception("Call setObjectHandle() before calling render()!"); | ||||
} | } | ||||
$handle = $this->handle; | $handle = $this->handle; | ||||
$user = $this->getUser(); | |||||
require_celerity_resource("phabricator-hovercard-view-css"); | require_celerity_resource("phabricator-hovercard-view-css"); | ||||
$title = pht("%s: %s", | $title = pht("%s: %s", | ||||
$handle->getTypeName(), | $handle->getTypeName(), | ||||
$this->title ? $this->title : $handle->getName()); | $this->title ? $this->title : $handle->getName()); | ||||
$header = new PhabricatorActionHeaderView(); | $header = new PhabricatorActionHeaderView(); | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public function render() { | ||||
$buttons = array(); | $buttons = array(); | ||||
foreach ($this->actions as $action) { | foreach ($this->actions as $action) { | ||||
$options = array( | $options = array( | ||||
'class' => 'button grey', | 'class' => 'button grey', | ||||
'href' => $action['uri'], | 'href' => $action['uri'], | ||||
); | ); | ||||
if ($action['workflow']) { | if ($action['form']) { | ||||
if (!$user) { | |||||
throw new Exception( | |||||
'Call setUser() when rendering an action as a form.'); | |||||
} | |||||
$buttons[] = phabricator_form($user, | |||||
array( | |||||
'action' => $action['uri'], | |||||
'method' => 'POST', | |||||
'sigil' => $action['workflow'] ? 'workflow' : null, | |||||
), | |||||
phutil_tag('button', | |||||
array( | |||||
'class' => 'button grey', | |||||
), | |||||
$action['label'])); | |||||
} else if ($action['workflow']) { | |||||
$options['sigil'] = 'workflow'; | $options['sigil'] = 'workflow'; | ||||
$buttons[] = javelin_tag( | $buttons[] = javelin_tag( | ||||
'a', | 'a', | ||||
$options, | $options, | ||||
$action['label']); | $action['label']); | ||||
} else { | } else { | ||||
$buttons[] = phutil_tag( | $buttons[] = phutil_tag( | ||||
'a', | 'a', | ||||
Show All 26 Lines |
Maybe this should just be a PhabricatorActionView? Not sure how messy that would be. Would simplify the disabled/inactive stuff too.