Changeset View
Changeset View
Standalone View
Standalone View
src/view/phui/PHUITabGroupView.php
| <?php | <?php | ||||
| final class PHUITabGroupView extends AphrontTagView { | final class PHUITabGroupView extends AphrontTagView { | ||||
| private $tabs = array(); | private $tabs = array(); | ||||
| private $selectedTab; | private $selectedTab; | ||||
| private $vertical; | |||||
| private $hideSingleTab; | private $hideSingleTab; | ||||
| protected function canAppendChild() { | protected function canAppendChild() { | ||||
| return false; | return false; | ||||
| } | } | ||||
| public function setVertical($vertical) { | |||||
| $this->vertical = $vertical; | |||||
| return $this; | |||||
| } | |||||
| public function getVertical() { | |||||
| return $this->vertical; | |||||
| } | |||||
| public function setHideSingleTab($hide_single_tab) { | public function setHideSingleTab($hide_single_tab) { | ||||
| $this->hideSingleTab = $hide_single_tab; | $this->hideSingleTab = $hide_single_tab; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getHideSingleTab() { | public function getHideSingleTab() { | ||||
| return $this->hideSingleTab; | return $this->hideSingleTab; | ||||
| } | } | ||||
| Show All 38 Lines | public function getSelectedTabKey() { | ||||
| } | } | ||||
| return head($this->tabs)->getKey(); | return head($this->tabs)->getKey(); | ||||
| } | } | ||||
| protected function getTagAttributes() { | protected function getTagAttributes() { | ||||
| $tab_map = mpull($this->tabs, 'getContentID', 'getKey'); | $tab_map = mpull($this->tabs, 'getContentID', 'getKey'); | ||||
| $classes = array(); | |||||
| if ($this->getVertical()) { | |||||
| $classes[] = 'phui-tab-group-view-vertical'; | |||||
| } | |||||
| return array( | return array( | ||||
| 'class' => $classes, | |||||
| 'sigil' => 'phui-tab-group-view', | 'sigil' => 'phui-tab-group-view', | ||||
| 'meta' => array( | 'meta' => array( | ||||
| 'tabMap' => $tab_map, | 'tabMap' => $tab_map, | ||||
| ), | ), | ||||
| ); | ); | ||||
| } | } | ||||
| protected function getTagContent() { | protected function getTagContent() { | ||||
| Javelin::initBehavior('phui-tab-group'); | Javelin::initBehavior('phui-tab-group'); | ||||
| $tabs = id(new PHUIListView()) | $tabs = new PHUIListView(); | ||||
| ->setType(PHUIListView::NAVBAR_LIST); | |||||
| if ($this->getVertical()) { | |||||
| $tabs->setType(PHUIListView::NAVBAR_VERTICAL); | |||||
| } else { | |||||
| $tabs->setType(PHUIListView::NAVBAR_LIST); | |||||
| } | |||||
| $content = array(); | $content = array(); | ||||
| $selected_tab = $this->getSelectedTabKey(); | $selected_tab = $this->getSelectedTabKey(); | ||||
| foreach ($this->tabs as $tab) { | foreach ($this->tabs as $tab) { | ||||
| $item = $tab->newMenuItem(); | $item = $tab->newMenuItem(); | ||||
| $tab_key = $tab->getKey(); | $tab_key = $tab->getKey(); | ||||
| if ($tab_key == $selected_tab) { | if ($tab_key == $selected_tab) { | ||||
| Show All 13 Lines | foreach ($this->tabs as $tab) { | ||||
| ), | ), | ||||
| $tab); | $tab); | ||||
| } | } | ||||
| if ($this->hideSingleTab && (count($this->tabs) == 1)) { | if ($this->hideSingleTab && (count($this->tabs) == 1)) { | ||||
| $tabs = null; | $tabs = null; | ||||
| } | } | ||||
| if ($tabs && $this->getVertical()) { | |||||
| $content = phutil_tag( | |||||
| 'table', | |||||
| array( | |||||
| 'style' => 'width: 100%', | |||||
| ), | |||||
| phutil_tag( | |||||
| 'tbody', | |||||
| array(), | |||||
| phutil_tag( | |||||
| 'tr', | |||||
| array(), | |||||
| array( | |||||
| phutil_tag( | |||||
| 'td', | |||||
| array( | |||||
| 'class' => 'phui-tab-group-view-tab-column', | |||||
| ), | |||||
| $tabs), | |||||
| phutil_tag( | |||||
| 'td', | |||||
| array(), | |||||
| $content), | |||||
| )))); | |||||
| $tabs = null; | |||||
| } | |||||
| return array( | return array( | ||||
| $tabs, | $tabs, | ||||
| $content, | $content, | ||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||