3 final class PhabricatorActionView
extends AphrontView
{
11 private $renderAsForm;
13 private $sigils = array();
16 private $openInNewWindow;
17 private $submenu = array();
25 const TYPE_DIVIDER
= 'type-divider';
26 const TYPE_LABEL
= 'label';
27 const RED
= 'action-item-red';
28 const GREEN
= 'action-item-green';
30 public function setSelected($selected) {
31 $this->selected
= $selected;
35 public function getSelected() {
36 return $this->selected
;
39 public function setMetadata($metadata) {
40 $this->metadata
= $metadata;
44 public function getMetadata() {
45 return $this->metadata
;
48 public function setDownload($download) {
49 $this->download
= $download;
53 public function getDownload() {
54 return $this->download
;
57 public function setHref($href) {
62 public function setColor($color) {
63 $this->color
= $color;
67 public function addSigil($sigil) {
68 $this->sigils
[] = $sigil;
72 public function getHref() {
76 public function setIcon($icon) {
81 public function setName($name) {
86 public function getName() {
90 public function setLabel($label) {
91 $this->label
= $label;
95 public function setDisabled($disabled) {
96 $this->disabled
= $disabled;
100 public function getDisabled() {
101 return $this->disabled
;
104 public function setWorkflow($workflow) {
105 $this->workflow
= $workflow;
109 public function setRenderAsForm($form) {
110 $this->renderAsForm
= $form;
114 public function setOpenInNewWindow($open_in_new_window) {
115 $this->openInNewWindow
= $open_in_new_window;
119 public function getOpenInNewWindow() {
120 return $this->openInNewWindow
;
123 public function setID($id) {
128 public function getID() {
130 $this->id
= celerity_generate_unique_node_id();
135 public function setOrder($order) {
136 $this->order
= $order;
140 public function getOrder() {
144 public function setType($type) {
149 public function getType() {
153 public function setSubmenu(array $submenu) {
154 $this->submenu
= $submenu;
156 if (!$this->getHref()) {
163 public function getItems($depth = 0) {
167 foreach ($this->submenu
as $action) {
168 foreach ($action->getItems($depth +
1) as $item) {
171 ->setDepth($depth +
1);
180 public function setHidden($hidden) {
181 $this->hidden
= $hidden;
185 public function getHidden() {
186 return $this->hidden
;
189 public function setDepth($depth) {
190 $this->depth
= $depth;
194 public function getDepth() {
198 public function render() {
199 $caret_id = celerity_generate_unique_node_id();
204 if ($this->disabled
) {
207 $icon = id(new PHUIIconView())
208 ->addClass('phabricator-action-view-icon')
209 ->setIcon($this->icon
.$color);
213 if ($this->workflow
) {
214 $sigils[] = 'workflow';
217 if ($this->download
) {
218 $sigils[] = 'download';
221 if ($this->submenu
) {
222 $sigils[] = 'keep-open';
226 $sigils = array_merge($sigils, $this->sigils
);
229 $sigils = $sigils ?
implode(' ', $sigils) : null;
232 if ($this->renderAsForm
) {
233 if (!$this->hasViewer()) {
236 'Call %s when rendering an action as a form.',
243 'class' => 'phabricator-action-view-item',
245 array($icon, $this->name
));
247 $item = phabricator_form(
250 'action' => $this->getHref(),
253 'meta' => $this->metadata
,
257 if ($this->getOpenInNewWindow()) {
265 if ($this->submenu
) {
266 $caret = javelin_tag(
269 'class' => 'caret-right',
280 'href' => $this->getHref(),
281 'class' => 'phabricator-action-view-item',
285 'meta' => $this->metadata
,
287 array($icon, $this->name
, $caret));
293 'class' => 'phabricator-action-view-item',
296 array($icon, $this->name
, $this->renderChildren()));
300 $classes[] = 'phabricator-action-view';
302 if ($this->disabled
) {
303 $classes[] = 'phabricator-action-view-disabled';
307 $classes[] = 'phabricator-action-view-label';
310 if ($this->selected
) {
311 $classes[] = 'phabricator-action-view-selected';
314 if ($this->submenu
) {
315 $classes[] = 'phabricator-action-view-submenu';
318 if ($this->getHref()) {
319 $classes[] = 'phabricator-action-view-href';
323 $classes[] = 'action-has-icon';
327 $classes[] = $this->color
;
331 $classes[] = 'phabricator-action-view-'.$this->type
;
337 $style[] = 'display: none;';
341 $indent = ($this->depth
* 16);
342 $style[] = "margin-left: {$indent}px;";
348 if ($this->submenu
) {
349 Javelin
::initBehavior('phui-submenu');
350 $sigil = 'phui-submenu';
353 foreach ($this->submenu
as $subitem) {
354 $item_ids[] = $subitem->getID();
358 'itemIDs' => $item_ids,
359 'caretID' => $caret_id,
366 'id' => $this->getID(),
367 'class' => implode(' ', $classes),
368 'style' => implode(' ', $style),