3 final class PHUIInfoView
extends AphrontTagView
{
5 const SEVERITY_ERROR
= 'error';
6 const SEVERITY_WARNING
= 'warning';
7 const SEVERITY_NOTICE
= 'notice';
8 const SEVERITY_NODATA
= 'nodata';
9 const SEVERITY_SUCCESS
= 'success';
10 const SEVERITY_PLAIN
= 'plain';
11 const SEVERITY_MFA
= 'mfa';
14 private $errors = array();
15 private $severity = null;
17 private $buttons = array();
22 public function setTitle($title) {
23 $this->title
= $title;
27 public function setSeverity($severity) {
28 $this->severity
= $severity;
32 private function getSeverity() {
33 $severity = $this->severity ?
$this->severity
: self
::SEVERITY_ERROR
;
37 public function setErrors(array $errors) {
38 $this->errors
= $errors;
42 public function setID($id) {
47 public function setIsHidden($is_hidden) {
48 $this->isHidden
= $is_hidden;
52 public function setFlush($flush) {
53 $this->flush
= $flush;
57 public function setIcon($icon) {
58 if ($icon instanceof PHUIIconView
) {
61 $icon = id(new PHUIIconView())
69 private function getIcon() {
74 switch ($this->getSeverity()) {
75 case self
::SEVERITY_ERROR
:
76 $icon = 'fa-exclamation-circle';
78 case self
::SEVERITY_WARNING
:
79 $icon = 'fa-exclamation-triangle';
81 case self
::SEVERITY_NOTICE
:
82 $icon = 'fa-info-circle';
84 case self
::SEVERITY_PLAIN
:
85 case self
::SEVERITY_NODATA
:
87 case self
::SEVERITY_SUCCESS
:
88 $icon = 'fa-check-circle';
90 case self
::SEVERITY_MFA
:
95 $icon = id(new PHUIIconView())
97 ->addClass('phui-info-icon');
101 public function addButton(PHUIButtonView
$button) {
102 $this->buttons
[] = $button;
106 protected function getTagAttributes() {
108 $classes[] = 'phui-info-view';
109 $classes[] = 'phui-info-severity-'.$this->getSeverity();
110 $classes[] = 'grouped';
112 $classes[] = 'phui-info-view-flush';
114 if ($this->getIcon()) {
115 $classes[] = 'phui-info-has-icon';
120 'class' => implode(' ', $classes),
121 'style' => $this->isHidden ?
'display: none;' : null,
125 protected function getTagContent() {
126 require_celerity_resource('phui-info-view-css');
128 $errors = $this->errors
;
129 if (count($errors) > 1) {
131 foreach ($errors as $error) {
132 $list[] = phutil_tag(
140 'class' => 'phui-info-view-list',
143 } else if (count($errors) == 1) {
144 $list = head($this->errors
);
149 $title = $this->title
;
150 if ($title !== null && strlen($title)) {
154 'class' => 'phui-info-view-head',
161 $children = $this->renderChildren();
167 if (!empty($children)) {
171 'class' => 'phui-info-view-body',
177 if (!empty($this->buttons
)) {
178 $buttons = phutil_tag(
181 'class' => 'phui-info-view-actions',
187 if ($this->getIcon()) {
191 'class' => 'phui-info-view-icon',