[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PHUIListItemView extends AphrontTagView { 4 5 const TYPE_LINK = 'type-link'; 6 const TYPE_SPACER = 'type-spacer'; 7 const TYPE_LABEL = 'type-label'; 8 const TYPE_BUTTON = 'type-button'; 9 const TYPE_CUSTOM = 'type-custom'; 10 const TYPE_DIVIDER = 'type-divider'; 11 const TYPE_ICON = 'type-icon'; 12 13 const STATUS_WARN = 'phui-list-item-warn'; 14 const STATUS_FAIL = 'phui-list-item-fail'; 15 16 private $name; 17 private $href; 18 private $type = self::TYPE_LINK; 19 private $isExternal; 20 private $key; 21 private $icon; 22 private $appIcon; 23 private $selected; 24 private $disabled; 25 private $renderNameAsTooltip; 26 private $statusColor; 27 private $order; 28 private $aural; 29 30 public function setAural($aural) { 31 $this->aural = $aural; 32 return $this; 33 } 34 35 public function getAural() { 36 return $this->aural; 37 } 38 39 public function setOrder($order) { 40 $this->order = $order; 41 return $this; 42 } 43 44 public function getOrder() { 45 return $this->order; 46 } 47 48 public function setRenderNameAsTooltip($render_name_as_tooltip) { 49 $this->renderNameAsTooltip = $render_name_as_tooltip; 50 return $this; 51 } 52 53 public function getRenderNameAsTooltip() { 54 return $this->renderNameAsTooltip; 55 } 56 57 public function setSelected($selected) { 58 $this->selected = $selected; 59 return $this; 60 } 61 62 public function getSelected() { 63 return $this->selected; 64 } 65 66 public function setIcon($icon) { 67 $this->icon = $icon; 68 return $this; 69 } 70 71 public function setAppIcon($icon) { 72 $this->appIcon = $icon; 73 return $this; 74 } 75 76 public function getIcon() { 77 return $this->icon; 78 } 79 80 public function setKey($key) { 81 $this->key = (string)$key; 82 return $this; 83 } 84 85 public function getKey() { 86 return $this->key; 87 } 88 89 public function setType($type) { 90 $this->type = $type; 91 return $this; 92 } 93 94 public function getType() { 95 return $this->type; 96 } 97 98 public function setHref($href) { 99 $this->href = $href; 100 return $this; 101 } 102 103 public function getHref() { 104 return $this->href; 105 } 106 107 public function setName($name) { 108 $this->name = $name; 109 return $this; 110 } 111 112 public function getName() { 113 return $this->name; 114 } 115 116 public function setIsExternal($is_external) { 117 $this->isExternal = $is_external; 118 return $this; 119 } 120 121 public function getIsExternal() { 122 return $this->isExternal; 123 } 124 125 public function setStatusColor($color) { 126 $this->statusColor = $color; 127 return $this; 128 } 129 130 protected function getTagName() { 131 return 'li'; 132 } 133 134 protected function getTagAttributes() { 135 $classes = array(); 136 $classes[] = 'phui-list-item-view'; 137 $classes[] = 'phui-list-item-'.$this->type; 138 139 if ($this->icon || $this->appIcon) { 140 $classes[] = 'phui-list-item-has-icon'; 141 } 142 143 if ($this->selected) { 144 $classes[] = 'phui-list-item-selected'; 145 } 146 147 if ($this->statusColor) { 148 $classes[] = $this->statusColor; 149 } 150 151 return array( 152 'class' => $classes, 153 ); 154 } 155 156 public function setDisabled($disabled) { 157 $this->disabled = $disabled; 158 return $this; 159 } 160 161 public function getDisabled() { 162 return $this->disabled; 163 } 164 165 protected function getTagContent() { 166 $name = null; 167 $icon = null; 168 $meta = null; 169 $sigil = null; 170 171 if ($this->name) { 172 if ($this->getRenderNameAsTooltip()) { 173 $sigil = 'has-tooltip'; 174 $meta = array( 175 'tip' => $this->name, 176 ); 177 } else { 178 $external = null; 179 if ($this->isExternal) { 180 $external = " \xE2\x86\x97"; 181 } 182 183 // If this element has an aural representation, make any name visual 184 // only. This is primarily dealing with the links in the main menu like 185 // "Profile" and "Logout". If we don't hide the name, the mobile 186 // version of these elements will have two redundant names. 187 188 $classes = array(); 189 $classes[] = 'phui-list-item-name'; 190 if ($this->aural !== null) { 191 $classes[] = 'visual-only'; 192 } 193 194 $name = phutil_tag( 195 'span', 196 array( 197 'class' => implode(' ', $classes), 198 ), 199 array( 200 $this->name, 201 $external, 202 )); 203 } 204 } 205 206 $aural = null; 207 if ($this->aural !== null) { 208 $aural = javelin_tag( 209 'span', 210 array( 211 'aural' => true, 212 ), 213 $this->aural); 214 } 215 216 if ($this->icon) { 217 $icon_name = $this->icon; 218 if ($this->getDisabled()) { 219 $icon_name .= ' grey'; 220 } 221 222 $icon = id(new PHUIIconView()) 223 ->addClass('phui-list-item-icon') 224 ->setIconFont($icon_name); 225 } 226 227 if ($this->appIcon) { 228 $icon = id(new PHUIIconView()) 229 ->addClass('phui-list-item-icon') 230 ->setSpriteSheet(PHUIIconView::SPRITE_APPS) 231 ->setSpriteIcon($this->appIcon); 232 } 233 234 return javelin_tag( 235 $this->href ? 'a' : 'div', 236 array( 237 'href' => $this->href, 238 'class' => $this->href ? 'phui-list-item-href' : null, 239 'meta' => $meta, 240 'sigil' => $sigil, 241 ), 242 array( 243 $aural, 244 $icon, 245 $this->renderChildren(), 246 $name, 247 )); 248 } 249 250 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |