Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUIInfoView.php
12249 views
1
<?php
2
3
final class PHUIInfoView extends AphrontTagView {
4
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';
12
13
private $title;
14
private $errors = array();
15
private $severity = null;
16
private $id;
17
private $buttons = array();
18
private $isHidden;
19
private $flush;
20
private $icon;
21
22
public function setTitle($title) {
23
$this->title = $title;
24
return $this;
25
}
26
27
public function setSeverity($severity) {
28
$this->severity = $severity;
29
return $this;
30
}
31
32
private function getSeverity() {
33
$severity = $this->severity ? $this->severity : self::SEVERITY_ERROR;
34
return $severity;
35
}
36
37
public function setErrors(array $errors) {
38
$this->errors = $errors;
39
return $this;
40
}
41
42
public function setID($id) {
43
$this->id = $id;
44
return $this;
45
}
46
47
public function setIsHidden($is_hidden) {
48
$this->isHidden = $is_hidden;
49
return $this;
50
}
51
52
public function setFlush($flush) {
53
$this->flush = $flush;
54
return $this;
55
}
56
57
public function setIcon($icon) {
58
if ($icon instanceof PHUIIconView) {
59
$this->icon = $icon;
60
} else {
61
$icon = id(new PHUIIconView())
62
->setIcon($icon);
63
$this->icon = $icon;
64
}
65
66
return $this;
67
}
68
69
private function getIcon() {
70
if ($this->icon) {
71
return $this->icon;
72
}
73
74
switch ($this->getSeverity()) {
75
case self::SEVERITY_ERROR:
76
$icon = 'fa-exclamation-circle';
77
break;
78
case self::SEVERITY_WARNING:
79
$icon = 'fa-exclamation-triangle';
80
break;
81
case self::SEVERITY_NOTICE:
82
$icon = 'fa-info-circle';
83
break;
84
case self::SEVERITY_PLAIN:
85
case self::SEVERITY_NODATA:
86
return null;
87
case self::SEVERITY_SUCCESS:
88
$icon = 'fa-check-circle';
89
break;
90
case self::SEVERITY_MFA:
91
$icon = 'fa-lock';
92
break;
93
}
94
95
$icon = id(new PHUIIconView())
96
->setIcon($icon)
97
->addClass('phui-info-icon');
98
return $icon;
99
}
100
101
public function addButton(PHUIButtonView $button) {
102
$this->buttons[] = $button;
103
return $this;
104
}
105
106
protected function getTagAttributes() {
107
$classes = array();
108
$classes[] = 'phui-info-view';
109
$classes[] = 'phui-info-severity-'.$this->getSeverity();
110
$classes[] = 'grouped';
111
if ($this->flush) {
112
$classes[] = 'phui-info-view-flush';
113
}
114
if ($this->getIcon()) {
115
$classes[] = 'phui-info-has-icon';
116
}
117
118
return array(
119
'id' => $this->id,
120
'class' => implode(' ', $classes),
121
'style' => $this->isHidden ? 'display: none;' : null,
122
);
123
}
124
125
protected function getTagContent() {
126
require_celerity_resource('phui-info-view-css');
127
128
$errors = $this->errors;
129
if (count($errors) > 1) {
130
$list = array();
131
foreach ($errors as $error) {
132
$list[] = phutil_tag(
133
'li',
134
array(),
135
$error);
136
}
137
$list = phutil_tag(
138
'ul',
139
array(
140
'class' => 'phui-info-view-list',
141
),
142
$list);
143
} else if (count($errors) == 1) {
144
$list = head($this->errors);
145
} else {
146
$list = null;
147
}
148
149
$title = $this->title;
150
if ($title !== null && strlen($title)) {
151
$title = phutil_tag(
152
'h1',
153
array(
154
'class' => 'phui-info-view-head',
155
),
156
$title);
157
} else {
158
$title = null;
159
}
160
161
$children = $this->renderChildren();
162
if ($list) {
163
$children[] = $list;
164
}
165
166
$body = null;
167
if (!empty($children)) {
168
$body = phutil_tag(
169
'div',
170
array(
171
'class' => 'phui-info-view-body',
172
),
173
$children);
174
}
175
176
$buttons = null;
177
if (!empty($this->buttons)) {
178
$buttons = phutil_tag(
179
'div',
180
array(
181
'class' => 'phui-info-view-actions',
182
),
183
$this->buttons);
184
}
185
186
$icon = null;
187
if ($this->getIcon()) {
188
$icon = phutil_tag(
189
'div',
190
array(
191
'class' => 'phui-info-view-icon',
192
),
193
$this->getIcon());
194
}
195
196
return array(
197
$icon,
198
$buttons,
199
$title,
200
$body,
201
);
202
}
203
}
204
205