1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: namespace picon;
24:
25: 26: 27: 28: 29: 30:
31: class TabPanel extends Panel
32: {
33: private $collection;
34: private $selctedTab = 0;
35: const PANEL_ID = 'panel';
36:
37: public function __construct($id, TabCollection $collection)
38: {
39: parent::__construct($id);
40: $this->collection = $collection;
41: $this->setup();
42: }
43:
44: protected function getCollection()
45: {
46: return $this->collection;
47: }
48:
49: protected function setup()
50: {
51: $this->setSelectedTab(0);
52: }
53:
54: protected function onInitialize()
55: {
56: parent::onInitialize();
57: $me = $this;
58:
59: $this->add(new ListView("tab", function($item) use ($me)
60: {
61: $tab = $item->getModelObject();
62: $link = $me->newLink('link', $item->getIndex());
63: if($me->getSelectedTab()==$item->getIndex())
64: {
65: $item->add(new \picon\AttributeAppender('class', new \picon\BasicModel('selected'), ' '));
66: }
67:
68: $item->add($link);
69: $link->add(new \picon\Label('name', new \picon\BasicModel($tab->name)));
70: }, new ArrayModel($this->collection->tabs)));
71: }
72:
73: public function newLink($id, $index)
74: {
75: $me = $this;
76: return new \picon\Link($id, function() use ($me, $item, $index)
77: {
78: $me->setSelectedTab($index);
79: });
80: }
81:
82: private function getPanelForSelected()
83: {
84: $tabs = $this->collection->tabs;
85: if(count($tabs)<1)
86: {
87: return new EmptyPanel(self::PANEL_ID);
88: }
89: else
90: {
91: $tab = $tabs[$this->selctedTab];
92: return $tab->newTab(self::PANEL_ID);
93: }
94: }
95:
96: public function setSelectedTab($tabIndex)
97: {
98: $this->selctedTab = $tabIndex;
99: $this->addOrReplace($this->getPanelForSelected());
100: }
101:
102: public function getSelectedTab()
103: {
104: return $this->selctedTab;
105: }
106: }
107:
108: ?>
109: