2012-08-15 19:45:06 +02:00
|
|
|
<?php
|
|
|
|
|
2013-03-23 22:38:01 +01:00
|
|
|
final class PhabricatorObjectItemView extends AphrontTagView {
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2013-03-23 22:37:18 +01:00
|
|
|
private $objectName;
|
2012-08-15 19:45:06 +02:00
|
|
|
private $header;
|
2013-05-06 23:01:57 +02:00
|
|
|
private $subhead;
|
2012-08-15 19:45:06 +02:00
|
|
|
private $href;
|
2012-10-01 05:08:22 +02:00
|
|
|
private $attributes = array();
|
2012-12-13 19:59:29 +01:00
|
|
|
private $icons = array();
|
|
|
|
private $barColor;
|
|
|
|
private $object;
|
2012-12-17 01:33:02 +01:00
|
|
|
private $effect;
|
2013-03-10 02:55:01 +01:00
|
|
|
private $footIcons = array();
|
|
|
|
private $handleIcons = array();
|
2013-04-06 20:38:43 +02:00
|
|
|
private $bylines = array();
|
2013-03-23 22:37:18 +01:00
|
|
|
private $grippable;
|
|
|
|
|
|
|
|
public function setObjectName($name) {
|
|
|
|
$this->objectName = $name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setGrippable($grippable) {
|
|
|
|
$this->grippable = $grippable;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGrippable() {
|
|
|
|
return $this->grippable;
|
|
|
|
}
|
2012-12-17 01:33:02 +01:00
|
|
|
|
|
|
|
public function setEffect($effect) {
|
|
|
|
$this->effect = $effect;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEffect() {
|
|
|
|
return $this->effect;
|
|
|
|
}
|
2012-12-13 19:59:29 +01:00
|
|
|
|
|
|
|
public function setObject($object) {
|
|
|
|
$this->object = $object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getObject() {
|
|
|
|
return $this->object;
|
|
|
|
}
|
2012-08-15 19:45:06 +02:00
|
|
|
|
|
|
|
public function setHref($href) {
|
|
|
|
$this->href = $href;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHref() {
|
|
|
|
return $this->href;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHeader($header) {
|
|
|
|
$this->header = $header;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:01:57 +02:00
|
|
|
public function setSubHead($subhead) {
|
|
|
|
$this->subhead = $subhead;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
public function getHeader() {
|
|
|
|
return $this->header;
|
|
|
|
}
|
|
|
|
|
2013-04-06 20:38:43 +02:00
|
|
|
public function addByline($byline) {
|
|
|
|
$this->bylines[] = $byline;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-02-14 22:07:35 +01:00
|
|
|
public function addIcon($icon, $label = null, $href = null) {
|
2012-12-13 19:59:29 +01:00
|
|
|
$this->icons[] = array(
|
|
|
|
'icon' => $icon,
|
|
|
|
'label' => $label,
|
2013-02-14 22:07:35 +01:00
|
|
|
'href' => $href,
|
2012-08-15 19:45:06 +02:00
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-10 02:55:01 +01:00
|
|
|
public function addFootIcon($icon, $label = null) {
|
|
|
|
$this->footIcons[] = array(
|
|
|
|
'icon' => $icon,
|
|
|
|
'label' => $label,
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addHandleIcon(
|
|
|
|
PhabricatorObjectHandle $handle,
|
|
|
|
$label = null) {
|
|
|
|
$this->handleIcons[] = array(
|
|
|
|
'icon' => $handle,
|
|
|
|
'label' => $label,
|
|
|
|
);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-13 19:59:29 +01:00
|
|
|
public function setBarColor($bar_color) {
|
|
|
|
$this->barColor = $bar_color;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBarColor() {
|
|
|
|
return $this->barColor;
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
public function addAttribute($attribute) {
|
|
|
|
$this->attributes[] = $attribute;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-23 22:38:01 +01:00
|
|
|
protected function getTagName() {
|
|
|
|
return 'li';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getTagAttributes() {
|
2013-03-10 02:55:01 +01:00
|
|
|
$item_classes = array();
|
2013-03-23 22:38:01 +01:00
|
|
|
$item_classes[] = 'phabricator-object-item';
|
|
|
|
|
|
|
|
if ($this->icons) {
|
|
|
|
$item_classes[] = 'phabricator-object-item-with-icons';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->attributes) {
|
|
|
|
$item_classes[] = 'phabricator-object-item-with-attrs';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->handleIcons) {
|
|
|
|
$item_classes[] = 'phabricator-object-item-with-handle-icons';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->barColor) {
|
|
|
|
$item_classes[] = 'phabricator-object-item-bar-color-'.$this->barColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->footIcons) {
|
|
|
|
$item_classes[] = 'phabricator-object-item-with-foot-icons';
|
|
|
|
}
|
|
|
|
|
2013-04-06 20:38:43 +02:00
|
|
|
if ($this->bylines) {
|
|
|
|
$item_classes[] = 'phabricator-object-item-with-bylines';
|
|
|
|
}
|
|
|
|
|
2013-03-23 22:38:01 +01:00
|
|
|
switch ($this->effect) {
|
|
|
|
case 'highlighted':
|
|
|
|
$item_classes[] = 'phabricator-object-item-highlighted';
|
|
|
|
break;
|
|
|
|
case 'selected':
|
|
|
|
$item_classes[] = 'phabricator-object-item-selected';
|
|
|
|
break;
|
|
|
|
case null:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception(pht("Invalid effect!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->getGrippable()) {
|
|
|
|
$item_classes[] = 'phabricator-object-item-grippable';
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'class' => $item_classes,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTagContent() {
|
|
|
|
$content_classes = array();
|
2013-03-10 02:55:01 +01:00
|
|
|
$content_classes[] = 'phabricator-object-item-content';
|
|
|
|
|
2013-03-23 22:37:18 +01:00
|
|
|
$header_name = null;
|
|
|
|
if ($this->objectName) {
|
|
|
|
$header_name = array(
|
|
|
|
phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-objname',
|
|
|
|
),
|
|
|
|
$this->objectName),
|
|
|
|
' ',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$header_link = phutil_tag(
|
2013-03-10 02:55:01 +01:00
|
|
|
$this->href ? 'a' : 'div',
|
2012-08-15 19:45:06 +02:00
|
|
|
array(
|
|
|
|
'href' => $this->href,
|
2013-03-23 22:37:18 +01:00
|
|
|
'class' => 'phabricator-object-item-link',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$this->header);
|
2012-08-15 19:45:06 +02:00
|
|
|
|
2013-03-23 22:38:01 +01:00
|
|
|
$header = javelin_tag(
|
2013-03-23 22:37:18 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-name',
|
2013-03-23 22:38:01 +01:00
|
|
|
'sigil' => 'slippery',
|
2013-03-23 22:37:18 +01:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
$header_name,
|
|
|
|
$header_link,
|
|
|
|
));
|
|
|
|
|
|
|
|
$icons = array();
|
2012-12-13 19:59:29 +01:00
|
|
|
if ($this->icons) {
|
|
|
|
$icon_list = array();
|
|
|
|
foreach ($this->icons as $spec) {
|
|
|
|
$icon = $spec['icon'];
|
|
|
|
|
2013-01-18 03:57:09 +01:00
|
|
|
$icon = phutil_tag(
|
2012-12-13 19:59:29 +01:00
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-icon-image '.
|
|
|
|
'sprite-icon action-'.$icon,
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
|
2013-01-18 03:43:35 +01:00
|
|
|
$label = phutil_tag(
|
2012-12-13 19:59:29 +01:00
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-icon-label',
|
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$spec['label']);
|
2012-12-13 19:59:29 +01:00
|
|
|
|
2013-02-14 22:07:35 +01:00
|
|
|
if ($spec['href']) {
|
|
|
|
$icon_href = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array('href' => $spec['href']),
|
2013-02-19 22:33:10 +01:00
|
|
|
array($label, $icon));
|
2013-02-14 22:07:35 +01:00
|
|
|
} else {
|
|
|
|
$icon_href = array($label, $icon);
|
|
|
|
}
|
|
|
|
|
2013-03-23 22:38:01 +01:00
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'phabricator-object-item-icon';
|
|
|
|
if ($spec['icon'] == 'none') {
|
|
|
|
$classes[] = 'phabricator-object-item-icon-none';
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
$icon_list[] = phutil_tag(
|
2012-12-13 19:59:29 +01:00
|
|
|
'li',
|
|
|
|
array(
|
2013-03-23 22:38:01 +01:00
|
|
|
'class' => implode(' ', $classes),
|
2012-12-13 19:59:29 +01:00
|
|
|
),
|
2013-02-14 22:07:35 +01:00
|
|
|
$icon_href);
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
2012-12-13 19:59:29 +01:00
|
|
|
|
2013-03-23 22:37:18 +01:00
|
|
|
$icons[] = phutil_tag(
|
2012-12-13 19:59:29 +01:00
|
|
|
'ul',
|
2012-08-15 19:45:06 +02:00
|
|
|
array(
|
2012-12-13 19:59:29 +01:00
|
|
|
'class' => 'phabricator-object-item-icons',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-01-18 09:32:58 +01:00
|
|
|
$icon_list);
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2013-03-23 22:37:18 +01:00
|
|
|
if ($this->handleIcons) {
|
|
|
|
$handle_bar = array();
|
|
|
|
foreach ($this->handleIcons as $icon) {
|
|
|
|
$handle_bar[] = $this->renderHandleIcon($icon['icon'], $icon['label']);
|
|
|
|
}
|
|
|
|
$icons[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-handle-icons',
|
|
|
|
),
|
|
|
|
$handle_bar);
|
|
|
|
}
|
|
|
|
|
2013-04-06 20:38:43 +02:00
|
|
|
$bylines = array();
|
|
|
|
if ($this->bylines) {
|
|
|
|
foreach ($this->bylines as $byline) {
|
|
|
|
$bylines[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-byline',
|
|
|
|
),
|
|
|
|
$byline);
|
|
|
|
}
|
|
|
|
$bylines = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-bylines',
|
|
|
|
),
|
|
|
|
$bylines);
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:01:57 +02:00
|
|
|
$subhead = null;
|
|
|
|
if ($this->subhead) {
|
|
|
|
$subhead = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-subhead',
|
|
|
|
),
|
|
|
|
$this->subhead);
|
|
|
|
}
|
|
|
|
|
2013-03-23 22:37:18 +01:00
|
|
|
if ($icons) {
|
|
|
|
$icons = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-icon-pane',
|
|
|
|
),
|
|
|
|
$icons);
|
|
|
|
}
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
$attrs = null;
|
|
|
|
if ($this->attributes) {
|
|
|
|
$attrs = array();
|
2013-01-18 03:57:09 +01:00
|
|
|
$spacer = phutil_tag(
|
2012-12-13 19:59:29 +01:00
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-attribute-spacer',
|
|
|
|
),
|
2013-01-18 03:57:09 +01:00
|
|
|
"\xC2\xB7");
|
2012-12-13 19:59:29 +01:00
|
|
|
$first = true;
|
2012-08-15 19:45:06 +02:00
|
|
|
foreach ($this->attributes as $attribute) {
|
2013-01-29 03:09:00 +01:00
|
|
|
$attrs[] = phutil_tag(
|
2012-12-13 19:59:29 +01:00
|
|
|
'li',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-attribute',
|
|
|
|
),
|
2013-01-29 03:09:00 +01:00
|
|
|
array(
|
|
|
|
($first ? null : $spacer),
|
|
|
|
$attribute,
|
|
|
|
));
|
2012-12-13 19:59:29 +01:00
|
|
|
$first = false;
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
2013-05-06 23:01:57 +02:00
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
$attrs = phutil_tag(
|
2012-08-15 19:45:06 +02:00
|
|
|
'ul',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-attributes',
|
|
|
|
),
|
2013-01-18 09:32:58 +01:00
|
|
|
$attrs);
|
2013-03-10 02:55:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-23 22:37:18 +01:00
|
|
|
$foot = null;
|
2013-03-10 02:55:01 +01:00
|
|
|
if ($this->footIcons) {
|
|
|
|
$foot_bar = array();
|
|
|
|
foreach ($this->footIcons as $icon) {
|
|
|
|
$foot_bar[] = $this->renderFootIcon($icon['icon'], $icon['label']);
|
|
|
|
}
|
2013-03-23 22:37:18 +01:00
|
|
|
$foot = phutil_tag(
|
2013-03-10 02:55:01 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-foot-icons',
|
|
|
|
),
|
|
|
|
$foot_bar);
|
2012-12-17 01:33:02 +01:00
|
|
|
}
|
2012-12-13 19:59:29 +01:00
|
|
|
|
2013-03-23 22:37:18 +01:00
|
|
|
$grippable = null;
|
|
|
|
if ($this->getGrippable()) {
|
|
|
|
$grippable = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-grip',
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
|
2013-01-29 03:09:00 +01:00
|
|
|
$content = phutil_tag(
|
2012-12-17 17:26:44 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2013-03-10 02:55:01 +01:00
|
|
|
'class' => implode(' ', $content_classes),
|
2012-12-17 17:26:44 +01:00
|
|
|
),
|
2013-03-09 22:52:41 +01:00
|
|
|
array(
|
2013-05-06 23:01:57 +02:00
|
|
|
$subhead,
|
2013-03-09 22:52:41 +01:00
|
|
|
$attrs,
|
|
|
|
$this->renderChildren(),
|
2013-03-23 22:37:18 +01:00
|
|
|
$foot,
|
2013-03-09 22:52:41 +01:00
|
|
|
));
|
2012-12-17 17:26:44 +01:00
|
|
|
|
2013-01-18 09:32:58 +01:00
|
|
|
return phutil_tag(
|
2013-03-23 22:38:01 +01:00
|
|
|
'div',
|
2012-08-15 19:45:06 +02:00
|
|
|
array(
|
2013-03-23 22:38:01 +01:00
|
|
|
'class' => 'phabricator-object-item-frame',
|
2012-08-15 19:45:06 +02:00
|
|
|
),
|
2013-03-23 22:38:01 +01:00
|
|
|
array(
|
|
|
|
$grippable,
|
2013-04-06 20:38:43 +02:00
|
|
|
$header,
|
2013-03-23 22:38:01 +01:00
|
|
|
$icons,
|
2013-04-06 20:38:43 +02:00
|
|
|
$bylines,
|
2013-03-23 22:38:01 +01:00
|
|
|
$content,
|
|
|
|
));
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|
|
|
|
|
2013-03-10 02:55:01 +01:00
|
|
|
private function renderFootIcon($icon, $label) {
|
|
|
|
require_celerity_resource('sprite-icon-css');
|
|
|
|
|
|
|
|
$icon = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'sprite-icon action-'.$icon,
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
|
|
|
|
$label = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
),
|
|
|
|
$label);
|
|
|
|
|
|
|
|
return phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-item-foot-icon',
|
|
|
|
),
|
|
|
|
array($icon, $label));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function renderHandleIcon(PhabricatorObjectHandle $handle, $label) {
|
|
|
|
Javelin::initBehavior('phabricator-tooltips');
|
|
|
|
|
2013-03-19 19:16:41 +01:00
|
|
|
$options = array(
|
|
|
|
'class' => 'phabricator-object-item-handle-icon',
|
2013-03-24 02:38:03 +01:00
|
|
|
'style' => 'background-image: url('.$handle->getImageURI().')',
|
2013-03-19 19:16:41 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (strlen($label)) {
|
|
|
|
$options['sigil'] = 'has-tooltip';
|
|
|
|
$options['meta'] = array('tip' => $label);
|
|
|
|
}
|
|
|
|
|
2013-03-10 02:55:01 +01:00
|
|
|
return javelin_tag(
|
|
|
|
'span',
|
2013-03-19 19:16:41 +01:00
|
|
|
$options,
|
2013-03-10 02:55:01 +01:00
|
|
|
'');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-15 19:45:06 +02:00
|
|
|
}
|