Skip to content

Commit 141d555

Browse files
committed
Shapes + HtmlButtonGroups update (Collection)
1 parent 2aad8b6 commit 141d555

File tree

9 files changed

+203
-18
lines changed

9 files changed

+203
-18
lines changed

Ajax/common/html/HtmlCollection.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,33 @@ protected function contentAs($tagName){
129129
}
130130
return $this;
131131
}
132+
133+
public function setProperties($properties){
134+
$i=0;
135+
foreach ($properties as $k=>$v){
136+
$c=$this->content[$i++];
137+
if(isset($c))
138+
$c->setProperty($k,$v);
139+
else
140+
return $this;
141+
}
142+
return $this;
143+
}
144+
145+
public function setPropertyValues($property,$values){
146+
$i=0;
147+
if(\is_array($values)===false){
148+
$values=\array_fill(0, $this->count(),$values);
149+
}
150+
foreach ($values as $value){
151+
$c=$this->content[$i++];
152+
if(isset($c)===true){
153+
$c->setProperty($property,$value);
154+
}
155+
else{
156+
return $this;
157+
}
158+
}
159+
return $this;
160+
}
132161
}

Ajax/semantic/components/Shape.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Ajax\semantic\components;
4+
5+
use Ajax\common\components\SimpleExtComponent;
6+
use Ajax\JsUtils;
7+
8+
class Shape extends SimpleExtComponent {
9+
10+
public function __construct(JsUtils $js) {
11+
parent::__construct($js);
12+
$this->uiName="shape";
13+
}
14+
}

Ajax/semantic/html/content/HtmlAbsractItem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function setActive($value=true){
5757
$this->setTagName("div");
5858
$this->removeProperty("href");
5959
$this->addToPropertyCtrl("class", "active", array("active"));
60+
}else{
61+
$this->removePropertyValue("class", "active");
6062
}
6163
return $this;
6264
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace Ajax\semantic\html\content;
3+
4+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
5+
6+
class HtmlShapeItem extends HtmlSemDoubleElement {
7+
public function __construct($identifier, $content) {
8+
parent::__construct($identifier,"div","side",$content);
9+
}
10+
11+
public function setActive($value=true){
12+
if($value){
13+
$this->addToPropertyCtrl("class", "active", ["active"]);
14+
}else{
15+
$this->removePropertyValue("class", "active");
16+
}
17+
return $this;
18+
}
19+
}

Ajax/semantic/html/elements/HtmlButtonGroups.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@
33
namespace Ajax\semantic\html\elements;
44

55
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6+
use Ajax\semantic\html\base\HtmlSemCollection;
67

