2012-12-07 22:35:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCrumbsView extends AphrontView {
|
|
|
|
|
|
|
|
private $crumbs = array();
|
|
|
|
private $actions = array();
|
|
|
|
|
|
|
|
protected function canAppendChild() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-19 02:47:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method for adding a simple crumb with just text, or text and
|
|
|
|
* a link.
|
|
|
|
*
|
|
|
|
* @param string Text of the crumb.
|
|
|
|
* @param string? Optional href for the crumb.
|
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
public function addTextCrumb($text, $href = null) {
|
|
|
|
return $this->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($text)
|
|
|
|
->setHref($href));
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:35:17 +01:00
|
|
|
public function addCrumb(PhabricatorCrumbView $crumb) {
|
|
|
|
$this->crumbs[] = $crumb;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-05 17:41:43 +02:00
|
|
|
public function addAction(PHUIListItemView $action) {
|
2012-12-07 22:35:17 +01:00
|
|
|
$this->actions[] = $action;
|
2013-04-09 21:42:03 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2012-12-07 22:35:17 +01:00
|
|
|
|
|
|
|
public function render() {
|
|
|
|
require_celerity_resource('phabricator-crumbs-view-css');
|
|
|
|
|
|
|
|
$action_view = null;
|
2015-01-12 16:24:35 +01:00
|
|
|
if ($this->actions) {
|
2012-12-07 22:35:17 +01:00
|
|
|
$actions = array();
|
|
|
|
foreach ($this->actions as $action) {
|
|
|
|
$icon = null;
|
|
|
|
if ($action->getIcon()) {
|
2013-10-15 03:21:06 +02:00
|
|
|
$icon_name = $action->getIcon();
|
|
|
|
if ($action->getDisabled()) {
|
2014-05-12 19:08:32 +02:00
|
|
|
$icon_name .= ' lightgreytext';
|
2013-10-15 03:21:06 +02:00
|
|
|
}
|
|
|
|
|
2014-05-12 19:08:32 +02:00
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setIconFont($icon_name);
|
|
|
|
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
2013-03-26 21:15:15 +01:00
|
|
|
$name = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phabricator-crumbs-action-name',
|
2013-03-26 21:15:15 +01:00
|
|
|
),
|
2013-06-05 00:28:24 +02:00
|
|
|
$action->getName());
|
2013-04-09 21:42:03 +02:00
|
|
|
|
2013-05-24 19:50:18 +02:00
|
|
|
$action_sigils = $action->getSigils();
|
|
|
|
if ($action->getWorkflow()) {
|
|
|
|
$action_sigils[] = 'workflow';
|
|
|
|
}
|
|
|
|
$action_classes = $action->getClasses();
|
|
|
|
$action_classes[] = 'phabricator-crumbs-action';
|
2013-10-15 03:21:06 +02:00
|
|
|
|
|
|
|
if ($action->getDisabled()) {
|
|
|
|
$action_classes[] = 'phabricator-crumbs-action-disabled';
|
|
|
|
}
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$actions[] = javelin_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $action->getHref(),
|
2013-05-24 19:50:18 +02:00
|
|
|
'class' => implode(' ', $action_classes),
|
|
|
|
'sigil' => implode(' ', $action_sigils),
|
2014-10-07 15:01:04 +02:00
|
|
|
'style' => $action->getStyle(),
|
2012-12-07 22:35:17 +01:00
|
|
|
),
|
2013-01-25 21:57:17 +01:00
|
|
|
array(
|
|
|
|
$icon,
|
2013-03-26 21:15:15 +01:00
|
|
|
$name,
|
2013-01-25 21:57:17 +01:00
|
|
|
));
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
|
|
|
|
2013-01-31 18:07:31 +01:00
|
|
|
$action_view = phutil_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-crumbs-actions',
|
|
|
|
),
|
2013-03-09 22:52:41 +01:00
|
|
|
$actions);
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->crumbs) {
|
|
|
|
last($this->crumbs)->setIsLastCrumb(true);
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:07:31 +01:00
|
|
|
return phutil_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'div',
|
|
|
|
array(
|
2012-12-07 22:35:49 +01:00
|
|
|
'class' => 'phabricator-crumbs-view '.
|
|
|
|
'sprite-gradient gradient-breadcrumbs',
|
2012-12-07 22:35:17 +01:00
|
|
|
),
|
2013-03-09 22:52:41 +01:00
|
|
|
array(
|
|
|
|
$action_view,
|
|
|
|
$this->crumbs,
|
|
|
|
));
|
2012-12-07 22:35:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|