[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AphrontDialogView extends AphrontView { 4 5 private $title; 6 private $shortTitle; 7 private $submitButton; 8 private $cancelURI; 9 private $cancelText = 'Cancel'; 10 private $submitURI; 11 private $hidden = array(); 12 private $class; 13 private $renderAsForm = true; 14 private $formID; 15 private $headerColor = PHUIActionHeaderView::HEADER_LIGHTBLUE; 16 private $footers = array(); 17 private $isStandalone; 18 private $method = 'POST'; 19 private $disableWorkflowOnSubmit; 20 private $disableWorkflowOnCancel; 21 private $width = 'default'; 22 private $errors = array(); 23 private $flush; 24 private $validationException; 25 26 27 const WIDTH_DEFAULT = 'default'; 28 const WIDTH_FORM = 'form'; 29 const WIDTH_FULL = 'full'; 30 31 public function setMethod($method) { 32 $this->method = $method; 33 return $this; 34 } 35 36 public function setIsStandalone($is_standalone) { 37 $this->isStandalone = $is_standalone; 38 return $this; 39 } 40 41 public function setErrors(array $errors) { 42 $this->errors = $errors; 43 return $this; 44 } 45 46 public function getIsStandalone() { 47 return $this->isStandalone; 48 } 49 50 public function setSubmitURI($uri) { 51 $this->submitURI = $uri; 52 return $this; 53 } 54 55 public function setTitle($title) { 56 $this->title = $title; 57 return $this; 58 } 59 60 public function getTitle() { 61 return $this->title; 62 } 63 64 public function setShortTitle($short_title) { 65 $this->shortTitle = $short_title; 66 return $this; 67 } 68 69 public function getShortTitle() { 70 return $this->shortTitle; 71 } 72 73 public function addSubmitButton($text = null) { 74 if (!$text) { 75 $text = pht('Okay'); 76 } 77 78 $this->submitButton = $text; 79 return $this; 80 } 81 82 public function addCancelButton($uri, $text = null) { 83 if (!$text) { 84 $text = pht('Cancel'); 85 } 86 87 $this->cancelURI = $uri; 88 $this->cancelText = $text; 89 return $this; 90 } 91 92 public function addFooter($footer) { 93 $this->footers[] = $footer; 94 return $this; 95 } 96 97 public function addHiddenInput($key, $value) { 98 if (is_array($value)) { 99 foreach ($value as $hidden_key => $hidden_value) { 100 $this->hidden[] = array($key.'['.$hidden_key.']', $hidden_value); 101 } 102 } else { 103 $this->hidden[] = array($key, $value); 104 } 105 return $this; 106 } 107 108 public function setClass($class) { 109 $this->class = $class; 110 return $this; 111 } 112 113 public function setFlush($flush) { 114 $this->flush = $flush; 115 return $this; 116 } 117 118 public function setRenderDialogAsDiv() { 119 // TODO: This API is awkward. 120 $this->renderAsForm = false; 121 return $this; 122 } 123 124 public function setFormID($id) { 125 $this->formID = $id; 126 return $this; 127 } 128 129 public function setWidth($width) { 130 $this->width = $width; 131 return $this; 132 } 133 134 public function setHeaderColor($color) { 135 $this->headerColor = $color; 136 return $this; 137 } 138 139 public function appendParagraph($paragraph) { 140 return $this->appendChild( 141 phutil_tag( 142 'p', 143 array( 144 'class' => 'aphront-dialog-view-paragraph', 145 ), 146 $paragraph)); 147 } 148 149 public function appendForm(AphrontFormView $form) { 150 return $this->appendChild($form->buildLayoutView()); 151 } 152 153 public function setDisableWorkflowOnSubmit($disable_workflow_on_submit) { 154 $this->disableWorkflowOnSubmit = $disable_workflow_on_submit; 155 return $this; 156 } 157 158 public function getDisableWorkflowOnSubmit() { 159 return $this->disableWorkflowOnSubmit; 160 } 161 162 public function setDisableWorkflowOnCancel($disable_workflow_on_cancel) { 163 $this->disableWorkflowOnCancel = $disable_workflow_on_cancel; 164 return $this; 165 } 166 167 public function getDisableWorkflowOnCancel() { 168 return $this->disableWorkflowOnCancel; 169 } 170 171 public function setValidationException( 172 PhabricatorApplicationTransactionValidationException $ex = null) { 173 $this->validationException = $ex; 174 return $this; 175 } 176 177 final public function render() { 178 require_celerity_resource('aphront-dialog-view-css'); 179 180 $buttons = array(); 181 if ($this->submitButton) { 182 $meta = array(); 183 if ($this->disableWorkflowOnSubmit) { 184 $meta['disableWorkflow'] = true; 185 } 186 187 $buttons[] = javelin_tag( 188 'button', 189 array( 190 'name' => '__submit__', 191 'sigil' => '__default__', 192 'type' => 'submit', 193 'meta' => $meta, 194 ), 195 $this->submitButton); 196 } 197 198 if ($this->cancelURI) { 199 $meta = array(); 200 if ($this->disableWorkflowOnCancel) { 201 $meta['disableWorkflow'] = true; 202 } 203 204 $buttons[] = javelin_tag( 205 'a', 206 array( 207 'href' => $this->cancelURI, 208 'class' => 'button grey', 209 'name' => '__cancel__', 210 'sigil' => 'jx-workflow-button', 211 'meta' => $meta, 212 ), 213 $this->cancelText); 214 } 215 216 if (!$this->user) { 217 throw new Exception( 218 pht('You must call setUser() when rendering an AphrontDialogView.')); 219 } 220 221 $more = $this->class; 222 if ($this->flush) { 223 $more .= ' aphront-dialog-flush'; 224 } 225 226 switch ($this->width) { 227 case self::WIDTH_FORM: 228 case self::WIDTH_FULL: 229 $more .= ' aphront-dialog-view-width-'.$this->width; 230 break; 231 case self::WIDTH_DEFAULT: 232 break; 233 default: 234 throw new Exception("Unknown dialog width '{$this->width}'!"); 235 } 236 237 if ($this->isStandalone) { 238 $more .= ' aphront-dialog-view-standalone'; 239 } 240 241 $attributes = array( 242 'class' => 'aphront-dialog-view '.$more, 243 'sigil' => 'jx-dialog', 244 ); 245 246 $form_attributes = array( 247 'action' => $this->submitURI, 248 'method' => $this->method, 249 'id' => $this->formID, 250 ); 251 252 $hidden_inputs = array(); 253 $hidden_inputs[] = phutil_tag( 254 'input', 255 array( 256 'type' => 'hidden', 257 'name' => '__dialog__', 258 'value' => '1', 259 )); 260 261 foreach ($this->hidden as $desc) { 262 list($key, $value) = $desc; 263 $hidden_inputs[] = javelin_tag( 264 'input', 265 array( 266 'type' => 'hidden', 267 'name' => $key, 268 'value' => $value, 269 'sigil' => 'aphront-dialog-application-input', 270 )); 271 } 272 273 if (!$this->renderAsForm) { 274 $buttons = array(phabricator_form( 275 $this->user, 276 $form_attributes, 277 array_merge($hidden_inputs, $buttons)), 278 ); 279 } 280 281 $children = $this->renderChildren(); 282 283 $errors = $this->errors; 284 285 $ex = $this->validationException; 286 $exception_errors = null; 287 if ($ex) { 288 foreach ($ex->getErrors() as $error) { 289 $errors[] = $error->getMessage(); 290 } 291 } 292 293 if ($errors) { 294 $children = array( 295 id(new AphrontErrorView())->setErrors($errors), 296 $children, 297 ); 298 } 299 300 $header = new PHUIActionHeaderView(); 301 $header->setHeaderTitle($this->title); 302 $header->setHeaderColor($this->headerColor); 303 304 $footer = null; 305 if ($this->footers) { 306 $footer = phutil_tag( 307 'div', 308 array( 309 'class' => 'aphront-dialog-foot', 310 ), 311 $this->footers); 312 } 313 314 $content = array( 315 phutil_tag( 316 'div', 317 array( 318 'class' => 'aphront-dialog-head', 319 ), 320 $header), 321 phutil_tag('div', 322 array( 323 'class' => 'aphront-dialog-body grouped', 324 ), 325 $children), 326 phutil_tag( 327 'div', 328 array( 329 'class' => 'aphront-dialog-tail grouped', 330 ), 331 array( 332 $buttons, 333 $footer, 334 )), 335 ); 336 337 if ($this->renderAsForm) { 338 return phabricator_form( 339 $this->user, 340 $form_attributes + $attributes, 341 array($hidden_inputs, $content)); 342 } else { 343 return javelin_tag( 344 'div', 345 $attributes, 346 $content); 347 } 348 } 349 350 }
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 |