Skip to content

Commit b1701b9

Browse files
committed
afterCompileHtml event + _self
_self introduction in BaseWidget afterCompileHtml event Recursive setInverted
1 parent f5f4952 commit b1701b9

File tree

15 files changed

+141
-108
lines changed

15 files changed

+141
-108
lines changed

Ajax/JsUtils.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ public function config($config=NULL) {
166166
return $this->config;
167167
}
168168

169+
/**
170+
* @param array $params ['driver'=>'jquery','debug'=>true,'defer'=>false,'ajaxTransition'=>null,'afterCompileHtml'=>null]
171+
* @param mixed $injected optional param for Symfony
172+
*/
169173
public function __construct($params=array(),$injected=NULL) {
170174
$defaults=['driver'=>'Jquery','debug'=>true,'defer'=>false,'ajaxTransition'=>null];
171175
foreach ( $defaults as $key => $val ) {
@@ -178,6 +182,9 @@ public function __construct($params=array(),$injected=NULL) {
178182
if(\array_key_exists("semantic", $params)){
179183
$this->semantic(new Semantic());
180184
}
185+
if(\array_key_exists("bootstrap", $params)){
186+
$this->bootstrap(new Bootstrap());
187+
}
181188
$this->cdns=array ();
182189
$this->params=$params;
183190
$this->injected=$injected;
@@ -199,8 +206,12 @@ public function __set($property, $value){
199206
}
200207
}
201208

209+
/**
210+
* @param string $key
211+
*/
202212
public function getParam($key){
203-
return $this->params[$key];
213+
if(isset($this->params[$key]))
214+
return $this->params[$key];
204215
}
205216

206217
public function addToCompile($jsScript) {

Ajax/common/Widget.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function __construct($identifier,$model,$modelInstance=NULL) {
6666
protected function _init($instanceViewer,$contentKey,$content,$edition){
6767
$this->_instanceViewer=$instanceViewer;
6868
$this->content=[$contentKey=>$content];
69+
$this->_self=$content;
6970
$this->_toolbarPosition=PositionInTable::BEFORETABLE;
7071
$this->_edition=$edition;
7172
}
@@ -440,4 +441,8 @@ public function asModal($header=null){
440441
}
441442
return $modal;
442443
}
444+
445+
public function addToProperty($name, $value, $separator=" ") {
446+
return $this->getHtmlComponent()->addToProperty($name,$value,$separator);
447+
}
443448
}

Ajax/common/html/BaseHtml.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ protected function compile_once(JsUtils $js=NULL, &$view=NULL) {
192192
}
193193
public function compile(JsUtils $js=NULL, &$view=NULL) {
194194
if(!$this->_compiled){
195+
if(isset($js)){
196+
$afterCompile=$js->getParam("afterCompileHtml");
197+
if(\is_callable($afterCompile)){
198+
$afterCompile($this,$js,$view);
199+
}
200+
}
195201
$this->compile_once($js,$view);
196202
$this->_compiled=true;
197203
}

Ajax/common/html/BaseWidget.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
abstract class BaseWidget {
1111
protected $identifier;
1212
protected $_identifier;
13+
protected $_self;
1314

1415
public function __construct($identifier) {
1516
$this->identifier=$this->cleanIdentifier($identifier);
1617
$this->_identifier=$this->identifier;
18+
$this->_self=$this;
1719
}
1820

1921
public function getIdentifier() {

Ajax/common/html/traits/BaseHtmlPropertiesTrait.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
use Ajax\service\JString;
55
use Ajax\common\html\BaseHtml;
6+
use Ajax\common\html\BaseWidget;
67

78
/**
89
* @author jc
9-
*
10+
* @property BaseWidget $_self
1011
*/
1112
trait BaseHtmlPropertiesTrait{
1213

@@ -15,101 +16,101 @@ abstract protected function ctrl($name, $value, $typeCtrl);
1516
abstract protected function removeOldValues(&$oldValue, $allValues);
1617
abstract protected function _getElementBy($callback,$elements);
1718
public function getProperties() {
18-
return $this->properties;
19+
return $this->_self->properties;
1920
}
2021

2122
/**
2223
* @param array $properties
2324
* @return BaseHtml
2425
*/
2526
public function setProperties($properties) {
26-
$this->properties=$properties;
27+
$this->_self->properties=$properties;
2728
return $this;
2829
}
2930

3031
public function setProperty($name, $value) {
31-
$this->properties[$name]=$value;
32+
$this->_self->properties[$name]=$value;
3233
return $this;
3334
}
3435

3536
public function getProperty($name) {
36-
if (array_key_exists($name, $this->properties))
37-
return $this->properties[$name];
37+
if (array_key_exists($name, $this->_self->properties))
38+
return $this->_self->properties[$name];
3839
}
3940

4041
public function addToProperty($name, $value, $separator=" ") {
4142
if (\is_array($value)) {
4243
foreach ( $value as $v ) {
43-
$this->addToProperty($name, $v, $separator);
44+
$this->_self->addToProperty($name, $v, $separator);
4445
}
45-
} else if ($value !== "" && $this->propertyContains($name, $value) === false) {
46-
$v=@$this->properties[$name];
46+
} else if ($value !== "" && $this->_self->propertyContains($name, $value) === false) {
47+
$v=@$this->_self->properties[$name];
4748
if (isset($v) && $v !== "")
4849
$v=$v . $separator . $value;
4950
else
5051
$v=$value;
5152

52-
return $this->setProperty($name, $v);
53+
return $this->_self->setProperty($name, $v);
5354
}
5455
return $this;
5556
}
5657

5758
public function addProperties($properties) {
58-
$this->properties=array_merge($this->properties, $properties);
59+
$this->_self->properties=array_merge($this->_self->properties, $properties);
5960
return $this;
6061
}
6162

6263
protected function removePropertyValue($name, $value) {
63-
$this->properties[$name]=\str_replace($value, "", $this->properties[$name]);
64+
$this->_self->properties[$name]=\str_replace($value, "", $this->_self->properties[$name]);
6465
return $this;
6566
}
6667

6768
protected function removePropertyValues($name, $values) {
68-
$this->removeOldValues($this->properties[$name], $values);
69+
$this->_self->removeOldValues($this->_self->properties[$name], $values);
6970
return $this;
7071
}
7172

7273
protected function addToPropertyUnique($name, $value, $typeCtrl) {
7374
if (@class_exists($typeCtrl, true))
7475
$typeCtrl=$typeCtrl::getConstants();
7576
if (\is_array($typeCtrl)) {
76-
$this->removeOldValues($this->properties[$name], $typeCtrl);
77+
$this->_self->removeOldValues($this->_self->properties[$name], $typeCtrl);
7778
}
78-
return $this->addToProperty($name, $value);
79+
return $this->_self->addToProperty($name, $value);
7980
}
8081

8182
public function addToPropertyCtrl($name, $value, $typeCtrl) {
82-
return $this->addToPropertyUnique($name, $value, $typeCtrl);
83+
return $this->_self->addToPropertyUnique($name, $value, $typeCtrl);
8384
}
8485

8586
public function addToPropertyCtrlCheck($name, $value, $typeCtrl) {
86-
if ($this->ctrl($name, $value, $typeCtrl) === true) {
87-
return $this->addToProperty($name, $value);
87+
if ($this->_self->ctrl($name, $value, $typeCtrl) === true) {
88+
return $this->_self->addToProperty($name, $value);
8889
}
8990
return $this;
9091
}
9192

9293
public function removeProperty($name) {
93-
if (\array_key_exists($name, $this->properties))
94-
unset($this->properties[$name]);
94+
if (\array_key_exists($name, $this->_self->properties))
95+
unset($this->_self->properties[$name]);
9596
return $this;
9697
}
9798

9899
public function propertyContains($propertyName, $value) {
99-
$values=$this->getProperty($propertyName);
100+
$values=$this->_self->getProperty($propertyName);
100101
if (isset($values)) {
101102
return JString::contains($values, $value);
102103
}
103104
return false;
104105
}
105106

106107
protected function setPropertyCtrl($name, $value, $typeCtrl) {
107-
if ($this->ctrl($name, $value, $typeCtrl) === true)
108-
return $this->setProperty($name, $value);
108+
if ($this->_self->ctrl($name, $value, $typeCtrl) === true)
109+
return $this->_self->setProperty($name, $value);
109110
return $this;
110111
}
111112

112113
protected function getElementByPropertyValue($propertyName,$value, $elements) {
113-
return $this->_getElementBy(function($element) use ($propertyName,$value){return $element->propertyContains($propertyName, $value) === true;}, $elements);
114+
return $this->_self->_getElementBy(function($element) use ($propertyName,$value){return $element->propertyContains($propertyName, $value) === true;}, $elements);
114115
}
115116
}

0 commit comments

Comments
 (0)