Changeset View
Changeset View
Standalone View
Standalone View
src/view/form/PHUIErrorView.php
<?php | <?php | ||||
final class PHUIErrorView extends AphrontView { | final class PHUIErrorView extends AphrontView { | ||||
const SEVERITY_ERROR = 'error'; | const SEVERITY_ERROR = 'error'; | ||||
const SEVERITY_WARNING = 'warning'; | const SEVERITY_WARNING = 'warning'; | ||||
const SEVERITY_NOTICE = 'notice'; | const SEVERITY_NOTICE = 'notice'; | ||||
const SEVERITY_NODATA = 'nodata'; | const SEVERITY_NODATA = 'nodata'; | ||||
const SEVERITY_SUCCESS = 'success'; | |||||
btrahan: I think before this diff every time I've used SEVERITY_NOTICE I should have used… | |||||
private $title; | private $title; | ||||
private $errors; | private $errors; | ||||
private $severity; | private $severity; | ||||
private $id; | private $id; | ||||
private $buttons = array(); | |||||
public function setTitle($title) { | public function setTitle($title) { | ||||
$this->title = $title; | $this->title = $title; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setSeverity($severity) { | public function setSeverity($severity) { | ||||
$this->severity = $severity; | $this->severity = $severity; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setErrors(array $errors) { | public function setErrors(array $errors) { | ||||
$this->errors = $errors; | $this->errors = $errors; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setID($id) { | public function setID($id) { | ||||
$this->id = $id; | $this->id = $id; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function addButton($button) { | |||||
$this->buttons[] = $button; | |||||
return $this; | |||||
} | |||||
final public function render() { | final public function render() { | ||||
require_celerity_resource('phui-error-view-css'); | require_celerity_resource('phui-error-view-css'); | ||||
$errors = $this->errors; | $errors = $this->errors; | ||||
if ($errors) { | if ($errors) { | ||||
$list = array(); | $list = array(); | ||||
foreach ($errors as $error) { | foreach ($errors as $error) { | ||||
Show All 24 Lines | if (strlen($title)) { | ||||
$title = null; | $title = null; | ||||
} | } | ||||
$this->severity = nonempty($this->severity, self::SEVERITY_ERROR); | $this->severity = nonempty($this->severity, self::SEVERITY_ERROR); | ||||
$classes = array(); | $classes = array(); | ||||
$classes[] = 'phui-error-view'; | $classes[] = 'phui-error-view'; | ||||
$classes[] = 'phui-error-severity-'.$this->severity; | $classes[] = 'phui-error-severity-'.$this->severity; | ||||
$classes[] = 'grouped'; | |||||
$classes = implode(' ', $classes); | $classes = implode(' ', $classes); | ||||
$children = $this->renderChildren(); | $children = $this->renderChildren(); | ||||
if ($list) { | if ($list) { | ||||
$children[] = $list; | $children[] = $list; | ||||
} | } | ||||
$body = null; | $body = null; | ||||
if (!empty($children)) { | if (!empty($children)) { | ||||
$body = phutil_tag( | $body = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'phui-error-view-body', | 'class' => 'phui-error-view-body', | ||||
), | ), | ||||
$children); | $children); | ||||
} | } | ||||
$buttons = null; | |||||
if (!empty($this->buttons)) { | |||||
$buttons = phutil_tag( | |||||
'div', | |||||
array( | |||||
'class' => 'phui-error-view-actions', | |||||
), | |||||
$this->buttons); | |||||
} | |||||
return phutil_tag( | return phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'id' => $this->id, | 'id' => $this->id, | ||||
'class' => $classes, | 'class' => $classes, | ||||
), | ), | ||||
array( | array( | ||||
$buttons, | |||||
$title, | $title, | ||||
$body, | $body, | ||||
)); | )); | ||||
} | } | ||||
} | } |
I think before this diff every time I've used SEVERITY_NOTICE I should have used SEVERITY_SUCCESS...