Path: blob/master/src/view/phui/PHUIListItemView.php
12249 views
<?php12final class PHUIListItemView extends AphrontTagView {34const TYPE_LINK = 'type-link';5const TYPE_SPACER = 'type-spacer';6const TYPE_LABEL = 'type-label';7const TYPE_BUTTON = 'type-button';8const TYPE_CUSTOM = 'type-custom';9const TYPE_DIVIDER = 'type-divider';10const TYPE_ICON = 'type-icon';1112const STATUS_WARN = 'phui-list-item-warn';13const STATUS_FAIL = 'phui-list-item-fail';1415private $name;16private $href;17private $type = self::TYPE_LINK;18private $isExternal;19private $key;20private $icon;21private $selected;22private $disabled;23private $renderNameAsTooltip;24private $statusColor;25private $order;26private $aural;27private $profileImage;28private $indented;29private $hideInApplicationMenu;30private $icons = array();31private $openInNewWindow = false;32private $tooltip;33private $actionIcon;34private $actionIconHref;35private $count;36private $rel;37private $dropdownMenu;38private $keyCommand;3940public function setOpenInNewWindow($open_in_new_window) {41$this->openInNewWindow = $open_in_new_window;42return $this;43}4445public function getOpenInNewWindow() {46return $this->openInNewWindow;47}4849public function setRel($rel) {50$this->rel = $rel;51return $this;52}5354public function getRel() {55return $this->rel;56}5758public function setHideInApplicationMenu($hide) {59$this->hideInApplicationMenu = $hide;60return $this;61}6263public function getHideInApplicationMenu() {64return $this->hideInApplicationMenu;65}6667public function setDropdownMenu(PhabricatorActionListView $actions) {6869$this->dropdownMenu = $actions;7071// TODO: "PHUICrumbsView" currently creates a bad copy of list items72// by reading some of their properties. To survive this copy step, we73// need to mutate "$this" immediately or the "Create Object" dropdown74// when multiple create forms exist breaks.7576if (!$this->actionIcon) {77Javelin::initBehavior('phui-dropdown-menu');78$this->addSigil('phui-dropdown-menu');79$this->setMetadata($actions->getDropdownMenuMetadata());80}8182return $this;83}8485public function setAural($aural) {86$this->aural = $aural;87return $this;88}8990public function getAural() {91return $this->aural;92}9394public function setOrder($order) {95$this->order = $order;96return $this;97}9899public function getOrder() {100return $this->order;101}102103public function setRenderNameAsTooltip($render_name_as_tooltip) {104$this->renderNameAsTooltip = $render_name_as_tooltip;105return $this;106}107108public function getRenderNameAsTooltip() {109return $this->renderNameAsTooltip;110}111112public function setSelected($selected) {113$this->selected = $selected;114return $this;115}116117public function getSelected() {118return $this->selected;119}120121public function setIcon($icon) {122$this->icon = $icon;123return $this;124}125126public function setProfileImage($image) {127$this->profileImage = $image;128return $this;129}130131public function getIcon() {132return $this->icon;133}134135public function setCount($count) {136$this->count = $count;137return $this;138}139140public function setIndented($indented) {141$this->indented = $indented;142return $this;143}144145public function getIndented() {146return $this->indented;147}148149public function setKey($key) {150$this->key = (string)$key;151return $this;152}153154public function getKey() {155return $this->key;156}157158public function setType($type) {159$this->type = $type;160return $this;161}162163public function getType() {164return $this->type;165}166167public function setHref($href) {168$this->href = $href;169return $this;170}171172public function getHref() {173return $this->href;174}175176public function setName($name) {177$this->name = $name;178return $this;179}180181public function getName() {182return $this->name;183}184185public function setActionIcon($icon, $href) {186$this->actionIcon = $icon;187$this->actionIconHref = $href;188return $this;189}190191public function setIsExternal($is_external) {192$this->isExternal = $is_external;193return $this;194}195196public function getIsExternal() {197return $this->isExternal;198}199200public function setStatusColor($color) {201$this->statusColor = $color;202return $this;203}204205public function addIcon($icon) {206$this->icons[] = $icon;207return $this;208}209210public function getIcons() {211return $this->icons;212}213214public function setTooltip($tooltip) {215$this->tooltip = $tooltip;216return $this;217}218219protected function getTagName() {220return 'li';221}222223public function setKeyCommand($key_command) {224$this->keyCommand = $key_command;225return $this;226}227228public function getKeyCommand() {229return $this->keyCommand;230}231232protected function getTagAttributes() {233$classes = array();234$classes[] = 'phui-list-item-view';235$classes[] = 'phui-list-item-'.$this->type;236237if ($this->icon || $this->profileImage) {238$classes[] = 'phui-list-item-has-icon';239}240241if ($this->selected) {242$classes[] = 'phui-list-item-selected';243}244245if ($this->disabled) {246$classes[] = 'phui-list-item-disabled';247}248249if ($this->statusColor) {250$classes[] = $this->statusColor;251}252253if ($this->actionIcon) {254$classes[] = 'phui-list-item-has-action-icon';255}256257$sigil = null;258$metadata = null;259if ($this->dropdownMenu) {260$classes[] = 'dropdown';261if (!$this->actionIcon) {262$classes[] = 'dropdown-with-caret';263Javelin::initBehavior('phui-dropdown-menu');264$sigil = 'phui-dropdown-menu';265$metadata = $this->dropdownMenu->getDropdownMenuMetadata();266}267}268269return array(270'class' => $classes,271'sigil' => $sigil,272'meta' => $metadata,273);274}275276public function setDisabled($disabled) {277$this->disabled = $disabled;278return $this;279}280281public function getDisabled() {282return $this->disabled;283}284285protected function getTagContent() {286$name = null;287$icon = null;288$meta = null;289$sigil = array();290291if ($this->name) {292if ($this->getRenderNameAsTooltip()) {293Javelin::initBehavior('phabricator-tooltips');294$sigil[] = 'has-tooltip';295$meta = array(296'tip' => $this->name,297'align' => 'E',298);299} else {300if ($this->tooltip) {301Javelin::initBehavior('phabricator-tooltips');302$sigil[] = 'has-tooltip';303$meta = array(304'tip' => $this->tooltip,305'align' => 'E',306'size' => 300,307);308}309310$external = null;311if ($this->isExternal) {312$external = " \xE2\x86\x97";313}314315// If this element has an aural representation, make any name visual316// only. This is primarily dealing with the links in the main menu like317// "Profile" and "Logout". If we don't hide the name, the mobile318// version of these elements will have two redundant names.319320$classes = array();321$classes[] = 'phui-list-item-name';322if ($this->aural !== null) {323$classes[] = 'visual-only';324}325326$name = phutil_tag(327'span',328array(329'class' => implode(' ', $classes),330),331array(332$this->name,333$external,334));335}336}337338$aural = null;339if ($this->aural !== null) {340$aural = javelin_tag(341'span',342array(343'aural' => true,344),345$this->aural);346}347348if ($this->icon) {349$icon_name = $this->icon;350if ($this->getDisabled()) {351$icon_name .= ' grey';352}353354$icon = id(new PHUIIconView())355->addClass('phui-list-item-icon')356->setIcon($icon_name);357}358359if ($this->profileImage) {360$icon = id(new PHUIIconView())361->setHeadSize(PHUIIconView::HEAD_SMALL)362->addClass('phui-list-item-icon')363->setImage($this->profileImage);364}365366$classes = array();367if ($this->href) {368$classes[] = 'phui-list-item-href';369}370371if ($this->indented) {372$classes[] = 'phui-list-item-indented';373}374375$action_link = $this->newActionIconView();376377$count = null;378if ($this->count) {379$count = phutil_tag(380'span',381array(382'class' => 'phui-list-item-count',383),384$this->count);385}386387$caret = null;388if ($this->dropdownMenu && !$this->actionIcon) {389$caret = id(new PHUIIconView())390->setIcon('fa-caret-down');391}392393$icons = $this->getIcons();394395$key_command = null;396if ($this->keyCommand) {397$key_command = phutil_tag(398'span',399array(400'class' => 'keyboard-shortcut-key',401),402$this->keyCommand);403$sigil[] = 'has-key-command';404$meta['keyCommand'] = $this->keyCommand;405}406407$list_item = javelin_tag(408$this->href ? 'a' : 'div',409array(410'href' => $this->href,411'class' => implode(' ', $classes),412'meta' => $meta,413'sigil' => implode(' ', $sigil),414'target' => $this->getOpenInNewWindow() ? '_blank' : null,415'rel' => $this->rel,416),417array(418$aural,419$icon,420$icons,421$this->renderChildren(),422$name,423$count,424$key_command,425$caret,426));427428return array($list_item, $action_link);429}430431private function newActionIconView() {432$action_icon = $this->actionIcon;433$action_href = $this->actionIconHref;434435if ($action_icon === null) {436return null;437}438439$icon_view = id(new PHUIIconView())440->setIcon($action_icon)441->addClass('phui-list-item-action-icon');442443if ($this->dropdownMenu) {444Javelin::initBehavior('phui-dropdown-menu');445$sigil = 'phui-dropdown-menu';446$metadata = $this->dropdownMenu->getDropdownMenuMetadata();447} else {448$sigil = null;449$metadata = null;450}451452return javelin_tag(453'a',454array(455'href' => $action_href,456'class' => 'phui-list-item-action-href',457'sigil' => $sigil,458'meta' => $metadata,459),460$icon_view);461}462463}464465466