Path: blob/master/src/view/phui/PHUITabGroupView.php
12249 views
<?php12final class PHUITabGroupView extends AphrontTagView {34private $tabs = array();5private $selectedTab;6private $vertical;78private $hideSingleTab;910protected function canAppendChild() {11return false;12}1314public function setVertical($vertical) {15$this->vertical = $vertical;16return $this;17}1819public function getVertical() {20return $this->vertical;21}2223public function setHideSingleTab($hide_single_tab) {24$this->hideSingleTab = $hide_single_tab;25return $this;26}2728public function getHideSingleTab() {29return $this->hideSingleTab;30}3132public function addTab(PHUITabView $tab) {33$key = $tab->getKey();34$tab->lockKey();3536if (isset($this->tabs[$key])) {37throw new Exception(38pht(39'Each tab in a tab group must have a unique key; attempting to add '.40'a second tab with a duplicate key ("%s").',41$key));42}4344$this->tabs[$key] = $tab;4546return $this;47}4849public function selectTab($key) {50if (empty($this->tabs[$key])) {51throw new Exception(52pht(53'Unable to select tab ("%s") which does not exist.',54$key));55}5657$this->selectedTab = $key;5859return $this;60}6162public function getSelectedTabKey() {63if (!$this->tabs) {64return null;65}6667if ($this->selectedTab !== null) {68return $this->selectedTab;69}7071return head($this->tabs)->getKey();72}7374protected function getTagAttributes() {75$tab_map = mpull($this->tabs, 'getContentID', 'getKey');7677$classes = array();78if ($this->getVertical()) {79$classes[] = 'phui-tab-group-view-vertical';80}8182return array(83'class' => $classes,84'sigil' => 'phui-tab-group-view',85'meta' => array(86'tabMap' => $tab_map,87),88);89}9091protected function getTagContent() {92Javelin::initBehavior('phui-tab-group');9394$tabs = new PHUIListView();9596if ($this->getVertical()) {97$tabs->setType(PHUIListView::NAVBAR_VERTICAL);98} else {99$tabs->setType(PHUIListView::NAVBAR_LIST);100}101102$content = array();103104$selected_tab = $this->getSelectedTabKey();105foreach ($this->tabs as $tab) {106$item = $tab->newMenuItem();107$tab_key = $tab->getKey();108109if ($tab_key == $selected_tab) {110$item->setSelected(true);111$style = null;112} else {113$style = 'display: none;';114}115116$tabs->addMenuItem($item);117118$content[] = javelin_tag(119'div',120array(121'style' => $style,122'id' => $tab->getContentID(),123),124$tab);125}126127if ($this->hideSingleTab && (count($this->tabs) == 1)) {128$tabs = null;129}130131if ($tabs && $this->getVertical()) {132$content = phutil_tag(133'table',134array(135'style' => 'width: 100%',136),137phutil_tag(138'tbody',139array(),140phutil_tag(141'tr',142array(),143array(144phutil_tag(145'td',146array(147'class' => 'phui-tab-group-view-tab-column',148),149$tabs),150phutil_tag(151'td',152array(),153$content),154))));155$tabs = null;156}157158return array(159$tabs,160$content,161);162}163164}165166167