1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xoops\Form;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: class TabTray extends ElementTray
25: {
26: 27: 28: 29: 30: 31:
32: public function __construct($caption, $name = null)
33: {
34: if (is_array($caption)) {
35: parent::__construct($caption);
36: } else {
37: parent::__construct([]);
38: $this->setName($name);
39: $this->setCaption($caption);
40: }
41: }
42:
43: 44: 45: 46: 47:
48: public function render()
49: {
50: $xoops = \Xoops::getInstance();
51: $xoops->theme()->addBaseScriptAssets('@jquery');
52: $xoops->theme()->addBaseScriptAssets('@jqueryui');
53: $xoops->theme()->addBaseStylesheetAssets('@jqueryuicss');
54: $xoops->theme()->addScript('', '', '$(function() { $("#tabs_' . $this->getName() . '").tabs(); });');
55:
56: $ret = '<div id="tabs_' . $this->getName() . '">' . "\n";
57: $ret .= '<ul>' . "\n";
58: foreach ($this->getElements() as $ele) {
59: if ($ele instanceof Tab) {
60: $ret .= '<li><a href="#tab_' . $ele->getName() . '"><span>'
61: . $ele->getCaption() . '</span></a></li>' . "\n";
62: }
63: }
64: $ret .= '</ul>' . "\n";
65:
66: $hidden = '';
67: $extras = array();
68:
69: foreach ($this->getElements() as $ele) {
70:
71: if (!$ele->isHidden()) {
72: if (!$ele instanceof Raw) {
73: if ($ele instanceof Tab) {
74: $ret .= '<div id="tab_' . $ele->getName() . '">' . "\n";
75: $ret .= '<table class="outer" cellspacing="1">' . "\n";
76: $ret .= $ele->render();
77: $ret .= '</table>' . "\n";
78: $ret .= '</div>' . "\n";
79: } else {
80: $extras[] = $ele;
81: }
82: } else {
83: $ret .= $ele->render();
84: }
85: } else {
86: $hidden .= $ele->render();
87: }
88: }
89: if (!empty($extras)) {
90: $tray = new ElementTray('', $this->getJoiner());
91: foreach ($extras as $extra) {
92: $tray->addElement($extra);
93: }
94: $ret .= $tray->render();
95: $ret .= "\n";
96: }
97:
98: $ret .= $hidden . "\n";
99: $ret .= '</div>' . "\n";
100: return $ret;
101: }
102: }
103: