Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUIObjectItemView.php
12249 views
1
<?php
2
3
final class PHUIObjectItemView extends AphrontTagView {
4
5
private $objectName;
6
private $header;
7
private $subhead;
8
private $href;
9
private $attributes = array();
10
private $icons = array();
11
private $barColor;
12
private $object;
13
private $effect;
14
private $statusIcon;
15
private $handleIcons = array();
16
private $bylines = array();
17
private $grippable;
18
private $actions = array();
19
private $headIcons = array();
20
private $disabled;
21
private $imageURI;
22
private $imageHref;
23
private $imageIcon;
24
private $titleText;
25
private $badge;
26
private $countdownNum;
27
private $countdownNoun;
28
private $sideColumn;
29
private $coverImage;
30
private $description;
31
private $clickable;
32
private $mapViews = array();
33
private $menu;
34
35
private $selectableName;
36
private $selectableValue;
37
private $isSelected;
38
private $isForbidden;
39
40
public function setDisabled($disabled) {
41
$this->disabled = $disabled;
42
return $this;
43
}
44
45
public function getDisabled() {
46
return $this->disabled;
47
}
48
49
public function addHeadIcon($icon) {
50
$this->headIcons[] = $icon;
51
return $this;
52
}
53
54
public function setObjectName($name) {
55
$this->objectName = $name;
56
return $this;
57
}
58
59
public function setGrippable($grippable) {
60
$this->grippable = $grippable;
61
return $this;
62
}
63
64
public function getGrippable() {
65
return $this->grippable;
66
}
67
68
public function setEffect($effect) {
69
$this->effect = $effect;
70
return $this;
71
}
72
73
public function getEffect() {
74
return $this->effect;
75
}
76
77
public function setObject($object) {
78
$this->object = $object;
79
return $this;
80
}
81
82
public function getObject() {
83
return $this->object;
84
}
85
86
public function setHref($href) {
87
$this->href = $href;
88
return $this;
89
}
90
91
public function getHref() {
92
return $this->href;
93
}
94
95
public function setHeader($header) {
96
$this->header = $header;
97
return $this;
98
}
99
100
public function getHeader() {
101
return $this->header;
102
}
103
104
public function setSubHead($subhead) {
105
$this->subhead = $subhead;
106
return $this;
107
}
108
109
public function setBadge(PHUIBadgeMiniView $badge) {
110
$this->badge = $badge;
111
return $this;
112
}
113
114
public function setCountdown($num, $noun) {
115
$this->countdownNum = $num;
116
$this->countdownNoun = $noun;
117
return $this;
118
}
119
120
public function setTitleText($title_text) {
121
$this->titleText = $title_text;
122
return $this;
123
}
124
125
public function getTitleText() {
126
return $this->titleText;
127
}
128
129
public function addByline($byline) {
130
$this->bylines[] = $byline;
131
return $this;
132
}
133
134
public function setImageURI($image_uri) {
135
$this->imageURI = $image_uri;
136
return $this;
137
}
138
139
public function setImageHref($image_href) {
140
$this->imageHref = $image_href;
141
return $this;
142
}
143
144
public function getImageURI() {
145
return $this->imageURI;
146
}
147
148
public function setImageIcon($image_icon) {
149
if (!$image_icon instanceof PHUIIconView) {
150
$image_icon = id(new PHUIIconView())
151
->setIcon($image_icon);
152
}
153
$this->imageIcon = $image_icon;
154
return $this;
155
}
156
157
public function getImageIcon() {
158
return $this->imageIcon;
159
}
160
161
public function setCoverImage($image) {
162
$this->coverImage = $image;
163
return $this;
164
}
165
166
public function setDescription($description) {
167
$this->description = $description;
168
return $this;
169
}
170
171
public function setSelectable(
172
$name,
173
$value,
174
$is_selected,
175
$is_forbidden = false) {
176
177
$this->selectableName = $name;
178
$this->selectableValue = $value;
179
$this->isSelected = $is_selected;
180
$this->isForbidden = $is_forbidden;
181
182
return $this;
183
}
184
185
public function setClickable($clickable) {
186
$this->clickable = $clickable;
187
return $this;
188
}
189
190
public function getClickable() {
191
return $this->clickable;
192
}
193
194
public function setEpoch($epoch) {
195
$date = phabricator_dual_datetime($epoch, $this->getUser());
196
$this->addIcon('none', $date);
197
return $this;
198
}
199
200
public function addAction(PHUIListItemView $action) {
201
if (count($this->actions) >= 3) {
202
throw new Exception(pht('Limit 3 actions per item.'));
203
}
204
$this->actions[] = $action;
205
return $this;
206
}
207
208
public function addIcon($icon, $label = null, $attributes = array()) {
209
$this->icons[] = array(
210
'icon' => $icon,
211
'label' => $label,
212
'attributes' => $attributes,
213
);
214
return $this;
215
}
216
217
public function newMenuItem() {
218
if (!$this->menu) {
219
$this->menu = new FuelMenuView();
220
}
221
222
return $this->menu->newItem();
223
}
224
225
public function newMapView() {
226
$list = id(new FuelMapView())
227
->addClass('fuel-map-property-list');
228
$this->mapViews[] = $list;
229
return $list;
230
}
231
232
/**
233
* This method has been deprecated, use @{method:setImageIcon} instead.
234
*
235
* @deprecated
236
*/
237
public function setIcon($icon) {
238
phlog(
239
pht('Deprecated call to setIcon(), use setImageIcon() instead.'));
240
241
return $this->setImageIcon($icon);
242
}
243
244
public function setStatusIcon($icon, $label = null) {
245
$this->statusIcon = array(
246
'icon' => $icon,
247
'label' => $label,
248
);
249
return $this;
250
}
251
252
public function addHandleIcon(
253
PhabricatorObjectHandle $handle,
254
$label = null) {
255
$this->handleIcons[] = array(
256
'icon' => $handle,
257
'label' => $label,
258
);
259
return $this;
260
}
261
262
public function setBarColor($bar_color) {
263
$this->barColor = $bar_color;
264
return $this;
265
}
266
267
public function getBarColor() {
268
return $this->barColor;
269
}
270
271
public function addAttribute($attribute) {
272
if (!empty($attribute)) {
273
$this->attributes[] = $attribute;
274
}
275
return $this;
276
}
277
278
public function setSideColumn($column) {
279
$this->sideColumn = $column;
280
return $this;
281
}
282
283
protected function getTagName() {
284
return 'li';
285
}
286
287
protected function getTagAttributes() {
288
$sigils = array();
289
290
$item_classes = array();
291
$item_classes[] = 'phui-oi';
292
293
if ($this->icons) {
294
$item_classes[] = 'phui-oi-with-icons';
295
}
296
297
if ($this->attributes) {
298
$item_classes[] = 'phui-oi-with-attrs';
299
}
300
301
if ($this->handleIcons) {
302
$item_classes[] = 'phui-oi-with-handle-icons';
303
}
304
305
if ($this->barColor) {
306
$item_classes[] = 'phui-oi-bar-color-'.$this->barColor;
307
} else {
308
$item_classes[] = 'phui-oi-no-bar';
309
}
310
311
if ($this->actions) {
312
$n = count($this->actions);
313
$item_classes[] = 'phui-oi-with-actions';
314
$item_classes[] = 'phui-oi-with-'.$n.'-actions';
315
}
316
317
if ($this->disabled) {
318
$item_classes[] = 'phui-oi-disabled';
319
} else {
320
$item_classes[] = 'phui-oi-enabled';
321
}
322
323
switch ($this->effect) {
324
case 'highlighted':
325
$item_classes[] = 'phui-oi-highlighted';
326
break;
327
case 'selected':
328
$item_classes[] = 'phui-oi-selected';
329
break;
330
case 'visited':
331
$item_classes[] = 'phui-oi-visited';
332
break;
333
case null:
334
break;
335
default:
336
throw new Exception(pht('Invalid effect!'));
337
}
338
339
if ($this->isForbidden) {
340
$item_classes[] = 'phui-oi-forbidden';
341
} else if ($this->isSelected) {
342
$item_classes[] = 'phui-oi-selected';
343
}
344
345
if ($this->selectableName !== null && !$this->isForbidden) {
346
$item_classes[] = 'phui-oi-selectable';
347
$sigils[] = 'phui-oi-selectable';
348
349
Javelin::initBehavior('phui-selectable-list');
350
}
351
352
$is_grippable = $this->getGrippable();
353
if ($is_grippable !== null) {
354
$item_classes[] = 'phui-oi-has-grip';
355
if ($is_grippable) {
356
$item_classes[] = 'phui-oi-grippable';
357
} else {
358
$item_classes[] = 'phui-oi-ungrippable';
359
}
360
}
361
362
if ($this->getImageURI()) {
363
$item_classes[] = 'phui-oi-with-image';
364
}
365
366
if ($this->getImageIcon()) {
367
$item_classes[] = 'phui-oi-with-image-icon';
368
}
369
370
if ($this->getClickable()) {
371
Javelin::initBehavior('linked-container');
372
373
$item_classes[] = 'phui-oi-linked-container';
374
$sigils[] = 'linked-container';
375
}
376
377
return array(
378
'class' => $item_classes,
379
'sigil' => $sigils,
380
);
381
}
382
383
protected function getTagContent() {
384
$viewer = $this->getUser();
385
386
$content_classes = array();
387
$content_classes[] = 'phui-oi-content';
388
389
$header_name = array();
390
391
if ($viewer) {
392
$header_name[] = id(new PHUISpacesNamespaceContextView())
393
->setUser($viewer)
394
->setObject($this->object);
395
}
396
397
if ($this->objectName) {
398
$header_name[] = array(
399
javelin_tag(
400
'span',
401
array(
402
'class' => 'phui-oi-objname',
403
'sigil' => 'ungrabbable',
404
),
405
$this->objectName),
406
' ',
407
);
408
}
409
410
$title_text = null;
411
if ($this->titleText) {
412
$title_text = $this->titleText;
413
} else if ($this->href) {
414
$title_text = $this->header;
415
}
416
417
$header_link = phutil_tag(
418
$this->href ? 'a' : 'div',
419
array(
420
'href' => $this->href,
421
'class' => 'phui-oi-link',
422
'title' => $title_text,
423
),
424
$this->header);
425
426
$description_tag = null;
427
if ($this->description) {
428
$decription_id = celerity_generate_unique_node_id();
429
$description_tag = id(new PHUITagView())
430
->setIcon('fa-ellipsis-h')
431
->addClass('phui-oi-description-tag')
432
->setType(PHUITagView::TYPE_SHADE)
433
->setColor(PHUITagView::COLOR_GREY)
434
->addSigil('jx-toggle-class')
435
->setSlimShady(true)
436
->setMetaData(array(
437
'map' => array(
438
$decription_id => 'phui-oi-description-reveal',
439
),
440
));
441
}
442
443
$header = phutil_tag(
444
'div',
445
array(
446
'class' => 'phui-oi-name',
447
),
448
array(
449
$this->headIcons,
450
$header_name,
451
$header_link,
452
$description_tag,
453
));
454
455
$icons = array();
456
if ($this->icons) {
457
$icon_list = array();
458
foreach ($this->icons as $spec) {
459
$icon = $spec['icon'];
460
$icon = id(new PHUIIconView())
461
->setIcon($icon)
462
->addClass('phui-oi-icon-image');
463
464
if (isset($spec['attributes']['tip'])) {
465
$sigil = 'has-tooltip';
466
$meta = array(
467
'tip' => $spec['attributes']['tip'],
468
'align' => 'W',
469
);
470
$icon->addSigil($sigil);
471
$icon->setMetadata($meta);
472
}
473
474
$label = phutil_tag(
475
'span',
476
array(
477
'class' => 'phui-oi-icon-label',
478
),
479
$spec['label']);
480
481
$classes = array();
482
$classes[] = 'phui-oi-icon';
483
if (isset($spec['attributes']['class'])) {
484
$classes[] = $spec['attributes']['class'];
485
}
486
487
$icon_list[] = javelin_tag(
488
'li',
489
array(
490
'class' => implode(' ', $classes),
491
),
492
array(
493
$icon,
494
$label,
495
));
496
}
497
498
$icons[] = phutil_tag(
499
'ul',
500
array(
501
'class' => 'phui-oi-icons',
502
),
503
$icon_list);
504
}
505
506
$handle_bar = null;
507
if ($this->handleIcons) {
508
$handle_bar = array();
509
foreach ($this->handleIcons as $handleicon) {
510
$handle_bar[] =
511
$this->renderHandleIcon($handleicon['icon'], $handleicon['label']);
512
}
513
$handle_bar = phutil_tag(
514
'li',
515
array(
516
'class' => 'phui-oi-handle-icons',
517
),
518
$handle_bar);
519
}
520
521
$bylines = array();
522
if ($this->bylines) {
523
foreach ($this->bylines as $byline) {
524
$bylines[] = phutil_tag(
525
'div',
526
array(
527
'class' => 'phui-oi-byline',
528
),
529
$byline);
530
}
531
$bylines = phutil_tag(
532
'div',
533
array(
534
'class' => 'phui-oi-bylines',
535
),
536
$bylines);
537
}
538
539
$subhead = null;
540
if ($this->subhead) {
541
$subhead = phutil_tag(
542
'div',
543
array(
544
'class' => 'phui-oi-subhead',
545
),
546
$this->subhead);
547
}
548
549
if ($this->description) {
550
$subhead = phutil_tag(
551
'div',
552
array(
553
'class' => 'phui-oi-subhead phui-oi-description',
554
'id' => $decription_id,
555
),
556
$this->description);
557
}
558
559
if ($icons) {
560
$icons = phutil_tag(
561
'div',
562
array(
563
'class' => 'phui-object-icon-pane',
564
),
565
$icons);
566
}
567
568
$attrs = null;
569
if ($this->attributes || $handle_bar) {
570
$attrs = array();
571
$spacer = phutil_tag(
572
'span',
573
array(
574
'class' => 'phui-oi-attribute-spacer',
575
),
576
"\xC2\xB7");
577
$first = true;
578
foreach ($this->attributes as $attribute) {
579
$attrs[] = phutil_tag(
580
'li',
581
array(
582
'class' => 'phui-oi-attribute',
583
),
584
array(
585
($first ? null : $spacer),
586
$attribute,
587
));
588
$first = false;
589
}
590
591
$attrs = phutil_tag(
592
'ul',
593
array(
594
'class' => 'phui-oi-attributes',
595
),
596
array(
597
$handle_bar,
598
$attrs,
599
));
600
}
601
602
$status = null;
603
if ($this->statusIcon) {
604
$icon = $this->statusIcon;
605
$status = $this->renderStatusIcon($icon['icon'], $icon['label']);
606
}
607
608
$grippable = null;
609
if ($this->getGrippable() !== null) {
610
$grippable = phutil_tag(
611
'div',
612
array(
613
'class' => 'phui-oi-grip',
614
),
615
'');
616
}
617
618
$map_views = null;
619
if ($this->mapViews) {
620
$grid = id(new FuelGridView())
621
->addClass('fuel-grid-property-list');
622
623
$row = $grid->newRow();
624
foreach ($this->mapViews as $map_view) {
625
$row->newCell()
626
->setContent($map_view);
627
}
628
629
$map_views = $grid;
630
}
631
632
$content = phutil_tag(
633
'div',
634
array(
635
'class' => implode(' ', $content_classes),
636
),
637
array(
638
$subhead,
639
$attrs,
640
$map_views,
641
$this->renderChildren(),
642
));
643
644
$image = null;
645
if ($this->getImageURI()) {
646
$image = phutil_tag(
647
'div',
648
array(
649
'class' => 'phui-oi-image',
650
'style' => 'background-image: url('.$this->getImageURI().')',
651
),
652
'');
653
} else if ($this->getImageIcon()) {
654
$image = phutil_tag(
655
'div',
656
array(
657
'class' => 'phui-oi-image-icon',
658
),
659
$this->getImageIcon());
660
}
661
662
$image_href = $this->href;
663
if ($image_href === null || !strlen($image_href)) {
664
$image_href = $this->imageHref;
665
}
666
667
if ($image && $image_href !== null && strlen($image_href)) {
668
$image = phutil_tag(
669
'a',
670
array(
671
'href' => $image_href,
672
),
673
$image);
674
}
675
676
/* Build a fake table */
677
$column0 = null;
678
if ($status) {
679
$column0 = phutil_tag(
680
'div',
681
array(
682
'class' => 'phui-oi-col0',
683
),
684
$status);
685
}
686
687
if ($this->badge) {
688
$column0 = phutil_tag(
689
'div',
690
array(
691
'class' => 'phui-oi-col0 phui-oi-badge',
692
),
693
$this->badge);
694
}
695
696
if ($this->countdownNum) {
697
$countdown = phutil_tag(
698
'div',
699
array(
700
'class' => 'phui-oi-countdown-number',
701
),
702
array(
703
phutil_tag_div('', $this->countdownNum),
704
phutil_tag_div('', $this->countdownNoun),
705
));
706
$column0 = phutil_tag(
707
'div',
708
array(
709
'class' => 'phui-oi-col0 phui-oi-countdown',
710
),
711
$countdown);
712
}
713
714
if ($this->selectableName !== null) {
715
if (!$this->isForbidden) {
716
$checkbox = phutil_tag(
717
'input',
718
array(
719
'type' => 'checkbox',
720
'name' => $this->selectableName,
721
'value' => $this->selectableValue,
722
'checked' => ($this->isSelected ? 'checked' : null),
723
));
724
} else {
725
$checkbox = null;
726
}
727
728
$column0 = phutil_tag(
729
'div',
730
array(
731
'class' => 'phui-oi-col0 phui-oi-checkbox',
732
),
733
$checkbox);
734
}
735
736
$column1 = phutil_tag(
737
'div',
738
array(
739
'class' => 'phui-oi-col1',
740
),
741
array(
742
$header,
743
$content,
744
));
745
746
$column2 = null;
747
if ($icons || $bylines) {
748
$column2 = phutil_tag(
749
'div',
750
array(
751
'class' => 'phui-oi-col2',
752
),
753
array(
754
$icons,
755
$bylines,
756
));
757
}
758
759
/* Fixed width, right column container. */
760
$column3 = null;
761
if ($this->sideColumn) {
762
$column3 = phutil_tag(
763
'div',
764
array(
765
'class' => 'phui-oi-col2 phui-oi-side-column',
766
),
767
array(
768
$this->sideColumn,
769
));
770
}
771
772
$table = phutil_tag(
773
'div',
774
array(
775
'class' => 'phui-oi-table',
776
),
777
phutil_tag_div(
778
'phui-oi-table-row',
779
array(
780
$column0,
781
$column1,
782
$column2,
783
$column3,
784
)));
785
786
$box = phutil_tag(
787
'div',
788
array(
789
'class' => 'phui-oi-content-box',
790
),
791
array(
792
$grippable,
793
$table,
794
));
795
796
$actions = array();
797
if ($this->actions) {
798
Javelin::initBehavior('phabricator-tooltips');
799
800
foreach (array_reverse($this->actions) as $action) {
801
$action->setRenderNameAsTooltip(true);
802
$actions[] = $action;
803
}
804
$actions = phutil_tag(
805
'ul',
806
array(
807
'class' => 'phui-oi-actions',
808
),
809
$actions);
810
}
811
812
$frame_content = phutil_tag(
813
'div',
814
array(
815
'class' => 'phui-oi-frame-content',
816
),
817
array(
818
$actions,
819
$image,
820
$box,
821
));
822
823
if ($this->menu) {
824
$grid_view = id(new FuelGridView())
825
->addClass('fuel-grid-tablet');
826
$grid_row = $grid_view->newRow();
827
828
$grid_row->newCell()
829
->setContent($frame_content);
830
831
$menu = $this->menu;
832
833
$grid_row->newCell()
834
->addClass('phui-oi-menu')
835
->setContent($menu);
836
837
$frame_content = $grid_view;
838
}
839
840
$frame_cover = null;
841
if ($this->coverImage) {
842
$cover_image = phutil_tag(
843
'img',
844
array(
845
'src' => $this->coverImage,
846
'class' => 'phui-oi-cover-image',
847
));
848
849
$frame_cover = phutil_tag(
850
'div',
851
array(
852
'class' => 'phui-oi-frame-cover',
853
),
854
$cover_image);
855
}
856
857
$frame = phutil_tag(
858
'div',
859
array(
860
'class' => 'phui-oi-frame',
861
),
862
array(
863
$frame_cover,
864
$frame_content,
865
));
866
867
return $frame;
868
}
869
870
private function renderStatusIcon($icon, $label) {
871
Javelin::initBehavior('phabricator-tooltips');
872
873
$icon = id(new PHUIIconView())
874
->setIcon($icon);
875
876
$options = array(
877
'class' => 'phui-oi-status-icon',
878
);
879
880
if ($label !== null && strlen($label)) {
881
$options['sigil'] = 'has-tooltip';
882
$options['meta'] = array('tip' => $label, 'size' => 300);
883
}
884
885
return javelin_tag('div', $options, $icon);
886
}
887
888
889
private function renderHandleIcon(PhabricatorObjectHandle $handle, $label) {
890
Javelin::initBehavior('phabricator-tooltips');
891
892
$options = array(
893
'class' => 'phui-oi-handle-icon',
894
'style' => 'background-image: url('.$handle->getImageURI().')',
895
);
896
897
if (strlen($label)) {
898
$options['sigil'] = 'has-tooltip';
899
$options['meta'] = array('tip' => $label, 'align' => 'E');
900
}
901
902
return javelin_tag('span', $options, '');
903
}
904
905
}
906
907