Path: blob/master/src/view/layout/PhabricatorActionView.php
12241 views
<?php12final class PhabricatorActionView extends AphrontView {34private $name;5private $icon;6private $href;7private $disabled;8private $label;9private $workflow;10private $renderAsForm;11private $download;12private $sigils = array();13private $metadata;14private $selected;15private $openInNewWindow;16private $submenu = array();17private $hidden;18private $depth;19private $id;20private $order;21private $color;22private $type;2324const TYPE_DIVIDER = 'type-divider';25const TYPE_LABEL = 'label';26const RED = 'action-item-red';27const GREEN = 'action-item-green';2829public function setSelected($selected) {30$this->selected = $selected;31return $this;32}3334public function getSelected() {35return $this->selected;36}3738public function setMetadata($metadata) {39$this->metadata = $metadata;40return $this;41}4243public function getMetadata() {44return $this->metadata;45}4647public function setDownload($download) {48$this->download = $download;49return $this;50}5152public function getDownload() {53return $this->download;54}5556public function setHref($href) {57$this->href = $href;58return $this;59}6061public function setColor($color) {62$this->color = $color;63return $this;64}6566public function addSigil($sigil) {67$this->sigils[] = $sigil;68return $this;69}7071public function getHref() {72return $this->href;73}7475public function setIcon($icon) {76$this->icon = $icon;77return $this;78}7980public function setName($name) {81$this->name = $name;82return $this;83}8485public function getName() {86return $this->name;87}8889public function setLabel($label) {90$this->label = $label;91return $this;92}9394public function setDisabled($disabled) {95$this->disabled = $disabled;96return $this;97}9899public function getDisabled() {100return $this->disabled;101}102103public function setWorkflow($workflow) {104$this->workflow = $workflow;105return $this;106}107108public function setRenderAsForm($form) {109$this->renderAsForm = $form;110return $this;111}112113public function setOpenInNewWindow($open_in_new_window) {114$this->openInNewWindow = $open_in_new_window;115return $this;116}117118public function getOpenInNewWindow() {119return $this->openInNewWindow;120}121122public function setID($id) {123$this->id = $id;124return $this;125}126127public function getID() {128if (!$this->id) {129$this->id = celerity_generate_unique_node_id();130}131return $this->id;132}133134public function setOrder($order) {135$this->order = $order;136return $this;137}138139public function getOrder() {140return $this->order;141}142143public function setType($type) {144$this->type = $type;145return $this;146}147148public function getType() {149return $this->type;150}151152public function setSubmenu(array $submenu) {153$this->submenu = $submenu;154155if (!$this->getHref()) {156$this->setHref('#');157}158159return $this;160}161162public function getItems($depth = 0) {163$items = array();164165$items[] = $this;166foreach ($this->submenu as $action) {167foreach ($action->getItems($depth + 1) as $item) {168$item169->setHidden(true)170->setDepth($depth + 1);171172$items[] = $item;173}174}175176return $items;177}178179public function setHidden($hidden) {180$this->hidden = $hidden;181return $this;182}183184public function getHidden() {185return $this->hidden;186}187188public function setDepth($depth) {189$this->depth = $depth;190return $this;191}192193public function getDepth() {194return $this->depth;195}196197public function render() {198$caret_id = celerity_generate_unique_node_id();199200$icon = null;201if ($this->icon) {202$color = '';203if ($this->disabled) {204$color = ' grey';205}206$icon = id(new PHUIIconView())207->addClass('phabricator-action-view-icon')208->setIcon($this->icon.$color);209}210211$sigils = array();212if ($this->workflow) {213$sigils[] = 'workflow';214}215216if ($this->download) {217$sigils[] = 'download';218}219220if ($this->submenu) {221$sigils[] = 'keep-open';222}223224if ($this->sigils) {225$sigils = array_merge($sigils, $this->sigils);226}227228$sigils = $sigils ? implode(' ', $sigils) : null;229230if ($this->href) {231if ($this->renderAsForm) {232if (!$this->hasViewer()) {233throw new Exception(234pht(235'Call %s when rendering an action as a form.',236'setViewer()'));237}238239$item = javelin_tag(240'button',241array(242'class' => 'phabricator-action-view-item',243),244array($icon, $this->name));245246$item = phabricator_form(247$this->getViewer(),248array(249'action' => $this->getHref(),250'method' => 'POST',251'sigil' => $sigils,252'meta' => $this->metadata,253),254$item);255} else {256if ($this->getOpenInNewWindow()) {257$target = '_blank';258$rel = 'noreferrer';259} else {260$target = null;261$rel = null;262}263264if ($this->submenu) {265$caret = javelin_tag(266'span',267array(268'class' => 'caret-right',269'id' => $caret_id,270),271'');272} else {273$caret = null;274}275276$item = javelin_tag(277'a',278array(279'href' => $this->getHref(),280'class' => 'phabricator-action-view-item',281'target' => $target,282'rel' => $rel,283'sigil' => $sigils,284'meta' => $this->metadata,285),286array($icon, $this->name, $caret));287}288} else {289$item = javelin_tag(290'span',291array(292'class' => 'phabricator-action-view-item',293'sigil' => $sigils,294),295array($icon, $this->name, $this->renderChildren()));296}297298$classes = array();299$classes[] = 'phabricator-action-view';300301if ($this->disabled) {302$classes[] = 'phabricator-action-view-disabled';303}304305if ($this->label) {306$classes[] = 'phabricator-action-view-label';307}308309if ($this->selected) {310$classes[] = 'phabricator-action-view-selected';311}312313if ($this->submenu) {314$classes[] = 'phabricator-action-view-submenu';315}316317if ($this->getHref()) {318$classes[] = 'phabricator-action-view-href';319}320321if ($this->icon) {322$classes[] = 'action-has-icon';323}324325if ($this->color) {326$classes[] = $this->color;327}328329if ($this->type) {330$classes[] = 'phabricator-action-view-'.$this->type;331}332333$style = array();334335if ($this->hidden) {336$style[] = 'display: none;';337}338339if ($this->depth) {340$indent = ($this->depth * 16);341$style[] = "margin-left: {$indent}px;";342}343344$sigil = null;345$meta = null;346347if ($this->submenu) {348Javelin::initBehavior('phui-submenu');349$sigil = 'phui-submenu';350351$item_ids = array();352foreach ($this->submenu as $subitem) {353$item_ids[] = $subitem->getID();354}355356$meta = array(357'itemIDs' => $item_ids,358'caretID' => $caret_id,359);360}361362return javelin_tag(363'li',364array(365'id' => $this->getID(),366'class' => implode(' ', $classes),367'style' => implode(' ', $style),368'sigil' => $sigil,369'meta' => $meta,370),371$item);372}373374}375376377