Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUIObjectBoxView.php
12249 views
1
<?php
2
3
final class PHUIObjectBoxView extends AphrontTagView {
4
5
private $headerText;
6
private $color;
7
private $background;
8
private $tabGroups = array();
9
private $formErrors = null;
10
private $infoView;
11
private $form;
12
private $validationException;
13
private $header;
14
private $flush;
15
private $actionListID;
16
private $objectList;
17
private $table;
18
private $collapsed = false;
19
private $anchor;
20
private $pager;
21
22
private $showAction;
23
private $hideAction;
24
private $showHideHref;
25
private $showHideContent;
26
private $showHideOpen;
27
28
private $propertyLists = array();
29
private $tailButtons = array();
30
31
const COLOR_RED = 'red';
32
const COLOR_BLUE = 'blue';
33
const COLOR_GREEN = 'green';
34
const COLOR_YELLOW = 'yellow';
35
36
const BLUE = 'phui-box-blue';
37
const BLUE_PROPERTY = 'phui-box-blue-property';
38
const WHITE_CONFIG = 'phui-box-white-config';
39
const GREY = 'phui-box-grey';
40
41
public function addPropertyList(PHUIPropertyListView $property_list) {
42
$this->propertyLists[] = $property_list;
43
44
$action_list = $property_list->getActionList();
45
if ($action_list) {
46
$this->actionListID = celerity_generate_unique_node_id();
47
$action_list->setId($this->actionListID);
48
}
49
50
return $this;
51
}
52
53
public function setHeaderText($text) {
54
$this->headerText = $text;
55
return $this;
56
}
57
58
public function setColor($color) {
59
$this->color = $color;
60
return $this;
61
}
62
63
public function setBackground($color) {
64
$this->background = $color;
65
return $this;
66
}
67
68
public function setFormErrors(array $errors, $title = null) {
69
if ($errors) {
70
$this->formErrors = id(new PHUIInfoView())
71
->setTitle($title)
72
->setErrors($errors);
73
}
74
return $this;
75
}
76
77
public function addTabGroup(PHUITabGroupView $view) {
78
$this->tabGroups[] = $view;
79
return $this;
80
}
81
82
public function setInfoView(PHUIInfoView $view) {
83
$this->infoView = $view;
84
return $this;
85
}
86
87
public function setForm($form) {
88
$this->form = $form;
89
return $this;
90
}
91
92
public function setHeader($header) {
93
$this->header = $header;
94
return $this;
95
}
96
97
public function setFlush($flush) {
98
$this->flush = $flush;
99
return $this;
100
}
101
102
public function setObjectList($list) {
103
$this->objectList = $list;
104
return $this;
105
}
106
107
public function setTable($table) {
108
$this->collapsed = true;
109
$this->table = $table;
110
return $this;
111
}
112
113
public function setCollapsed($collapsed) {
114
$this->collapsed = $collapsed;
115
return $this;
116
}
117
118
public function setPager(PHUIPagerView $pager) {
119
$this->pager = $pager;
120
return $this;
121
}
122
123
public function setAnchor(PhabricatorAnchorView $anchor) {
124
$this->anchor = $anchor;
125
return $this;
126
}
127
128
public function setShowHide($show, $hide, $content, $href, $open = false) {
129
$this->showAction = $show;
130
$this->hideAction = $hide;
131
$this->showHideContent = $content;
132
$this->showHideHref = $href;
133
$this->showHideOpen = $open;
134
return $this;
135
}
136
137
public function setValidationException(
138
PhabricatorApplicationTransactionValidationException $ex = null) {
139
$this->validationException = $ex;
140
return $this;
141
}
142
143
public function newTailButton() {
144
$button = id(new PHUIButtonView())
145
->setTag('a')
146
->setColor(PHUIButtonView::GREY);
147
148
$this->tailButtons[] = $button;
149
150
return $button;
151
}
152
153
protected function getTagAttributes() {
154
$classes = array();
155
$classes[] = 'phui-box';
156
$classes[] = 'phui-box-border';
157
$classes[] = 'phui-object-box';
158
$classes[] = 'mlt mll mlr';
159
160
if ($this->color) {
161
$classes[] = 'phui-object-box-'.$this->color;
162
}
163
164
if ($this->collapsed) {
165
$classes[] = 'phui-object-box-collapsed';
166
}
167
168
if ($this->flush) {
169
$classes[] = 'phui-object-box-flush';
170
}
171
172
if ($this->background) {
173
$classes[] = $this->background;
174
}
175
176
return array(
177
'class' => implode(' ', $classes),
178
);
179
}
180
181
protected function getTagContent() {
182
require_celerity_resource('phui-box-css');
183
require_celerity_resource('phui-object-box-css');
184
185
$header = $this->header;
186
187
if ($this->headerText) {
188
$header = id(new PHUIHeaderView())
189
->setHeader($this->headerText);
190
}
191
192
$showhide = null;
193
if ($this->showAction !== null) {
194
if (!$header) {
195
$header = id(new PHUIHeaderView());
196
}
197
198
Javelin::initBehavior('phabricator-reveal-content');
199
200
$hide_action_id = celerity_generate_unique_node_id();
201
$show_action_id = celerity_generate_unique_node_id();
202
$content_id = celerity_generate_unique_node_id();
203
204
$hide_style = ($this->showHideOpen ? 'display: none;': null);
205
$show_style = ($this->showHideOpen ? null : 'display: none;');
206
$hide_action = id(new PHUIButtonView())
207
->setTag('a')
208
->addSigil('reveal-content')
209
->setID($hide_action_id)
210
->setStyle($hide_style)
211
->setIcon('fa-search')
212
->setHref($this->showHideHref)
213
->setMetaData(
214
array(
215
'hideIDs' => array($hide_action_id),
216
'showIDs' => array($content_id, $show_action_id),
217
))
218
->setText($this->showAction);
219
220
$show_action = id(new PHUIButtonView())
221
->setTag('a')
222
->addSigil('reveal-content')
223
->setStyle($show_style)
224
->setIcon('fa-search')
225
->setHref('#')
226
->setID($show_action_id)
227
->setMetaData(
228
array(
229
'hideIDs' => array($content_id, $show_action_id),
230
'showIDs' => array($hide_action_id),
231
))
232
->setText($this->hideAction);
233
234
$header->addActionLink($hide_action);
235
$header->addActionLink($show_action);
236
237
$showhide = array(
238
phutil_tag(
239
'div',
240
array(
241
'class' => 'phui-object-box-hidden-content',
242
'id' => $content_id,
243
'style' => $show_style,
244
),
245
$this->showHideContent),
246
);
247
}
248
249
250
if ($this->actionListID) {
251
$icon_id = celerity_generate_unique_node_id();
252
$icon = id(new PHUIIconView())
253
->setIcon('fa-bars');
254
$meta = array(
255
'map' => array(
256
$this->actionListID => 'phabricator-action-list-toggle',
257
$icon_id => 'phuix-dropdown-open',
258
),
259
);
260
$mobile_menu = id(new PHUIButtonView())
261
->setTag('a')
262
->setText(pht('Actions'))
263
->setHref('#')
264
->setIcon($icon)
265
->addClass('phui-mobile-menu')
266
->setID($icon_id)
267
->addSigil('jx-toggle-class')
268
->setMetadata($meta);
269
$header->addActionLink($mobile_menu);
270
}
271
272
$ex = $this->validationException;
273
$exception_errors = null;
274
if ($ex) {
275
$messages = array();
276
foreach ($ex->getErrors() as $error) {
277
$messages[] = $error->getMessage();
278
}
279
if ($messages) {
280
$exception_errors = id(new PHUIInfoView())
281
->setErrors($messages);
282
}
283
}
284
285
if ($this->propertyLists) {
286
$lists = new PHUIPropertyGroupView();
287
288
$ii = 0;
289
foreach ($this->propertyLists as $list) {
290
if ($ii > 0 || $this->tabGroups) {
291
$list->addClass('phui-property-list-section-noninitial');
292
}
293
294
$lists->addPropertyList($list);
295
$ii++;
296
}
297
} else {
298
$lists = null;
299
}
300
301
$pager = null;
302
if ($this->pager) {
303
if ($this->pager->willShowPagingControls()) {
304
$pager = phutil_tag_div('phui-object-box-pager', $this->pager);
305
}
306
}
307
308
$content = array(
309
($this->showHideOpen == false ? $this->anchor : null),
310
$header,
311
$this->infoView,
312
$this->formErrors,
313
$exception_errors,
314
$this->form,
315
$this->tabGroups,
316
$showhide,
317
($this->showHideOpen == true ? $this->anchor : null),
318
$lists,
319
$this->table,
320
$pager,
321
$this->renderChildren(),
322
);
323
324
if ($this->objectList) {
325
$content[] = $this->objectList;
326
}
327
328
if ($this->tailButtons) {
329
$content[] = phutil_tag(
330
'div',
331
array(
332
'class' => 'phui-object-box-tail-buttons',
333
),
334
$this->tailButtons);
335
}
336
337
return $content;
338
}
339
}
340
341