Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUIListItemView.php
12249 views
1
<?php
2
3
final class PHUIListItemView extends AphrontTagView {
4
5
const TYPE_LINK = 'type-link';
6
const TYPE_SPACER = 'type-spacer';
7
const TYPE_LABEL = 'type-label';
8
const TYPE_BUTTON = 'type-button';
9
const TYPE_CUSTOM = 'type-custom';
10
const TYPE_DIVIDER = 'type-divider';
11
const TYPE_ICON = 'type-icon';
12
13
const STATUS_WARN = 'phui-list-item-warn';
14
const STATUS_FAIL = 'phui-list-item-fail';
15
16
private $name;
17
private $href;
18
private $type = self::TYPE_LINK;
19
private $isExternal;
20
private $key;
21
private $icon;
22
private $selected;
23
private $disabled;
24
private $renderNameAsTooltip;
25
private $statusColor;
26
private $order;
27
private $aural;
28
private $profileImage;
29
private $indented;
30
private $hideInApplicationMenu;
31
private $icons = array();
32
private $openInNewWindow = false;
33
private $tooltip;
34
private $actionIcon;
35
private $actionIconHref;
36
private $count;
37
private $rel;
38
private $dropdownMenu;
39
private $keyCommand;
40
41
public function setOpenInNewWindow($open_in_new_window) {
42
$this->openInNewWindow = $open_in_new_window;
43
return $this;
44
}
45
46
public function getOpenInNewWindow() {
47
return $this->openInNewWindow;
48
}
49
50
public function setRel($rel) {
51
$this->rel = $rel;
52
return $this;
53
}
54
55
public function getRel() {
56
return $this->rel;
57
}
58
59
public function setHideInApplicationMenu($hide) {
60
$this->hideInApplicationMenu = $hide;
61
return $this;
62
}
63
64
public function getHideInApplicationMenu() {
65
return $this->hideInApplicationMenu;
66
}
67
68
public function setDropdownMenu(PhabricatorActionListView $actions) {
69
70
$this->dropdownMenu = $actions;
71
72
// TODO: "PHUICrumbsView" currently creates a bad copy of list items
73
// by reading some of their properties. To survive this copy step, we
74
// need to mutate "$this" immediately or the "Create Object" dropdown
75
// when multiple create forms exist breaks.
76
77
if (!$this->actionIcon) {
78
Javelin::initBehavior('phui-dropdown-menu');
79
$this->addSigil('phui-dropdown-menu');
80
$this->setMetadata($actions->getDropdownMenuMetadata());
81
}
82
83
return $this;
84
}
85
86
public function setAural($aural) {
87
$this->aural = $aural;
88
return $this;
89
}
90
91
public function getAural() {
92
return $this->aural;
93
}
94
95
public function setOrder($order) {
96
$this->order = $order;
97
return $this;
98
}
99
100
public function getOrder() {
101
return $this->order;
102
}
103
104
public function setRenderNameAsTooltip($render_name_as_tooltip) {
105
$this->renderNameAsTooltip = $render_name_as_tooltip;
106
return $this;
107
}
108
109
public function getRenderNameAsTooltip() {
110
return $this->renderNameAsTooltip;
111
}
112
113
public function setSelected($selected) {
114
$this->selected = $selected;
115
return $this;
116
}
117
118
public function getSelected() {
119
return $this->selected;
120
}
121
122
public function setIcon($icon) {
123
$this->icon = $icon;
124
return $this;
125
}
126
127
public function setProfileImage($image) {
128
$this->profileImage = $image;
129
return $this;
130
}
131
132
public function getIcon() {
133
return $this->icon;
134
}
135
136
public function setCount($count) {
137
$this->count = $count;
138
return $this;
139
}
140
141
public function setIndented($indented) {
142
$this->indented = $indented;
143
return $this;
144
}
145
146
public function getIndented() {
147
return $this->indented;
148
}
149
150
public function setKey($key) {
151
$this->key = (string)$key;
152
return $this;
153
}
154
155
public function getKey() {
156
return $this->key;
157
}
158
159
public function setType($type) {
160
$this->type = $type;
161
return $this;
162
}
163
164
public function getType() {
165
return $this->type;
166
}
167
168
public function setHref($href) {
169
$this->href = $href;
170
return $this;
171
}
172
173
public function getHref() {
174
return $this->href;
175
}
176
177
public function setName($name) {
178
$this->name = $name;
179
return $this;
180
}
181
182
public function getName() {
183
return $this->name;
184
}
185
186
public function setActionIcon($icon, $href) {
187
$this->actionIcon = $icon;
188
$this->actionIconHref = $href;
189
return $this;
190
}
191
192
public function setIsExternal($is_external) {
193
$this->isExternal = $is_external;
194
return $this;
195
}
196
197
public function getIsExternal() {
198
return $this->isExternal;
199
}
200
201
public function setStatusColor($color) {
202
$this->statusColor = $color;
203
return $this;
204
}
205
206
public function addIcon($icon) {
207
$this->icons[] = $icon;
208
return $this;
209
}
210
211
public function getIcons() {
212
return $this->icons;
213
}
214
215
public function setTooltip($tooltip) {
216
$this->tooltip = $tooltip;
217
return $this;
218
}
219
220
protected function getTagName() {
221
return 'li';
222
}
223
224
public function setKeyCommand($key_command) {
225
$this->keyCommand = $key_command;
226
return $this;
227
}
228
229
public function getKeyCommand() {
230
return $this->keyCommand;
231
}
232
233
protected function getTagAttributes() {
234
$classes = array();
235
$classes[] = 'phui-list-item-view';
236
$classes[] = 'phui-list-item-'.$this->type;
237
238
if ($this->icon || $this->profileImage) {
239
$classes[] = 'phui-list-item-has-icon';
240
}
241
242
if ($this->selected) {
243
$classes[] = 'phui-list-item-selected';
244
}
245
246
if ($this->disabled) {
247
$classes[] = 'phui-list-item-disabled';
248
}
249
250
if ($this->statusColor) {
251
$classes[] = $this->statusColor;
252
}
253
254
if ($this->actionIcon) {
255
$classes[] = 'phui-list-item-has-action-icon';
256
}
257
258
$sigil = null;
259
$metadata = null;
260
if ($this->dropdownMenu) {
261
$classes[] = 'dropdown';
262
if (!$this->actionIcon) {
263
$classes[] = 'dropdown-with-caret';
264
Javelin::initBehavior('phui-dropdown-menu');
265
$sigil = 'phui-dropdown-menu';
266
$metadata = $this->dropdownMenu->getDropdownMenuMetadata();
267
}
268
}
269
270
return array(
271
'class' => $classes,
272
'sigil' => $sigil,
273
'meta' => $metadata,
274
);
275
}
276
277
public function setDisabled($disabled) {
278
$this->disabled = $disabled;
279
return $this;
280
}
281
282
public function getDisabled() {
283
return $this->disabled;
284
}
285
286
protected function getTagContent() {
287
$name = null;
288
$icon = null;
289
$meta = null;
290
$sigil = array();
291
292
if ($this->name) {
293
if ($this->getRenderNameAsTooltip()) {
294
Javelin::initBehavior('phabricator-tooltips');
295
$sigil[] = 'has-tooltip';
296
$meta = array(
297
'tip' => $this->name,
298
'align' => 'E',
299
);
300
} else {
301
if ($this->tooltip) {
302
Javelin::initBehavior('phabricator-tooltips');
303
$sigil[] = 'has-tooltip';
304
$meta = array(
305
'tip' => $this->tooltip,
306
'align' => 'E',
307
'size' => 300,
308
);
309
}
310
311
$external = null;
312
if ($this->isExternal) {
313
$external = " \xE2\x86\x97";
314
}
315
316
// If this element has an aural representation, make any name visual
317
// only. This is primarily dealing with the links in the main menu like
318
// "Profile" and "Logout". If we don't hide the name, the mobile
319
// version of these elements will have two redundant names.
320
321
$classes = array();
322
$classes[] = 'phui-list-item-name';
323
if ($this->aural !== null) {
324
$classes[] = 'visual-only';
325
}
326
327
$name = phutil_tag(
328
'span',
329
array(
330
'class' => implode(' ', $classes),
331
),
332
array(
333
$this->name,
334
$external,
335
));
336
}
337
}
338
339
$aural = null;
340
if ($this->aural !== null) {
341
$aural = javelin_tag(
342
'span',
343
array(
344
'aural' => true,
345
),
346
$this->aural);
347
}
348
349
if ($this->icon) {
350
$icon_name = $this->icon;
351
if ($this->getDisabled()) {
352
$icon_name .= ' grey';
353
}
354
355
$icon = id(new PHUIIconView())
356
->addClass('phui-list-item-icon')
357
->setIcon($icon_name);
358
}
359
360
if ($this->profileImage) {
361
$icon = id(new PHUIIconView())
362
->setHeadSize(PHUIIconView::HEAD_SMALL)
363
->addClass('phui-list-item-icon')
364
->setImage($this->profileImage);
365
}
366
367
$classes = array();
368
if ($this->href) {
369
$classes[] = 'phui-list-item-href';
370
}
371
372
if ($this->indented) {
373
$classes[] = 'phui-list-item-indented';
374
}
375
376
$action_link = $this->newActionIconView();
377
378
$count = null;
379
if ($this->count) {
380
$count = phutil_tag(
381
'span',
382
array(
383
'class' => 'phui-list-item-count',
384
),
385
$this->count);
386
}
387
388
$caret = null;
389
if ($this->dropdownMenu && !$this->actionIcon) {
390
$caret = id(new PHUIIconView())
391
->setIcon('fa-caret-down');
392
}
393
394
$icons = $this->getIcons();
395
396
$key_command = null;
397
if ($this->keyCommand) {
398
$key_command = phutil_tag(
399
'span',
400
array(
401
'class' => 'keyboard-shortcut-key',
402
),
403
$this->keyCommand);
404
$sigil[] = 'has-key-command';
405
$meta['keyCommand'] = $this->keyCommand;
406
}
407
408
$list_item = javelin_tag(
409
$this->href ? 'a' : 'div',
410
array(
411
'href' => $this->href,
412
'class' => implode(' ', $classes),
413
'meta' => $meta,
414
'sigil' => implode(' ', $sigil),
415
'target' => $this->getOpenInNewWindow() ? '_blank' : null,
416
'rel' => $this->rel,
417
),
418
array(
419
$aural,
420
$icon,
421
$icons,
422
$this->renderChildren(),
423
$name,
424
$count,
425
$key_command,
426
$caret,
427
));
428
429
return array($list_item, $action_link);
430
}
431
432
private function newActionIconView() {
433
$action_icon = $this->actionIcon;
434
$action_href = $this->actionIconHref;
435
436
if ($action_icon === null) {
437
return null;
438
}
439
440
$icon_view = id(new PHUIIconView())
441
->setIcon($action_icon)
442
->addClass('phui-list-item-action-icon');
443
444
if ($this->dropdownMenu) {
445
Javelin::initBehavior('phui-dropdown-menu');
446
$sigil = 'phui-dropdown-menu';
447
$metadata = $this->dropdownMenu->getDropdownMenuMetadata();
448
} else {
449
$sigil = null;
450
$metadata = null;
451
}
452
453
return javelin_tag(
454
'a',
455
array(
456
'href' => $action_href,
457
'class' => 'phui-list-item-action-href',
458
'sigil' => $sigil,
459
'meta' => $metadata,
460
),
461
$icon_view);
462
}
463
464
}
465
466