[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PHUITagView extends AphrontTagView { 4 5 const TYPE_PERSON = 'person'; 6 const TYPE_OBJECT = 'object'; 7 const TYPE_STATE = 'state'; 8 const TYPE_SHADE = 'shade'; 9 10 const COLOR_RED = 'red'; 11 const COLOR_ORANGE = 'orange'; 12 const COLOR_YELLOW = 'yellow'; 13 const COLOR_BLUE = 'blue'; 14 const COLOR_INDIGO = 'indigo'; 15 const COLOR_VIOLET = 'violet'; 16 const COLOR_GREEN = 'green'; 17 const COLOR_BLACK = 'black'; 18 const COLOR_GREY = 'grey'; 19 const COLOR_WHITE = 'white'; 20 const COLOR_PINK = 'pink'; 21 const COLOR_BLUEGREY = 'bluegrey'; 22 const COLOR_CHECKERED = 'checkered'; 23 const COLOR_DISABLED = 'disabled'; 24 25 const COLOR_OBJECT = 'object'; 26 const COLOR_PERSON = 'person'; 27 28 private $type; 29 private $href; 30 private $name; 31 private $phid; 32 private $backgroundColor; 33 private $dotColor; 34 private $closed; 35 private $external; 36 private $icon; 37 private $shade; 38 private $slimShady; 39 40 public function setType($type) { 41 $this->type = $type; 42 switch ($type) { 43 case self::TYPE_SHADE: 44 break; 45 case self::TYPE_OBJECT: 46 $this->setBackgroundColor(self::COLOR_OBJECT); 47 break; 48 case self::TYPE_PERSON: 49 $this->setBackgroundColor(self::COLOR_PERSON); 50 break; 51 } 52 return $this; 53 } 54 55 public function setShade($shade) { 56 $this->shade = $shade; 57 return $this; 58 } 59 60 public function setDotColor($dot_color) { 61 $this->dotColor = $dot_color; 62 return $this; 63 } 64 65 public function setBackgroundColor($background_color) { 66 $this->backgroundColor = $background_color; 67 return $this; 68 } 69 70 public function setPHID($phid) { 71 $this->phid = $phid; 72 return $this; 73 } 74 75 public function setName($name) { 76 $this->name = $name; 77 return $this; 78 } 79 80 public function setHref($href) { 81 $this->href = $href; 82 return $this; 83 } 84 85 public function setClosed($closed) { 86 $this->closed = $closed; 87 return $this; 88 } 89 90 public function setIcon($icon) { 91 $this->icon = $icon; 92 return $this; 93 } 94 95 public function setSlimShady($mm) { 96 $this->slimShady = $mm; 97 return $this; 98 } 99 100 protected function getTagName() { 101 return strlen($this->href) ? 'a' : 'span'; 102 } 103 104 protected function getTagAttributes() { 105 require_celerity_resource('phui-tag-view-css'); 106 107 $classes = array( 108 'phui-tag-view', 109 'phui-tag-type-'.$this->type, 110 ); 111 112 if ($this->shade) { 113 $classes[] = 'phui-tag-shade'; 114 $classes[] = 'phui-tag-shade-'.$this->shade; 115 if ($this->slimShady) { 116 $classes[] = 'phui-tag-shade-slim'; 117 } 118 } 119 120 if ($this->icon) { 121 $classes[] = 'phui-tag-icon-view'; 122 } 123 124 if ($this->phid) { 125 Javelin::initBehavior('phabricator-hovercards'); 126 127 $attributes = array( 128 'href' => $this->href, 129 'sigil' => 'hovercard', 130 'meta' => array( 131 'hoverPHID' => $this->phid, 132 ), 133 'target' => $this->external ? '_blank' : null, 134 ); 135 } else { 136 $attributes = array( 137 'href' => $this->href, 138 'target' => $this->external ? '_blank' : null, 139 ); 140 } 141 142 return $attributes + array('class' => $classes); 143 } 144 145 public function getTagContent() { 146 if (!$this->type) { 147 throw new Exception(pht('You must call setType() before render()!')); 148 } 149 150 $color = null; 151 if (!$this->shade && $this->backgroundColor) { 152 $color = 'phui-tag-color-'.$this->backgroundColor; 153 } 154 155 if ($this->dotColor) { 156 $dotcolor = 'phui-tag-color-'.$this->dotColor; 157 $dot = phutil_tag( 158 'span', 159 array( 160 'class' => 'phui-tag-dot '.$dotcolor, 161 ), 162 ''); 163 } else { 164 $dot = null; 165 } 166 167 if ($this->icon) { 168 $icon = id(new PHUIIconView()) 169 ->setIconFont($this->icon); 170 } else { 171 $icon = null; 172 } 173 174 $content = phutil_tag( 175 'span', 176 array( 177 'class' => 'phui-tag-core '.$color, 178 ), 179 array($dot, $this->name)); 180 181 if ($this->closed) { 182 $content = phutil_tag( 183 'span', 184 array( 185 'class' => 'phui-tag-core-closed', 186 ), 187 $content); 188 } 189 190 return array($icon, $content); 191 } 192 193 public static function getTagTypes() { 194 return array( 195 self::TYPE_PERSON, 196 self::TYPE_OBJECT, 197 self::TYPE_STATE, 198 ); 199 } 200 201 public static function getColors() { 202 return array( 203 self::COLOR_RED, 204 self::COLOR_ORANGE, 205 self::COLOR_YELLOW, 206 self::COLOR_BLUE, 207 self::COLOR_INDIGO, 208 self::COLOR_VIOLET, 209 self::COLOR_GREEN, 210 self::COLOR_BLACK, 211 self::COLOR_GREY, 212 self::COLOR_WHITE, 213 214 self::COLOR_OBJECT, 215 self::COLOR_PERSON, 216 ); 217 } 218 219 public static function getShades() { 220 return array_keys(self::getShadeMap()); 221 } 222 223 public static function getShadeMap() { 224 return array( 225 self::COLOR_RED => pht('Red'), 226 self::COLOR_ORANGE => pht('Orange'), 227 self::COLOR_YELLOW => pht('Yellow'), 228 self::COLOR_BLUE => pht('Blue'), 229 self::COLOR_INDIGO => pht('Indigo'), 230 self::COLOR_VIOLET => pht('Violet'), 231 self::COLOR_GREEN => pht('Green'), 232 self::COLOR_GREY => pht('Grey'), 233 self::COLOR_PINK => pht('Pink'), 234 self::COLOR_CHECKERED => pht('Checkered'), 235 self::COLOR_DISABLED => pht('Disabled'), 236 ); 237 } 238 239 public static function getShadeName($shade) { 240 return idx(self::getShadeMap(), $shade, $shade); 241 } 242 243 244 public function setExternal($external) { 245 $this->external = $external; 246 return $this; 247 } 248 249 public function getExternal() { 250 return $this->external; 251 } 252 253 }
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 |