Changeset View
Changeset View
Standalone View
Standalone View
src/view/phui/PHUIListItemView.php
Show All 29 Lines | final class PHUIListItemView extends AphrontTagView { | ||||
private $hideInApplicationMenu; | private $hideInApplicationMenu; | ||||
private $icons = array(); | private $icons = array(); | ||||
private $openInNewWindow = false; | private $openInNewWindow = false; | ||||
private $tooltip; | private $tooltip; | ||||
private $actionIcon; | private $actionIcon; | ||||
private $actionIconHref; | private $actionIconHref; | ||||
private $count; | private $count; | ||||
private $rel; | private $rel; | ||||
private $hasDropdown; | private $dropdownMenu; | ||||
public function setOpenInNewWindow($open_in_new_window) { | public function setOpenInNewWindow($open_in_new_window) { | ||||
$this->openInNewWindow = $open_in_new_window; | $this->openInNewWindow = $open_in_new_window; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getOpenInNewWindow() { | public function getOpenInNewWindow() { | ||||
return $this->openInNewWindow; | return $this->openInNewWindow; | ||||
Show All 13 Lines | public function setHideInApplicationMenu($hide) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getHideInApplicationMenu() { | public function getHideInApplicationMenu() { | ||||
return $this->hideInApplicationMenu; | return $this->hideInApplicationMenu; | ||||
} | } | ||||
public function setDropdownMenu(PhabricatorActionListView $actions) { | public function setDropdownMenu(PhabricatorActionListView $actions) { | ||||
Javelin::initBehavior('phui-dropdown-menu'); | |||||
$this->dropdownMenu = $actions; | |||||
// TODO: "PHUICrumbsView" currently creates a bad copy of list items | |||||
// by reading some of their properties. To survive this copy step, we | |||||
// need to mutate "$this" immediately or the "Create Object" dropdown | |||||
// when multiple create forms exist breaks. | |||||
if (!$this->actionIcon) { | |||||
Javelin::initBehavior('phui-dropdown-menu'); | |||||
$this->addSigil('phui-dropdown-menu'); | $this->addSigil('phui-dropdown-menu'); | ||||
$this->setMetadata($actions->getDropdownMenuMetadata()); | $this->setMetadata($actions->getDropdownMenuMetadata()); | ||||
$this->hasDropdown = true; | } | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setAural($aural) { | public function setAural($aural) { | ||||
$this->aural = $aural; | $this->aural = $aural; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | protected function getTagAttributes() { | ||||
if ($this->statusColor) { | if ($this->statusColor) { | ||||
$classes[] = $this->statusColor; | $classes[] = $this->statusColor; | ||||
} | } | ||||
if ($this->actionIcon) { | if ($this->actionIcon) { | ||||
$classes[] = 'phui-list-item-has-action-icon'; | $classes[] = 'phui-list-item-has-action-icon'; | ||||
} | } | ||||
if ($this->hasDropdown) { | if ($this->dropdownMenu) { | ||||
$classes[] = 'dropdown'; | $classes[] = 'dropdown'; | ||||
if (!$this->actionIcon) { | |||||
throw new Exception( | |||||
pht( | |||||
'List item views can not currently render a dropdown without '. | |||||
'an action icon, because no application uses one. Clean up '. | |||||
'PHUICrumbsView, then add this capability.')); | |||||
amckinley: haha I don't think I've ever seen a `//TODO` in an exception before | |||||
Done Inline ActionsYeah, this is a little sketchy but I didn't want to leave us with a silent failure when you configure the View in an apparently-correct way that magically doesn't work. epriestley: Yeah, this is a little sketchy but I didn't want to leave us with a silent failure when you… | |||||
} | |||||
} | } | ||||
return array( | return array( | ||||
'class' => implode(' ', $classes), | 'class' => $classes, | ||||
); | ); | ||||
} | } | ||||
public function setDisabled($disabled) { | public function setDisabled($disabled) { | ||||
$this->disabled = $disabled; | $this->disabled = $disabled; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | protected function getTagContent() { | ||||
if ($this->href) { | if ($this->href) { | ||||
$classes[] = 'phui-list-item-href'; | $classes[] = 'phui-list-item-href'; | ||||
} | } | ||||
if ($this->indented) { | if ($this->indented) { | ||||
$classes[] = 'phui-list-item-indented'; | $classes[] = 'phui-list-item-indented'; | ||||
} | } | ||||
$action_link = null; | $action_link = $this->newActionIconView(); | ||||
if ($this->actionIcon) { | |||||
$action_icon = id(new PHUIIconView()) | |||||
->setIcon($this->actionIcon) | |||||
->addClass('phui-list-item-action-icon'); | |||||
$action_link = phutil_tag( | |||||
'a', | |||||
array( | |||||
'href' => $this->actionIconHref, | |||||
'class' => 'phui-list-item-action-href', | |||||
), | |||||
$action_icon); | |||||
} | |||||
$count = null; | $count = null; | ||||
if ($this->count) { | if ($this->count) { | ||||
$count = phutil_tag( | $count = phutil_tag( | ||||
'span', | 'span', | ||||
array( | array( | ||||
'class' => 'phui-list-item-count', | 'class' => 'phui-list-item-count', | ||||
), | ), | ||||
$this->count); | $this->count); | ||||
} | } | ||||
if ($this->hasDropdown) { | |||||
$caret = phutil_tag('span', array('class' => 'caret'), ''); | |||||
} else { | |||||
$caret = null; | |||||
} | |||||
$icons = $this->getIcons(); | $icons = $this->getIcons(); | ||||
$list_item = javelin_tag( | $list_item = javelin_tag( | ||||
$this->href ? 'a' : 'div', | $this->href ? 'a' : 'div', | ||||
array( | array( | ||||
'href' => $this->href, | 'href' => $this->href, | ||||
'class' => implode(' ', $classes), | 'class' => implode(' ', $classes), | ||||
'meta' => $meta, | 'meta' => $meta, | ||||
'sigil' => $sigil, | 'sigil' => $sigil, | ||||
'target' => $this->getOpenInNewWindow() ? '_blank' : null, | 'target' => $this->getOpenInNewWindow() ? '_blank' : null, | ||||
'rel' => $this->rel, | 'rel' => $this->rel, | ||||
), | ), | ||||
array( | array( | ||||
$aural, | $aural, | ||||
$icon, | $icon, | ||||
$icons, | $icons, | ||||
$this->renderChildren(), | $this->renderChildren(), | ||||
$name, | $name, | ||||
$caret, | |||||
$count, | $count, | ||||
)); | )); | ||||
return array($list_item, $action_link); | return array($list_item, $action_link); | ||||
} | } | ||||
private function newActionIconView() { | |||||
$action_icon = $this->actionIcon; | |||||
$action_href = $this->actionIconHref; | |||||
if ($action_icon === null) { | |||||
return null; | |||||
} | |||||
$icon_view = id(new PHUIIconView()) | |||||
->setIcon($action_icon) | |||||
->addClass('phui-list-item-action-icon'); | |||||
if ($this->dropdownMenu) { | |||||
Javelin::initBehavior('phui-dropdown-menu'); | |||||
$sigil = 'phui-dropdown-menu'; | |||||
$metadata = $this->dropdownMenu->getDropdownMenuMetadata(); | |||||
} else { | |||||
$sigil = null; | |||||
$metadata = null; | |||||
} | |||||
return javelin_tag( | |||||
'a', | |||||
array( | |||||
'href' => $action_href, | |||||
'class' => 'phui-list-item-action-href', | |||||
'sigil' => $sigil, | |||||
'meta' => $metadata, | |||||
), | |||||
$icon_view); | |||||
} | |||||
} | } |
haha I don't think I've ever seen a //TODO in an exception before