Skip to content

Commit d789b09

Browse files
committed
HtmlTab finished
1 parent 4924e44 commit d789b09

File tree

2 files changed

+167
-13
lines changed

2 files changed

+167
-13
lines changed

Ajax/semantic/html/content/HtmlMenuItem.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Ajax\semantic\html\content;
44

5-
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6-
use Ajax\semantic\html\elements\HtmlIcon;
75
use Ajax\service\JArray;
86

97
class HtmlMenuItem extends HtmlAbsractItem {

Ajax/semantic/html/modules/HtmlTab.php

Lines changed: 167 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66
use Ajax\semantic\html\collections\menus\HtmlMenu;
77
use Ajax\semantic\html\base\constants\Side;
88
use Ajax\JsUtils;
9+
use Ajax\semantic\html\base\constants\Direction;
910

11+
/**
12+
* Semantic Tab component
13+
* @see http://semantic-ui.com/collections/tab.html
14+
* @author jc
15+
* @version 1.001
16+
*/
1017
class HtmlTab extends HtmlSemCollection{
18+
1119
protected $params=array("debug"=>true);
1220

1321
public function __construct( $identifier, $tabs=array()){
@@ -18,6 +26,11 @@ public function __construct( $identifier, $tabs=array()){
1826
$this->addItems($tabs);
1927
}
2028

29+
/**
30+
* {@inheritDoc}
31+
* @see \Ajax\common\html\HtmlCollection::createItem()
32+
* @return HtmlSegment
33+
*/
2134
protected function createItem($value){
2235
$count=$this->count();
2336
$title=$value;
@@ -28,44 +41,186 @@ protected function createItem($value){
2841
$menuItem=$this->content["menu"]->addItem($title);
2942
$menuItem->addToProperty("data-tab", $menuItem->getIdentifier());
3043
$menuItem->removeProperty("href");
44+
return $this->createSegment($count, $content, $menuItem->getIdentifier());
45+
}
46+
47+
/**
48+
* @param int $count
49+
* @param string $content
50+
* @param string $datatab
51+
* @return \Ajax\semantic\html\elements\HtmlSegment
52+
*/
53+
private function createSegment($count,$content,$datatab){
3154
$segment=new HtmlSegment("item-".$this->identifier."-".$count, $content);
32-
$segment->setAttachment(NULL,Side::BOTTOM)->addToProperty("class", "tab")->addToProperty("data-tab",$menuItem->getIdentifier());
55+
$segment->setAttachment(NULL,Side::BOTTOM)->addToProperty("class", "tab")->addToProperty("data-tab",$datatab);
3356
return $segment;
3457
}
3558

59+
/**
60+
* Sets the content of the tab at position $index
61+
* @param int $index index of the tab
62+
* @param String $content new content
63+
* @return \Ajax\semantic\html\modules\HtmlTab
64+
*/
65+
public function setTabContent($index,$content){
66+
$menu=$this->content["menu"];
67+
if($index<$menu->count()){
68+
if(isset($this->content[$index])===false){
69+
$this->content[$index]=$this->createSegment($index, $content, $menu->getItem($index)->getIdentifier());
70+
}else
71+
$this->content[$index]->setContent($content);
72+
}
73+
return $this;
74+
}
75+
76+
/**
77+
* Sets all contents of tabs
78+
* @param array $contents
79+
* @return \Ajax\semantic\html\modules\HtmlTab
80+
*/
81+
public function setTabsContent($contents){
82+
for($i=0;$i<\sizeof($contents);$i++){
83+
$this->setTabContent($i, $contents[$i]);
84+
}
85+
return $this;
86+
}
87+
88+
/**
89+
* Activates the tab element at $index
90+
* @param int $index
91+
* @return \Ajax\semantic\html\modules\HtmlTab
92+
*/
3693
public function activate($index){
3794
$this->content["menu"]->getItem($index)->setActive(true);
3895
$this->content[$index]->setActive(true);
3996
return $this;
4097
}
4198

42-
public function addPanel($title,$content){
99+
/**
100+
* Adds a new tab
101+
* @param string $title
102+
* @param string $content
103+
* @return \Ajax\semantic\html\elements\HtmlSegment
104+
*/
105+
public function addTab($title,$content){
43106
return $this->addItem([$title,$content]);
44107
}
45108

46109
/**
47-
* render the content of $controller::$action and set the response to a new panel
110+
* Renders the content of $controller::$action and sets the response to the tab at $index position
111+
* @param int $index
112+
* @param JsUtils $js
113+
* @param string $title The panel title
114+
* @param Controller $initialController
115+
* @param string $controller a controller
116+
* @param string $action an action
117+
* @param array $params
118+
* @return \Ajax\semantic\html\elements\HtmlSegment
119+
*/
120+
public function forwardTab($index,JsUtils $js,$title,$initialController,$controller,$action,$params=array()){
121+
if(\array_key_exists($index, $this->content)){
122+
$this->content[$index]=$js->forward($initialController, $controller, $action,$params);
123+
return $this->content[$index];
124+
}
125+
126+
return $this->addAndForwardTab($js, $title, $initialController, $controller, $action,$params);
127+
}
128+
129+
/**
130+
* Renders the content of an existing view : $controller/$action and sets the response to the tab at $index position
131+
* @param $index
48132
* @param JsUtils $js
49133
* @param string $title The panel title
50134
* @param Controller $initialController
51-
* @param string $controller a Phalcon controller
52-
* @param string $action a Phalcon action
135+
* @param string $viewName
136+
* @param $params The parameters to pass to the view
137+
* @return \Ajax\semantic\html\elements\HtmlSegment
138+
*/
139+
public function renderViewTab($index,JsUtils $js,$title,$initialController, $viewName, $params=array()) {
140+
if(\array_key_exists($index, $this->content)){
141+
$this->content[$index]=$js->renderContent($initialController, $viewName,$params);
142+
return $this->content[$index];
143+
}
144+
return $this->addAndRenderViewTab($js, $title, $initialController, $viewName,$params);
145+
}
146+
147+
148+
/**
149+
* render the content of $controller::$action and set the response to a new tab
150+
* @param JsUtils $js
151+
* @param string $title The panel title
152+
* @param Controller $initialController
153+
* @param string $controller a controller
154+
* @param string $action an action
53155
* @param array $params
156+
* @return \Ajax\semantic\html\elements\HtmlSegment
54157
*/
55-
public function forwardPanel(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){
56-
return $this->addPanel($title, $js->forward($initialController, $controller, $action,$params));
158+
public function addAndForwardTab(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){
159+
return $this->addTab($title, $js->forward($initialController, $controller, $action,$params));
57160
}
58161

59162
/**
60-
* render the content of an existing view : $controller/$action and set the response to a new panel
163+
* render the content of an existing view : $controller/$action and set the response to a new tab
61164
* @param JsUtils $js
62165
* @param string $title The panel title
63166
* @param Controller $initialController
64167
* @param string $viewName
65168
* @param $params The parameters to pass to the view
169+
* @return \Ajax\semantic\html\elements\HtmlSegment
66170
*/
67-
public function renderViewPanel(JsUtils $js,$title,$initialController, $viewName, $params=array()) {
68-
return $this->addPanel($title, $js->renderContent($initialController, $viewName,$params));
171+
public function addAndRenderViewTab(JsUtils $js,$title,$initialController, $viewName, $params=array()) {
172+
return $this->addTab($title, $js->renderContent($initialController, $viewName,$params));
173+
}
174+
175+
public function setPointing($value=Direction::NONE) {
176+
return $this->content["menu"]->setPointing($value);
177+
}
178+
179+
public function setSecondary() {
180+
return $this->content["menu"]->setSecondary();
181+
}
182+
183+
/**
184+
* Returns the menu item at position $index
185+
* @param int $index
186+
* @return Ajax\semantic\html\content\HtmlMenuItem
187+
*/
188+
public function getMenuTab($index){
189+
return $this->content["menu"]->getItem($index);
190+
}
191+
192+
/**
193+
* Returns the tab at position $index
194+
* @param int $index
195+
* @return HtmlSegment
196+
*/
197+
public function getTab($index){
198+
return $this->content[$index];
199+
}
200+
201+
/**
202+
* Sets the menu of tabs
203+
* @param HtmlMenu $menu
204+
* @return \Ajax\semantic\html\modules\HtmlTab
205+
*/
206+
public function setMenu($menu){
207+
for($i=0;$i<\sizeof($this->content);$i++){
208+
if($menu->getItem($i)!==NULL){
209+
if(isset($this->content[$i])===true){
210+
$menu->getItem($i)->addToProperty("data-tab",$this->content[$i]->getProperty("data-tab"));
211+
}
212+
}
213+
}
214+
for($i=0;$i<$menu->count();$i++){
215+
$menu->getItem($i)->removeProperty("href");
216+
if(isset($this->content[$i])===false){
217+
$this->content[$i]=$this->createSegment($i, "New content", $menu->getItem($i)->getIdentifier());
218+
}
219+
$menu->getItem($i)->addToProperty("data-tab",$this->content[$i]->getProperty("data-tab"));
220+
}
221+
222+
$this->content["menu"]=$menu;
223+
return $this;
69224
}
70225

71226
/*
@@ -78,8 +233,9 @@ public function run(JsUtils $js) {
78233
$this->addEventsOnRun($js);
79234
return $this->_bsComponent;
80235
}
236+
81237
public function compile(JsUtils $js=NULL, &$view=NULL) {
82-
if($this->content["menu"]->count()>0)
238+
if($this->content["menu"]->count()>0 && \sizeof($this->content)>1)
83239
$this->activate(0);
84240
return parent::compile($js,$view);
85241
}

0 commit comments

Comments
 (0)