2013-06-01 00:03:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PHUIDocumentView extends AphrontTagView {
|
|
|
|
|
2013-06-06 21:47:40 +02:00
|
|
|
/* For mobile displays, where do you want the sidebar */
|
|
|
|
const NAV_BOTTOM = 'nav_bottom';
|
|
|
|
const NAV_TOP = 'nav_top';
|
2014-03-06 20:28:24 +01:00
|
|
|
const FONT_SOURCE_SANS = 'source-sans';
|
2013-06-06 21:47:40 +02:00
|
|
|
|
2013-06-01 00:03:59 +02:00
|
|
|
private $offset;
|
2013-06-05 17:41:43 +02:00
|
|
|
private $header;
|
|
|
|
private $sidenav;
|
|
|
|
private $topnav;
|
|
|
|
private $crumbs;
|
|
|
|
private $bookname;
|
|
|
|
private $bookdescription;
|
2013-06-06 21:47:40 +02:00
|
|
|
private $mobileview;
|
2014-03-06 20:28:24 +01:00
|
|
|
private $fontKit;
|
2015-01-19 21:42:05 +01:00
|
|
|
private $actionListID;
|
2013-06-01 00:03:59 +02:00
|
|
|
|
|
|
|
public function setOffset($offset) {
|
|
|
|
$this->offset = $offset;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
public function setHeader(PHUIHeaderView $header) {
|
2014-06-24 18:39:32 +02:00
|
|
|
$header->setHeaderColor(PHUIActionHeaderView::HEADER_LIGHTBLUE);
|
2013-06-05 17:41:43 +02:00
|
|
|
$this->header = $header;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-06 21:47:40 +02:00
|
|
|
public function setSideNav(PHUIListView $list, $display = self::NAV_BOTTOM) {
|
2013-06-06 17:36:51 +02:00
|
|
|
$list->setType(PHUIListView::SIDENAV_LIST);
|
2013-06-05 17:41:43 +02:00
|
|
|
$this->sidenav = $list;
|
2013-06-06 21:47:40 +02:00
|
|
|
$this->mobileview = $display;
|
2013-06-05 17:41:43 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTopNav(PHUIListView $list) {
|
2013-06-06 17:36:51 +02:00
|
|
|
$list->setType(PHUIListView::NAVBAR_LIST);
|
2013-06-05 17:41:43 +02:00
|
|
|
$this->topnav = $list;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCrumbs(PHUIListView $list) {
|
|
|
|
$this->crumbs = $list;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBook($name, $description) {
|
|
|
|
$this->bookname = $name;
|
|
|
|
$this->bookdescription = $description;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:28:24 +01:00
|
|
|
public function setFontKit($kit) {
|
|
|
|
$this->fontKit = $kit;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-01-19 21:42:05 +01:00
|
|
|
public function setActionListID($id) {
|
|
|
|
$this->actionListID = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:54:39 +01:00
|
|
|
protected function getTagAttributes() {
|
2013-06-01 00:03:59 +02:00
|
|
|
$classes = array();
|
|
|
|
|
|
|
|
if ($this->offset) {
|
|
|
|
$classes[] = 'phui-document-offset';
|
|
|
|
};
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'class' => $classes,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:54:39 +01:00
|
|
|
protected function getTagContent() {
|
2013-06-01 00:03:59 +02:00
|
|
|
require_celerity_resource('phui-document-view-css');
|
2014-03-06 20:28:24 +01:00
|
|
|
if ($this->fontKit) {
|
|
|
|
require_celerity_resource('phui-fontkit-css');
|
|
|
|
}
|
2013-06-01 00:03:59 +02:00
|
|
|
|
2014-03-06 20:39:48 +01:00
|
|
|
switch ($this->fontKit) {
|
|
|
|
case self::FONT_SOURCE_SANS:
|
|
|
|
require_celerity_resource('font-source-sans-pro');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-05 17:41:43 +02:00
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'phui-document-view';
|
|
|
|
if ($this->offset) {
|
|
|
|
$classes[] = 'phui-offset-view';
|
|
|
|
}
|
|
|
|
if ($this->sidenav) {
|
|
|
|
$classes[] = 'phui-sidenav-view';
|
|
|
|
}
|
|
|
|
|
|
|
|
$sidenav = null;
|
|
|
|
if ($this->sidenav) {
|
|
|
|
$sidenav = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-document-sidenav',
|
2013-06-05 17:41:43 +02:00
|
|
|
),
|
|
|
|
$this->sidenav);
|
|
|
|
}
|
|
|
|
|
|
|
|
$book = null;
|
|
|
|
if ($this->bookname) {
|
|
|
|
$book = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-document-bookname grouped',
|
2013-06-05 17:41:43 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
phutil_tag(
|
|
|
|
'span',
|
|
|
|
array('class' => 'bookname'),
|
|
|
|
$this->bookname),
|
|
|
|
phutil_tag(
|
|
|
|
'span',
|
|
|
|
array('class' => 'bookdescription'),
|
2014-10-07 15:01:04 +02:00
|
|
|
$this->bookdescription),
|
|
|
|
));
|
2013-06-05 17:41:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$topnav = null;
|
|
|
|
if ($this->topnav) {
|
|
|
|
$topnav = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-document-topnav',
|
2013-06-05 17:41:43 +02:00
|
|
|
),
|
|
|
|
$this->topnav);
|
|
|
|
}
|
|
|
|
|
|
|
|
$crumbs = null;
|
|
|
|
if ($this->crumbs) {
|
|
|
|
$crumbs = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-document-crumbs',
|
2013-06-05 17:41:43 +02:00
|
|
|
),
|
|
|
|
$this->bookName);
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:28:24 +01:00
|
|
|
if ($this->fontKit) {
|
|
|
|
$main_content = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'class' => 'phui-font-'.$this->fontKit,
|
2014-03-06 20:28:24 +01:00
|
|
|
),
|
|
|
|
$this->renderChildren());
|
|
|
|
} else {
|
|
|
|
$main_content = $this->renderChildren();
|
|
|
|
}
|
|
|
|
|
2015-01-19 21:42:05 +01:00
|
|
|
if ($this->actionListID) {
|
|
|
|
$icon_id = celerity_generate_unique_node_id();
|
|
|
|
$icon = id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-bars');
|
|
|
|
$meta = array(
|
|
|
|
'map' => array(
|
|
|
|
$this->actionListID => 'phabricator-action-list-toggle',
|
|
|
|
$icon_id => 'phuix-dropdown-open',
|
|
|
|
),);
|
|
|
|
$mobile_menu = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setText(pht('Actions'))
|
|
|
|
->setHref('#')
|
|
|
|
->setIcon($icon)
|
|
|
|
->addClass('phui-mobile-menu')
|
|
|
|
->setID($icon_id)
|
|
|
|
->addSigil('jx-toggle-class')
|
|
|
|
->setMetadata($meta);
|
|
|
|
$this->header->addActionLink($mobile_menu);
|
|
|
|
}
|
|
|
|
|
2013-06-05 17:41:43 +02:00
|
|
|
$content_inner = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-document-inner',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$book,
|
|
|
|
$this->header,
|
|
|
|
$topnav,
|
2014-03-06 20:28:24 +01:00
|
|
|
$main_content,
|
2014-10-07 15:01:04 +02:00
|
|
|
$crumbs,
|
2013-06-05 17:41:43 +02:00
|
|
|
));
|
|
|
|
|
2013-06-06 21:47:40 +02:00
|
|
|
if ($this->mobileview == self::NAV_BOTTOM) {
|
|
|
|
$order = array($content_inner, $sidenav);
|
|
|
|
} else {
|
|
|
|
$order = array($sidenav, $content_inner);
|
|
|
|
}
|
|
|
|
|
2013-06-05 17:41:43 +02:00
|
|
|
$content = phutil_tag(
|
2013-06-01 00:03:59 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-document-content',
|
|
|
|
),
|
2013-06-06 21:47:40 +02:00
|
|
|
$order);
|
2013-06-05 17:41:43 +02:00
|
|
|
|
|
|
|
$view = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $classes),
|
|
|
|
),
|
|
|
|
$content);
|
|
|
|
|
|
|
|
return $view;
|
2013-06-01 00:03:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|