78
/**
89
* Semantic UI Buttongroups component
910
* @see http://semantic-ui.com/elements/button.html
1011
* @author jc
1112
* @version 1.001
1213
*/
13-
class HtmlButtonGroups extends HtmlSemDoubleElement {
14+
class HtmlButtonGroups extends HtmlSemCollection {
1415

1516
public function __construct($identifier, $elements=array(), $asIcons=false) {
1617
parent::__construct($identifier, "div", "ui buttons");
17-
$this->content=array ();
1818
if ($asIcons === true)
1919
$this->asIcons();
2020
$this->addElements($elements, $asIcons);
2121
}
22+
protected function createItem($value){
23+
return new HtmlButton("button-" . $this->identifier . "-" . \sizeof($this->content), $value);
24+
}
25+
2226

2327
public function addElement($element, $asIcon=false) {
24-
$elementO=$element;
25-
if (\is_string($element)) {
26-
if ($asIcon) {
27-
$elementO=new HtmlButton("button-" . $this->identifier . "-" . \sizeof($this->content));
28-
$elementO->asIcon($element);
29-
} else
30-
$elementO=new HtmlButton("button-" . $this->identifier . "-" . \sizeof($this->content), $element);
31-
}
32-
$this->addContent($elementO);
28+
$item=$this->addItem($element);
29+
if($asIcon)
30+
$item->asIcon($element);
31+
return $item;
3332
}
3433

3534
public function addElements($elements, $asIcons=false) {
@@ -56,6 +55,7 @@ public function fromArray($array) {
5655

5756
public function asIcons() {
5857
foreach ( $this->content as $item ) {
58+
if($item instanceof HtmlButton)
5959
$item->asIcon($item->getContent());
6060
}
6161
return $this->addToProperty("class", "icons");
@@ -75,16 +75,11 @@ public function setLabeled() {
7575
* @return HtmlButton
7676
*/
7777
public function getElement($index) {
78-
if (is_int($index))
79-
return $this->content[$index];
80-
else {
81-
$elm=$this->getElementById($index, $this->content);
82-
return $elm;
83-
}
78+
return $this->getItem($index);
8479
}
8580

8681
public function setElement($index, $button) {
87-
$this->content[$index]=$button;
82+
$this->setItem($index, $button);
8883
return $this;
8984
}
9085

Ajax/semantic/html/elements/HtmlDivider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ public function asHeader() {
6464
public function setInverted() {
6565
return $this->addToProperty("class", "inverted");
6666
}
67+
68+
public function setIgnored(){
69+
return $this->addToProperty("class", "ignored");
70+
}
6771
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
namespace Ajax\semantic\html\modules;
3+
4+
use Ajax\semantic\html\base\HtmlSemCollection;
5+
use Ajax\semantic\html\content\HtmlShapeItem;
6+
use Ajax\JsUtils;
7+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
8+
9+
10+
class HtmlShape extends HtmlSemCollection{
11+
12+
protected $_params=array();
13+
protected $_autoActive=true;
14+
15+
public function __construct( $identifier, $sides){
16+
parent::__construct( $identifier, "div", "ui shape");
17+
$this->_template="<%tagName% id='%identifier%' %properties%><div class='sides'>%wrapContentBefore%%content%%wrapContentAfter%</div></%tagName%>";
18+
$this->addItems($sides);
19+
}
20+
21+
/**
22+
* {@inheritDoc}
23+
* @see \Ajax\common\html\HtmlCollection::createItem()
24+
*/
25+
protected function createItem($value){
26+
if(\is_object($value)===false){
27+
$value=new HtmlSemDoubleElement("","div","content",$value);
28+
}
29+
return new HtmlShapeItem("side-".$this->identifier."-".$this->count(), $value);
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
* @see \Ajax\common\html\HtmlCollection::createCondition()
35+
*/
36+
protected function createCondition($value){
37+
return ($value instanceof HtmlShapeItem)===false;
38+
}
39+
40+
/**
41+
* @param int $index
42+
* @return \Ajax\semantic\html\content\HtmlShapeItem
43+
*/
44+
public function getSide($index){
45+
return $this->getItem($index);
46+
}
47+
48+
/**
49+
* @param int $index
50+
* @return mixed|NULL
51+
*/
52+
public function getSideContent($index){
53+
$item= $this->getItem($index);
54+
if(isset($item))
55+
return $item->getContent();
56+
return null;
57+
}
58+
59+
public function jsDo($action){
60+
return "$('#".$this->identifier."').shape('".$action."');";
61+
}
62+
63+
public function jsFlipleft(){
64+
return $this->jsDo("flip left");
65+
}
66+
67+
public function setActiveSide($index){
68+
$side=$this->getSide($index);
69+
if(isset($side)){
70+
$side->setActive(true);
71+
}
72+
return $this;
73+
}
74+
75+
public function asCube(){
76+
return $this->addToPropertyCtrl("class", "cube", ["cube"]);
77+
}
78+
79+
public function asText(){
80+
return $this->addToPropertyCtrl("class", "text", ["text"]);
81+
}
82+
83+
/*
84+
* (non-PHPdoc)
85+
* @see BaseHtml::run()
86+
*/
87+
public function run(JsUtils $js) {
88+
if (isset($this->_bsComponent) === false)
89+
$this->_bsComponent=$js->semantic()->shape("#" . $this->identifier, $this->_params);
90+
$this->addEventsOnRun($js);
91+
return $this->_bsComponent;
92+
}
93+
94+
public function compile(JsUtils $js=NULL, &$view=NULL) {
95+
if($this->_autoActive)
96+
$this->setActiveSide(0);
97+
return parent::compile($js,$view);
98+
}
99+
}

Ajax/semantic/traits/SemanticComponentsTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Ajax\semantic\components\Dimmer;
1616
use Ajax\semantic\components\Modal;
1717
use Ajax\semantic\components\Tab;
18+
use Ajax\semantic\components\Shape;
1819

1920
trait SemanticComponentsTrait {
2021

@@ -140,4 +141,14 @@ public function tab($attachTo=NULL, $params=NULL) {
140141
$result= $this->addComponent(new Tab($this->js), $attachTo, $params);
141142
return $result;
142143
}
144+
145+
/**
146+
* @param string $attachTo
147+
* @param string|array $params
148+
* @return Shape
149+
*/
150+
public function shape($attachTo=NULL, $params=NULL) {
151+
$result= $this->addComponent(new Shape($this->js), $attachTo, $params);
152+
return $result;
153+
}
143154
}

Ajax/semantic/traits/SemanticHtmlModulesTrait.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Ajax\semantic\html\modules\HtmlModal;
1212
use Ajax\semantic\html\modules\checkbox\HtmlCheckbox;
1313
use Ajax\semantic\html\modules\HtmlTab;
14+
use Ajax\semantic\html\modules\HtmlShape;
1415

1516
trait SemanticHtmlModulesTrait {
1617

@@ -72,6 +73,7 @@ public function htmlDimmer($identifier, $content=NULL) {
7273

7374

7475
/**
76+
* Returns a new semantic modal dialog
7577
* @param string $identifier
7678
* @param string $header
7779
* @param string $content
@@ -91,4 +93,14 @@ public function htmlModal($identifier, $header="", $content="", $actions=array()
9193
public function htmlTab($identifier, $tabs=array()) {
9294
return $this->addHtmlComponent(new HtmlTab($identifier, $tabs));
9395
}
96+
97+
/**
98+
* Returns a new Semantic Shape
99+
* @see http://semantic-ui.com/modules/shape.html
100+
* @param array $slides
101+
* @return HtmlShape
102+
*/
103+
public function htmlShape($identifier, $slides=array()) {
104+
return $this->addHtmlComponent(new HtmlShape($identifier, $slides));
105+
}
94106
}

0 commit comments

Comments
 (0)