[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PHUIObjectBoxView extends AphrontView { 4 5 private $headerText; 6 private $headerColor; 7 private $formErrors = null; 8 private $formSaved = false; 9 private $errorView; 10 private $form; 11 private $validationException; 12 private $header; 13 private $flush; 14 private $id; 15 private $sigils = array(); 16 private $metadata; 17 18 private $tabs = array(); 19 private $propertyLists = array(); 20 21 public function addSigil($sigil) { 22 $this->sigils[] = $sigil; 23 return $this; 24 } 25 26 public function setMetadata(array $metadata) { 27 $this->metadata = $metadata; 28 return $this; 29 } 30 31 public function addPropertyList( 32 PHUIPropertyListView $property_list, 33 $tab = null) { 34 35 if (!($tab instanceof PHUIListItemView) && 36 ($tab !== null)) { 37 assert_stringlike($tab); 38 $tab = id(new PHUIListItemView())->setName($tab); 39 } 40 41 if ($tab) { 42 if ($tab->getKey()) { 43 $key = $tab->getKey(); 44 } else { 45 $key = 'tab.default.'.spl_object_hash($tab); 46 $tab->setKey($key); 47 } 48 } else { 49 $key = 'tab.default'; 50 } 51 52 if ($tab) { 53 if (empty($this->tabs[$key])) { 54 $tab->addSigil('phui-object-box-tab'); 55 $tab->setMetadata( 56 array( 57 'tabKey' => $key, 58 )); 59 60 if (!$tab->getHref()) { 61 $tab->setHref('#'); 62 } 63 64 if (!$tab->getType()) { 65 $tab->setType(PHUIListItemView::TYPE_LINK); 66 } 67 68 $this->tabs[$key] = $tab; 69 } 70 } 71 72 $this->propertyLists[$key][] = $property_list; 73 74 return $this; 75 } 76 77 public function setHeaderText($text) { 78 $this->headerText = $text; 79 return $this; 80 } 81 82 public function setHeaderColor($color) { 83 $this->headerColor = $color; 84 return $this; 85 } 86 87 public function setFormErrors(array $errors, $title = null) { 88 if ($errors) { 89 $this->formErrors = id(new AphrontErrorView()) 90 ->setTitle($title) 91 ->setErrors($errors); 92 } 93 return $this; 94 } 95 96 public function setFormSaved($saved, $text = null) { 97 if (!$text) { 98 $text = pht('Changes saved.'); 99 } 100 if ($saved) { 101 $save = id(new AphrontErrorView()) 102 ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) 103 ->appendChild($text); 104 $this->formSaved = $save; 105 } 106 return $this; 107 } 108 109 public function setErrorView(AphrontErrorView $view) { 110 $this->errorView = $view; 111 return $this; 112 } 113 114 public function setForm($form) { 115 $this->form = $form; 116 return $this; 117 } 118 119 public function setID($id) { 120 $this->id = $id; 121 return $this; 122 } 123 124 public function setHeader($header) { 125 $this->header = $header; 126 return $this; 127 } 128 129 public function setFlush($flush) { 130 $this->flush = $flush; 131 return $this; 132 } 133 134 public function setValidationException( 135 PhabricatorApplicationTransactionValidationException $ex = null) { 136 $this->validationException = $ex; 137 return $this; 138 } 139 140 public function render() { 141 142 require_celerity_resource('phui-object-box-css'); 143 144 if ($this->headerColor) { 145 $header_color = $this->headerColor; 146 } else { 147 $header_color = PHUIActionHeaderView::HEADER_LIGHTBLUE; 148 } 149 150 if ($this->header) { 151 $header = $this->header; 152 $header->setHeaderColor($header_color); 153 } else { 154 $header = id(new PHUIHeaderView()) 155 ->setHeader($this->headerText) 156 ->setHeaderColor($header_color); 157 } 158 159 $ex = $this->validationException; 160 $exception_errors = null; 161 if ($ex) { 162 $messages = array(); 163 foreach ($ex->getErrors() as $error) { 164 $messages[] = $error->getMessage(); 165 } 166 if ($messages) { 167 $exception_errors = id(new AphrontErrorView()) 168 ->setErrors($messages); 169 } 170 } 171 172 $tab_lists = array(); 173 $property_lists = array(); 174 $tab_map = array(); 175 176 $default_key = 'tab.default'; 177 178 // Find the selected tab, or select the first tab if none are selected. 179 if ($this->tabs) { 180 $selected_tab = null; 181 foreach ($this->tabs as $key => $tab) { 182 if ($tab->getSelected()) { 183 $selected_tab = $key; 184 break; 185 } 186 } 187 if ($selected_tab === null) { 188 head($this->tabs)->setSelected(true); 189 $selected_tab = head_key($this->tabs); 190 } 191 } 192 193 foreach ($this->propertyLists as $key => $list) { 194 $group = new PHUIPropertyGroupView(); 195 $i = 0; 196 foreach ($list as $item) { 197 $group->addPropertyList($item); 198 if ($i > 0) { 199 $item->addClass('phui-property-list-section-noninitial'); 200 } 201 $i++; 202 } 203 204 if ($this->tabs && $key != $default_key) { 205 $tab_id = celerity_generate_unique_node_id(); 206 $tab_map[$key] = $tab_id; 207 208 if ($key === $selected_tab) { 209 $style = null; 210 } else { 211 $style = 'display: none'; 212 } 213 214 $tab_lists[] = phutil_tag( 215 'div', 216 array( 217 'style' => $style, 218 'id' => $tab_id, 219 ), 220 $group); 221 } else { 222 if ($this->tabs) { 223 $group->addClass('phui-property-group-noninitial'); 224 } 225 $property_lists[] = $group; 226 } 227 } 228 229 $tabs = null; 230 if ($this->tabs) { 231 $tabs = id(new PHUIListView()) 232 ->setType(PHUIListView::NAVBAR_LIST); 233 foreach ($this->tabs as $tab) { 234 $tabs->addMenuItem($tab); 235 } 236 237 Javelin::initBehavior('phui-object-box-tabs'); 238 } 239 240 $content = id(new PHUIBoxView()) 241 ->appendChild( 242 array( 243 $header, 244 $this->errorView, 245 $this->formErrors, 246 $this->formSaved, 247 $exception_errors, 248 $this->form, 249 $tabs, 250 $tab_lists, 251 $property_lists, 252 $this->renderChildren(), 253 )) 254 ->setBorder(true) 255 ->setID($this->id) 256 ->addMargin(PHUI::MARGIN_LARGE_TOP) 257 ->addMargin(PHUI::MARGIN_LARGE_LEFT) 258 ->addMargin(PHUI::MARGIN_LARGE_RIGHT) 259 ->addClass('phui-object-box'); 260 261 if ($this->tabs) { 262 $content->addSigil('phui-object-box'); 263 $content->setMetadata( 264 array( 265 'tabMap' => $tab_map, 266 )); 267 } 268 269 if ($this->flush) { 270 $content->addClass('phui-object-box-flush'); 271 } 272 273 $content->addClass('phui-object-box-'.$header_color); 274 275 foreach ($this->sigils as $sigil) { 276 $content->addSigil($sigil); 277 } 278 279 if ($this->metadata !== null) { 280 $content->setMetadata($this->metadata); 281 } 282 283 return $content; 284 } 285 }
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 |