3 final class PHUIPropertyListView
extends AphrontView
{
5 private $parts = array();
6 private $hasKeyboardShortcuts;
8 private $invokedWillRenderEvent;
9 private $actionList = null;
10 private $classes = array();
13 const ICON_SUMMARY
= 'fa-align-left';
14 const ICON_TESTPLAN
= 'fa-file-text-o';
16 protected function canAppendChild() {
20 public function setObject($object) {
21 $this->object = $object;
25 public function setActionList(PhabricatorActionListView
$list) {
26 $this->actionList
= $list;
30 public function getActionList() {
31 return $this->actionList
;
34 public function setStacked($stacked) {
35 $this->stacked
= $stacked;
39 public function addClass($class) {
40 $this->classes
[] = $class;
44 public function setHasKeyboardShortcuts($has_keyboard_shortcuts) {
45 $this->hasKeyboardShortcuts
= $has_keyboard_shortcuts;
49 public function addProperty($key, $value) {
50 $current = array_pop($this->parts
);
52 if (!$current ||
$current['type'] != 'property') {
54 $this->parts
[] = $current;
62 $current['list'][] = array(
67 $this->parts
[] = $current;
71 public function addSectionHeader($name, $icon = null) {
72 $this->parts
[] = array(
80 public function addTextContent($content) {
81 $this->parts
[] = array(
83 'content' => $content,
88 public function addRawContent($content) {
89 $this->parts
[] = array(
91 'content' => $content,
96 public function addImageContent($content) {
97 $this->parts
[] = array(
99 'content' => $content,
104 public function invokeWillRenderEvent() {
105 if ($this->object && $this->getUser() && !$this->invokedWillRenderEvent
) {
106 $event = new PhabricatorEvent(
107 PhabricatorEventType
::TYPE_UI_WILLRENDERPROPERTIES
,
109 'object' => $this->object,
112 $event->setUser($this->getUser());
113 PhutilEventEngine
::dispatchEvent($event);
115 $this->invokedWillRenderEvent
= true;
118 public function hasAnyProperties() {
119 $this->invokeWillRenderEvent();
128 public function render() {
129 $this->invokeWillRenderEvent();
131 require_celerity_resource('phui-property-list-view-css');
135 $parts = $this->parts
;
137 // If we have an action list, make sure we render a property part, even
138 // if there are no properties. Otherwise, the action list won't render.
139 if ($this->actionList
) {
140 $this->classes
[] = 'phui-property-list-has-actions';
141 $have_property_part = false;
142 foreach ($this->parts
as $part) {
143 if ($part['type'] == 'property') {
144 $have_property_part = true;
148 if (!$have_property_part) {
150 'type' => 'property',
156 foreach ($parts as $part) {
157 $type = $part['type'];
160 $items[] = $this->renderPropertyPart($part);
163 $items[] = $this->renderSectionPart($part);
167 $items[] = $this->renderTextPart($part);
170 $items[] = $this->renderRawPart($part);
173 throw new Exception(pht("Unknown part type '%s'!", $type));
176 $this->classes
[] = 'phui-property-list-section';
177 $classes = implode(' ', $this->classes
);
189 private function renderPropertyPart(array $part) {
191 foreach ($part['list'] as $spec) {
193 $value = $spec['value'];
195 // NOTE: We append a space to each value to improve the behavior when the
196 // user double-clicks a property value (like a URI) to select it. Without
197 // the space, the label is also selected.
199 $items[] = phutil_tag(
202 'class' => 'phui-property-list-key',
206 $items[] = phutil_tag(
209 'class' => 'phui-property-list-value',
215 if ($this->stacked
) {
216 $stacked = 'phui-property-list-stacked';
222 'class' => 'phui-property-list-properties',
227 if ($this->hasKeyboardShortcuts
) {
228 $shortcuts = new AphrontKeyboardShortcutsAvailableView();
234 'class' => 'phui-property-list-properties-wrap '.$stacked,
236 array($shortcuts, $list));
239 if ($this->actionList
) {
240 $action_list = phutil_tag(
243 'class' => 'phui-property-list-actions',
246 $this->actionList
= null;
252 'class' => 'phui-property-list-container grouped',
254 array($action_list, $list));
257 private function renderSectionPart(array $part) {
258 $name = $part['name'];
260 $icon = id(new PHUIIconView())
261 ->setIcon($part['icon'].' bluegrey');
265 'class' => 'phui-property-list-section-header-icon',
267 array($icon, $name));
273 'class' => 'phui-property-list-section-header',
278 private function renderTextPart(array $part) {
280 $classes[] = 'phui-property-list-text-content';
281 if ($part['type'] == 'image') {
282 $classes[] = 'phui-property-list-image-content';
287 'class' => implode(' ', $classes),
292 private function renderRawPart(array $part) {
294 $classes[] = 'phui-property-list-raw-content';
298 'class' => implode(' ', $classes),