2012-08-15 19:45:06 +02:00
|
|
|
<?php
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
final class PHUIPropertyListView extends AphrontView {
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2012-11-21 03:01:18 +01:00
|
|
|
private $parts = array();
|
2012-12-11 23:59:27 +01:00
|
|
|
private $hasKeyboardShortcuts;
|
2013-02-15 16:47:14 +01:00
|
|
|
private $object;
|
|
|
|
private $invokedWillRenderEvent;
|
2013-10-06 20:12:00 +02:00
|
|
|
private $actionList;
|
2012-11-21 03:01:18 +01:00
|
|
|
|
|
|
|
protected function canAppendChild() {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2013-02-15 16:47:14 +01:00
|
|
|
public function setObject($object) {
|
|
|
|
$this->object = $object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-10-06 20:12:00 +02:00
|
|
|
public function setActionList(PhabricatorActionListView $list) {
|
|
|
|
$this->actionList = $list;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-11 23:59:27 +01:00
|
|
|
public function setHasKeyboardShortcuts($has_keyboard_shortcuts) {
|
|
|
|
$this->hasKeyboardShortcuts = $has_keyboard_shortcuts;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
public function addProperty($key, $value) {
|
2012-11-21 03:01:18 +01:00
|
|
|
$current = array_pop($this->parts);
|
|
|
|
|
|
|
|
if (!$current || $current['type'] != 'property') {
|
|
|
|
if ($current) {
|
|
|
|
$this->parts[] = $current;
|
|
|
|
}
|
|
|
|
$current = array(
|
|
|
|
'type' => 'property',
|
|
|
|
'list' => array(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$current['list'][] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'value' => $value,
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->parts[] = $current;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addSectionHeader($name) {
|
|
|
|
$this->parts[] = array(
|
|
|
|
'type' => 'section',
|
|
|
|
'name' => $name,
|
|
|
|
);
|
2012-08-15 19:45:06 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-15 23:50:53 +02:00
|
|
|
public function addTextContent($content) {
|
2012-11-21 03:01:18 +01:00
|
|
|
$this->parts[] = array(
|
|
|
|
'type' => 'text',
|
|
|
|
'content' => $content,
|
|
|
|
);
|
|
|
|
return $this;
|
2012-10-15 23:50:53 +02:00
|
|
|
}
|
|
|
|
|
2013-02-27 01:37:45 +01:00
|
|
|
public function addImageContent($content) {
|
|
|
|
$this->parts[] = array(
|
|
|
|
'type' => 'image',
|
|
|
|
'content' => $content,
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-02-15 16:47:14 +01:00
|
|
|
public function invokeWillRenderEvent() {
|
|
|
|
if ($this->object && $this->getUser() && !$this->invokedWillRenderEvent) {
|
|
|
|
$event = new PhabricatorEvent(
|
|
|
|
PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES,
|
|
|
|
array(
|
|
|
|
'object' => $this->object,
|
|
|
|
'view' => $this,
|
|
|
|
));
|
|
|
|
$event->setUser($this->getUser());
|
|
|
|
PhutilEventEngine::dispatchEvent($event);
|
|
|
|
}
|
|
|
|
$this->invokedWillRenderEvent = true;
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
public function render() {
|
2013-02-15 16:47:14 +01:00
|
|
|
$this->invokeWillRenderEvent();
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
require_celerity_resource('phui-property-list-view-css');
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
$items = array();
|
2012-11-21 03:01:18 +01:00
|
|
|
foreach ($this->parts as $part) {
|
|
|
|
$type = $part['type'];
|
|
|
|
switch ($type) {
|
|
|
|
case 'property':
|
|
|
|
$items[] = $this->renderPropertyPart($part);
|
|
|
|
break;
|
|
|
|
case 'section':
|
|
|
|
$items[] = $this->renderSectionPart($part);
|
|
|
|
break;
|
|
|
|
case 'text':
|
2013-02-27 01:37:45 +01:00
|
|
|
case 'image':
|
2012-11-21 03:01:18 +01:00
|
|
|
$items[] = $this->renderTextPart($part);
|
|
|
|
break;
|
|
|
|
default:
|
2013-03-02 00:37:32 +01:00
|
|
|
throw new Exception(pht("Unknown part type '%s'!", $type));
|
2012-11-21 03:01:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 15:04:54 +01:00
|
|
|
return phutil_tag(
|
2012-11-21 03:01:18 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-section',
|
2012-11-21 03:01:18 +01:00
|
|
|
),
|
2013-10-11 16:53:56 +02:00
|
|
|
array(
|
|
|
|
$items,
|
|
|
|
));
|
2012-11-21 03:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderPropertyPart(array $part) {
|
|
|
|
$items = array();
|
|
|
|
foreach ($part['list'] as $spec) {
|
|
|
|
$key = $spec['key'];
|
|
|
|
$value = $spec['value'];
|
|
|
|
|
2013-05-24 19:47:54 +02:00
|
|
|
// NOTE: We append a space to each value to improve the behavior when the
|
|
|
|
// user double-clicks a property value (like a URI) to select it. Without
|
|
|
|
// the space, the label is also selected.
|
|
|
|
|
2013-01-18 03:43:35 +01:00
|
|
|
$items[] = phutil_tag(
|
2012-08-15 19:45:06 +02:00
|
|
|
'dt',
|
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-key',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-05-24 19:47:54 +02:00
|
|
|
array($key, ' '));
|
2013-01-29 20:01:47 +01:00
|
|
|
|
|
|
|
$items[] = phutil_tag(
|
2012-08-15 19:45:06 +02:00
|
|
|
'dd',
|
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-value',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-05-24 19:47:54 +02:00
|
|
|
array($value, ' '));
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 20:01:47 +01:00
|
|
|
$list = phutil_tag(
|
2012-08-15 19:45:06 +02:00
|
|
|
'dl',
|
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-properties',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-03-10 04:23:50 +01:00
|
|
|
$items);
|
2012-12-11 23:59:27 +01:00
|
|
|
|
|
|
|
$shortcuts = null;
|
|
|
|
if ($this->hasKeyboardShortcuts) {
|
2013-03-09 22:52:21 +01:00
|
|
|
$shortcuts = new AphrontKeyboardShortcutsAvailableView();
|
2012-12-11 23:59:27 +01:00
|
|
|
}
|
|
|
|
|
2013-10-06 20:12:00 +02:00
|
|
|
$list = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-properties-wrap',
|
2013-10-06 20:12:00 +02:00
|
|
|
),
|
|
|
|
array($shortcuts, $list));
|
|
|
|
|
|
|
|
$action_list = null;
|
|
|
|
if ($this->actionList) {
|
|
|
|
$action_list = phutil_tag(
|
2012-12-11 23:59:27 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-actions',
|
2012-12-11 23:59:27 +01:00
|
|
|
),
|
2013-10-06 20:12:00 +02:00
|
|
|
$this->actionList);
|
|
|
|
$this->actionList = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return phutil_tag(
|
|
|
|
'div',
|
2013-01-18 09:32:58 +01:00
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-container grouped',
|
2013-10-06 20:12:00 +02:00
|
|
|
),
|
|
|
|
array($action_list, $list));
|
2012-11-21 03:01:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderSectionPart(array $part) {
|
2013-01-18 03:43:35 +01:00
|
|
|
return phutil_tag(
|
2012-11-21 03:01:18 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2013-10-11 16:53:56 +02:00
|
|
|
'class' => 'phui-property-list-section-header',
|
2012-11-21 03:01:18 +01:00
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$part['name']);
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2012-11-21 03:01:18 +01:00
|
|
|
private function renderTextPart(array $part) {
|
2013-02-27 01:37:45 +01:00
|
|
|
$classes = array();
|
2013-10-11 16:53:56 +02:00
|
|
|
$classes[] = 'phui-property-list-text-content';
|
2013-02-27 01:37:45 +01:00
|
|
|
if ($part['type'] == 'image') {
|
2013-10-11 16:53:56 +02:00
|
|
|
$classes[] = 'phui-property-list-image-content';
|
2013-02-27 01:37:45 +01:00
|
|
|
}
|
2013-01-29 20:01:47 +01:00
|
|
|
return phutil_tag(
|
2012-11-21 03:01:18 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2013-02-27 01:37:45 +01:00
|
|
|
'class' => implode($classes, ' '),
|
2012-11-21 03:01:18 +01:00
|
|
|
),
|
|
|
|
$part['content']);
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
}
|