2012-12-07 22:35:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCrumbsView extends AphrontView {
|
|
|
|
|
|
|
|
private $crumbs = array();
|
|
|
|
private $actions = array();
|
2013-04-09 21:42:03 +02:00
|
|
|
private $actionListID = null;
|
2012-12-07 22:35:17 +01:00
|
|
|
|
|
|
|
protected function canAppendChild() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addCrumb(PhabricatorCrumbView $crumb) {
|
|
|
|
$this->crumbs[] = $crumb;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addAction(PhabricatorMenuItemView $action) {
|
|
|
|
$this->actions[] = $action;
|
2013-04-09 21:42:03 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2012-12-07 22:35:17 +01:00
|
|
|
|
2013-04-09 21:42:03 +02:00
|
|
|
public function setActionList(PhabricatorActionListView $list) {
|
|
|
|
$this->actionListID = celerity_generate_unique_node_id();
|
|
|
|
$list->setId($this->actionListID);
|
2012-12-07 22:35:17 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
require_celerity_resource('phabricator-crumbs-view-css');
|
|
|
|
|
|
|
|
$action_view = null;
|
2013-04-10 22:08:36 +02:00
|
|
|
if (($this->actions) || ($this->actionListID)) {
|
2012-12-07 22:35:17 +01:00
|
|
|
$actions = array();
|
|
|
|
foreach ($this->actions as $action) {
|
|
|
|
$icon = null;
|
|
|
|
if ($action->getIcon()) {
|
2013-01-18 03:57:09 +01:00
|
|
|
$icon = phutil_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'sprite-icon action-'.$action->getIcon(),
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
2013-03-26 21:15:15 +01:00
|
|
|
$name = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-crumbs-action-name'
|
|
|
|
),
|
|
|
|
$action->getName()
|
|
|
|
);
|
2013-04-09 21:42:03 +02:00
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$actions[] = javelin_tag(
|
2012-12-07 22:35:17 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $action->getHref(),
|
|
|
|
'class' => 'phabricator-crumbs-action',
|
2013-01-11 20:58:31 +01:00
|
|
|
'sigil' => $action->getWorkflow() ? 'workflow' : null,
|
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-04-09 21:42:03 +02:00
|
|
|
if ($this->actionListID) {
|
|
|
|
$icon_id = celerity_generate_unique_node_id();
|
|
|
|
$icon = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'sprite-icon action-action-menu'
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
$name = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-crumbs-action-name'
|
|
|
|
),
|
|
|
|
pht('Actions'));
|
|
|
|
|
|
|
|
$actions[] = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '#',
|
|
|
|
'class' =>
|
|
|
|
'phabricator-crumbs-action phabricator-crumbs-action-menu',
|
|
|
|
'sigil' => 'jx-toggle-class',
|
|
|
|
'id' => $icon_id,
|
|
|
|
'meta' => array(
|
|
|
|
'map' => array(
|
|
|
|
$this->actionListID => 'phabricator-action-list-toggle',
|
|
|
|
$icon_id => 'phabricator-crumbs-action-menu-open'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$icon,
|
|
|
|
$name,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|