Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / view / phui / PHUITabGroupView.php
blob65e9e1c82130ecda0ce0ae494d7b7cea4f211e69
1 <?php
3 final class PHUITabGroupView extends AphrontTagView {
5 private $tabs = array();
6 private $selectedTab;
7 private $vertical;
9 private $hideSingleTab;
11 protected function canAppendChild() {
12 return false;
15 public function setVertical($vertical) {
16 $this->vertical = $vertical;
17 return $this;
20 public function getVertical() {
21 return $this->vertical;
24 public function setHideSingleTab($hide_single_tab) {
25 $this->hideSingleTab = $hide_single_tab;
26 return $this;
29 public function getHideSingleTab() {
30 return $this->hideSingleTab;
33 public function addTab(PHUITabView $tab) {
34 $key = $tab->getKey();
35 $tab->lockKey();
37 if (isset($this->tabs[$key])) {
38 throw new Exception(
39 pht(
40 'Each tab in a tab group must have a unique key; attempting to add '.
41 'a second tab with a duplicate key ("%s").',
42 $key));
45 $this->tabs[$key] = $tab;
47 return $this;
50 public function selectTab($key) {
51 if (empty($this->tabs[$key])) {
52 throw new Exception(
53 pht(
54 'Unable to select tab ("%s") which does not exist.',
55 $key));
58 $this->selectedTab = $key;
60 return $this;
63 public function getSelectedTabKey() {
64 if (!$this->tabs) {
65 return null;
68 if ($this->selectedTab !== null) {
69 return $this->selectedTab;
72 return head($this->tabs)->getKey();
75 protected function getTagAttributes() {
76 $tab_map = mpull($this->tabs, 'getContentID', 'getKey');
78 $classes = array();
79 if ($this->getVertical()) {
80 $classes[] = 'phui-tab-group-view-vertical';
83 return array(
84 'class' => $classes,
85 'sigil' => 'phui-tab-group-view',
86 'meta' => array(
87 'tabMap' => $tab_map,
92 protected function getTagContent() {
93 Javelin::initBehavior('phui-tab-group');
95 $tabs = new PHUIListView();
97 if ($this->getVertical()) {
98 $tabs->setType(PHUIListView::NAVBAR_VERTICAL);
99 } else {
100 $tabs->setType(PHUIListView::NAVBAR_LIST);
103 $content = array();
105 $selected_tab = $this->getSelectedTabKey();
106 foreach ($this->tabs as $tab) {
107 $item = $tab->newMenuItem();
108 $tab_key = $tab->getKey();
110 if ($tab_key == $selected_tab) {
111 $item->setSelected(true);
112 $style = null;
113 } else {
114 $style = 'display: none;';
117 $tabs->addMenuItem($item);
119 $content[] = javelin_tag(
120 'div',
121 array(
122 'style' => $style,
123 'id' => $tab->getContentID(),
125 $tab);
128 if ($this->hideSingleTab && (count($this->tabs) == 1)) {
129 $tabs = null;
132 if ($tabs && $this->getVertical()) {
133 $content = phutil_tag(
134 'table',
135 array(
136 'style' => 'width: 100%',
138 phutil_tag(
139 'tbody',
140 array(),
141 phutil_tag(
142 'tr',
143 array(),
144 array(
145 phutil_tag(
146 'td',
147 array(
148 'class' => 'phui-tab-group-view-tab-column',
150 $tabs),
151 phutil_tag(
152 'td',
153 array(),
154 $content),
155 ))));
156 $tabs = null;
159 return array(
160 $tabs,
161 $content,