@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * @version 1.3 |
16 | 16 | */ |
17 | 17 | abstract class BaseHtml extends BaseWidget { |
18 | - use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait; |
|
18 | + use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait; |
|
19 | 19 | protected $_template; |
20 | 20 | protected $tagName; |
21 | - protected $_wrapBefore=array (); |
|
22 | - protected $_wrapAfter=array (); |
|
21 | + protected $_wrapBefore=array(); |
|
22 | + protected $_wrapAfter=array(); |
|
23 | 23 | protected $_bsComponent; |
24 | 24 | protected $_compiled=false; |
25 | 25 | protected $_runned=false; |
@@ -33,32 +33,32 @@ discard block |
||
33 | 33 | */ |
34 | 34 | abstract public function run(JsUtils $js); |
35 | 35 | |
36 | - private function _callSetter($setter,$key,$value,&$array){ |
|
36 | + private function _callSetter($setter, $key, $value, &$array) { |
|
37 | 37 | $result=false; |
38 | - if (method_exists($this, $setter) && substr($setter, 0, 1) !== "_") { |
|
38 | + if (method_exists($this, $setter) && substr($setter, 0, 1)!=="_") { |
|
39 | 39 | try { |
40 | 40 | $this->$setter($value); |
41 | 41 | unset($array[$key]); |
42 | 42 | $result=true; |
43 | - } catch ( \Exception $e ) { |
|
43 | + }catch (\Exception $e) { |
|
44 | 44 | $result=false; |
45 | 45 | } |
46 | 46 | } |
47 | 47 | return $result; |
48 | 48 | } |
49 | 49 | |
50 | - protected function getTemplate(JsUtils $js=NULL,$view=null) { |
|
51 | - return PropertyWrapper::wrap($this->_wrapBefore, $js,$view) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js,$view); |
|
50 | + protected function getTemplate(JsUtils $js=NULL, $view=null) { |
|
51 | + return PropertyWrapper::wrap($this->_wrapBefore, $js, $view).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js, $view); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | protected function ctrl($name, $value, $typeCtrl) { |
55 | 55 | if (\is_array($typeCtrl)) { |
56 | - if (array_search($value, $typeCtrl) === false) { |
|
57 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
56 | + if (array_search($value, $typeCtrl)===false) { |
|
57 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
58 | 58 | } |
59 | 59 | } else { |
60 | 60 | if (!$typeCtrl($value)) { |
61 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
61 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | return true; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
76 | 76 | if (\is_array($typeCtrl)) { |
77 | 77 | $this->removeOldValues($name, $typeCtrl); |
78 | - $name.=$separator . $value; |
|
78 | + $name.=$separator.$value; |
|
79 | 79 | } |
80 | 80 | return $this; |
81 | 81 | } |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | if (\is_array($typeCtrl)) { |
88 | 88 | $this->removeOldValues($name, $typeCtrl); |
89 | 89 | } |
90 | - $name.=$separator . $value; |
|
90 | + $name.=$separator.$value; |
|
91 | 91 | return $this; |
92 | 92 | } |
93 | 93 | |
94 | 94 | protected function addToMember(&$name, $value, $separator=" ") { |
95 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
95 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
96 | 96 | return $this; |
97 | 97 | } |
98 | 98 | |
@@ -103,18 +103,18 @@ discard block |
||
103 | 103 | $oldValue=trim($oldValue); |
104 | 104 | } |
105 | 105 | |
106 | - protected function _getElementBy($callback,$elements){ |
|
106 | + protected function _getElementBy($callback, $elements) { |
|
107 | 107 | if (\is_array($elements)) { |
108 | 108 | $elements=\array_values($elements); |
109 | 109 | $flag=false; |
110 | 110 | $index=0; |
111 | - while ( !$flag && $index < sizeof($elements) ) { |
|
111 | + while (!$flag && $index<sizeof($elements)) { |
|
112 | 112 | if ($elements[$index] instanceof BaseHtml) |
113 | 113 | $flag=($callback($elements[$index])); |
114 | 114 | $index++; |
115 | 115 | } |
116 | - if ($flag === true) |
|
117 | - return $elements[$index - 1]; |
|
116 | + if ($flag===true) |
|
117 | + return $elements[$index-1]; |
|
118 | 118 | } elseif ($elements instanceof BaseHtml) { |
119 | 119 | if ($callback($elements)) |
120 | 120 | return $elements; |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | public function fromArray($array) { |
145 | - foreach ( $this as $key => $value ) { |
|
146 | - if(array_key_exists($key, $array)===true) |
|
147 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
145 | + foreach ($this as $key => $value) { |
|
146 | + if (array_key_exists($key, $array)===true) |
|
147 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
148 | 148 | } |
149 | - foreach ( $array as $key => $value ) { |
|
150 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
151 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
149 | + foreach ($array as $key => $value) { |
|
150 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
151 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | return $array; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | public function fromDatabaseObjects($objects, $function) { |
158 | 158 | if (isset($objects)) { |
159 | - foreach ( $objects as $object ) { |
|
159 | + foreach ($objects as $object) { |
|
160 | 160 | $this->fromDatabaseObject($object, $function); |
161 | 161 | } |
162 | 162 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | |
179 | 179 | public function getElementById($identifier, $elements) { |
180 | - return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
180 | + return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | public function getBsComponent() { |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | } |
191 | 191 | |
192 | 192 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
193 | - if(!$this->_compiled){ |
|
194 | - if(isset($js)){ |
|
193 | + if (!$this->_compiled) { |
|
194 | + if (isset($js)) { |
|
195 | 195 | $beforeCompile=$js->getParam("beforeCompileHtml"); |
196 | - if(\is_callable($beforeCompile)){ |
|
197 | - $beforeCompile($this,$js,$view); |
|
196 | + if (\is_callable($beforeCompile)) { |
|
197 | + $beforeCompile($this, $js, $view); |
|
198 | 198 | } |
199 | 199 | } |
200 | - if(\is_callable($this->_preCompile)){ |
|
200 | + if (\is_callable($this->_preCompile)) { |
|
201 | 201 | $pc=$this->_preCompile; |
202 | 202 | $pc($this); |
203 | 203 | } |
@@ -207,17 +207,17 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
210 | - $this->compile_once($js,$view); |
|
211 | - $result=$this->getTemplate($js,$view); |
|
212 | - foreach ( $this as $key => $value ) { |
|
213 | - if(\strstr($result, "%{$key}%")!==false){ |
|
210 | + $this->compile_once($js, $view); |
|
211 | + $result=$this->getTemplate($js, $view); |
|
212 | + foreach ($this as $key => $value) { |
|
213 | + if (\strstr($result, "%{$key}%")!==false) { |
|
214 | 214 | if (\is_array($value)) { |
215 | - $v=PropertyWrapper::wrap($value, $js,$view); |
|
216 | - }elseif($value instanceof \stdClass){ |
|
217 | - $v=\print_r($value,true); |
|
218 | - }elseif ($value instanceof BaseHtml){ |
|
219 | - $v=$value->compile($js,$view); |
|
220 | - }else{ |
|
215 | + $v=PropertyWrapper::wrap($value, $js, $view); |
|
216 | + }elseif ($value instanceof \stdClass) { |
|
217 | + $v=\print_r($value, true); |
|
218 | + }elseif ($value instanceof BaseHtml) { |
|
219 | + $v=$value->compile($js, $view); |
|
220 | + } else { |
|
221 | 221 | $v=$value; |
222 | 222 | } |
223 | 223 | $result=str_replace("%{$key}%", $v, $result); |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | } |
226 | 226 | if (isset($js)===true) { |
227 | 227 | $this->run($js); |
228 | - if (isset($view) === true) { |
|
228 | + if (isset($view)===true) { |
|
229 | 229 | $js->addViewElement($this->_identifier, $result, $view); |
230 | 230 | } |
231 | 231 | } |
232 | 232 | |
233 | - if(\is_callable($this->_postCompile)){ |
|
233 | + if (\is_callable($this->_postCompile)) { |
|
234 | 234 | $pc=$this->_postCompile; |
235 | 235 | $pc($this); |
236 | 236 | } |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | * @param array $parameters default: ["jsCallback"=>"","jqueryDone"=>"append"] |
245 | 245 | * @return \Ajax\common\html\BaseHtml |
246 | 246 | */ |
247 | - public function setDraggable($attr="id",$dropZone=null,$parameters=[]){ |
|
247 | + public function setDraggable($attr="id", $dropZone=null, $parameters=[]) { |
|
248 | 248 | $this->setProperty("draggable", "true"); |
249 | - $this->addEvent("dragstart",Javascript::draggable($attr)); |
|
250 | - if(isset($dropZone)&& $dropZone instanceof BaseHtml){ |
|
251 | - $jqueryDone="append";$jsCallback=""; |
|
249 | + $this->addEvent("dragstart", Javascript::draggable($attr)); |
|
250 | + if (isset($dropZone) && $dropZone instanceof BaseHtml) { |
|
251 | + $jqueryDone="append"; $jsCallback=""; |
|
252 | 252 | extract($parameters); |
253 | - $dropZone->asDropZone($jsCallback,$jqueryDone,$parameters); |
|
253 | + $dropZone->asDropZone($jsCallback, $jqueryDone, $parameters); |
|
254 | 254 | } |
255 | 255 | return $this; |
256 | 256 | } |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | * @param array $parameters |
263 | 263 | * @return \Ajax\common\html\BaseHtml |
264 | 264 | */ |
265 | - public function asDropZone($jsCallback="",$jqueryDone="append",$parameters=[]){ |
|
265 | + public function asDropZone($jsCallback="", $jqueryDone="append", $parameters=[]) { |
|
266 | 266 | $stopPropagation=false; |
267 | - $this->addEvent("dragover", '', $stopPropagation,true); |
|
267 | + $this->addEvent("dragover", '', $stopPropagation, true); |
|
268 | 268 | extract($parameters); |
269 | - $this->addEvent("drop",Javascript::dropZone($jqueryDone,$jsCallback),$stopPropagation,true); |
|
269 | + $this->addEvent("drop", Javascript::dropZone($jqueryDone, $jsCallback), $stopPropagation, true); |
|
270 | 270 | return $this; |
271 | 271 | } |
272 | 272 | |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | return $this->compile(); |
275 | 275 | } |
276 | 276 | |
277 | - public function onPostCompile($callback){ |
|
277 | + public function onPostCompile($callback) { |
|
278 | 278 | $this->_postCompile=$callback; |
279 | 279 | } |
280 | 280 | |
281 | - public function onPreCompile($callback){ |
|
281 | + public function onPreCompile($callback) { |
|
282 | 282 | $this->_preCompile=$callback; |
283 | 283 | } |
284 | 284 | } |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | } |
13 | 13 | $output=""; |
14 | 14 | if (\is_array($input)) { |
15 | - if (sizeof($input) > 0) { |
|
16 | - if (self::containsElement($input) === false) { |
|
15 | + if (sizeof($input)>0) { |
|
16 | + if (self::containsElement($input)===false) { |
|
17 | 17 | $output=self::wrapStrings($input, $separator=' ', $valueQuote='"'); |
18 | 18 | } else { |
19 | 19 | $output=self::wrapObjects($input, $js, $view, $separator, $valueQuote); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | private static function containsElement($input) { |
27 | - foreach ( $input as $v ) { |
|
27 | + foreach ($input as $v) { |
|
28 | 28 | if (\is_object($v) || \is_array($v)) |
29 | 29 | return true; |
30 | 30 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | public static function wrapStrings($input, $separator=' ', $valueQuote='"') { |
35 | - if (JArray::isAssociative($input) === true) { |
|
36 | - $result=implode($separator, array_map(function ($v, $k) use($valueQuote) { |
|
37 | - return $k . '=' . $valueQuote . $v . $valueQuote; |
|
35 | + if (JArray::isAssociative($input)===true) { |
|
36 | + $result=implode($separator, array_map(function($v, $k) use($valueQuote) { |
|
37 | + return $k.'='.$valueQuote.$v.$valueQuote; |
|
38 | 38 | }, $input, array_keys($input))); |
39 | 39 | } else { |
40 | 40 | $result=implode($separator, $input); |
@@ -43,30 +43,30 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | public static function wrapObjects($input, $js=NULL, $view=null, $separator=' ', $valueQuote='"') { |
46 | - return implode($separator, array_map(function ($v) use($js, $view,$separator, $valueQuote) { |
|
47 | - if(\is_string($v)){ |
|
46 | + return implode($separator, array_map(function($v) use($js, $view, $separator, $valueQuote) { |
|
47 | + if (\is_string($v)) { |
|
48 | 48 | return $v; |
49 | 49 | } |
50 | - if ($v instanceof BaseHtml){ |
|
51 | - return $v->compile($js,$view); |
|
50 | + if ($v instanceof BaseHtml) { |
|
51 | + return $v->compile($js, $view); |
|
52 | 52 | } |
53 | 53 | if (\is_array($v)) { |
54 | - return self::wrap($v, $js, $view,$separator, $valueQuote); |
|
54 | + return self::wrap($v, $js, $view, $separator, $valueQuote); |
|
55 | 55 | } |
56 | - if(!\is_callable($v)){ |
|
56 | + if (!\is_callable($v)) { |
|
57 | 57 | return $v; |
58 | 58 | } |
59 | 59 | }, $input)); |
60 | 60 | } |
61 | 61 | |
62 | - protected static function wrapValue($value,$js=NULL, $separator=' ', $valueQuote='"'){ |
|
62 | + protected static function wrapValue($value, $js=NULL, $separator=' ', $valueQuote='"') { |
|
63 | 63 | if (\is_array($value)) { |
64 | 64 | return self::wrap($value, $js, $separator, $valueQuote); |
65 | 65 | } |
66 | - if ($value instanceof BaseHtml){ |
|
66 | + if ($value instanceof BaseHtml) { |
|
67 | 67 | return $value->compile($js); |
68 | 68 | } |
69 | - if(!\is_callable($value)){ |
|
69 | + if (!\is_callable($value)) { |
|
70 | 70 | return $value; |
71 | 71 | } |
72 | 72 | return ''; |
@@ -14,44 +14,44 @@ discard block |
||
14 | 14 | */ |
15 | 15 | abstract class HtmlCollection extends HtmlDoubleElement { |
16 | 16 | |
17 | - public function __construct($identifier,$tagName="div"){ |
|
18 | - parent::__construct($identifier,$tagName); |
|
17 | + public function __construct($identifier, $tagName="div") { |
|
18 | + parent::__construct($identifier, $tagName); |
|
19 | 19 | $this->content=array(); |
20 | 20 | } |
21 | 21 | |
22 | - public function addItems($items){ |
|
23 | - if(JArray::isAssociative($items)){ |
|
24 | - foreach ($items as $k=>$v){ |
|
25 | - $this->addItem([$k,$v]); |
|
22 | + public function addItems($items) { |
|
23 | + if (JArray::isAssociative($items)) { |
|
24 | + foreach ($items as $k=>$v) { |
|
25 | + $this->addItem([$k, $v]); |
|
26 | 26 | } |
27 | - }else{ |
|
28 | - foreach ($items as $item){ |
|
27 | + } else { |
|
28 | + foreach ($items as $item) { |
|
29 | 29 | $this->addItem($item); |
30 | 30 | } |
31 | 31 | } |
32 | 32 | return $this; |
33 | 33 | } |
34 | 34 | |
35 | - public function setItems($items){ |
|
35 | + public function setItems($items) { |
|
36 | 36 | $this->content=$items; |
37 | 37 | return $this; |
38 | 38 | } |
39 | 39 | |
40 | - public function getItems(){ |
|
40 | + public function getItems() { |
|
41 | 41 | return $this->content; |
42 | 42 | } |
43 | 43 | |
44 | - protected function getItemToAdd($item){ |
|
44 | + protected function getItemToAdd($item) { |
|
45 | 45 | $itemO=$item; |
46 | - if($this->createCondition($item)===true){ |
|
46 | + if ($this->createCondition($item)===true) { |
|
47 | 47 | $itemO=$this->createItem($item); |
48 | 48 | } |
49 | 49 | return $itemO; |
50 | 50 | } |
51 | 51 | |
52 | - protected function setItemIdentifier($item,$classname,$index){ |
|
53 | - if($item instanceof BaseWidget){ |
|
54 | - if(JString::isNull($item->getIdentifier())){ |
|
52 | + protected function setItemIdentifier($item, $classname, $index) { |
|
53 | + if ($item instanceof BaseWidget) { |
|
54 | + if (JString::isNull($item->getIdentifier())) { |
|
55 | 55 | $item->setIdentifier($classname."-".$this->identifier."-".$index); |
56 | 56 | } |
57 | 57 | } |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | * @param HtmlDoubleElement|string|array $item |
63 | 63 | * @return \Ajax\common\html\HtmlDoubleElement |
64 | 64 | */ |
65 | - public function addItem($item){ |
|
65 | + public function addItem($item) { |
|
66 | 66 | $itemO=$this->getItemToAdd($item); |
67 | 67 | $this->addContent($itemO); |
68 | 68 | return $itemO; |
69 | 69 | } |
70 | 70 | |
71 | - public function insertItem($item,$position=0){ |
|
71 | + public function insertItem($item, $position=0) { |
|
72 | 72 | $itemO=$this->getItemToAdd($item); |
73 | - \array_splice( $this->content, $position, 0, array($itemO)); |
|
73 | + \array_splice($this->content, $position, 0, array($itemO)); |
|
74 | 74 | return $itemO; |
75 | 75 | } |
76 | 76 | |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | return $this; |
94 | 94 | } |
95 | 95 | |
96 | - public function removeItem($index){ |
|
96 | + public function removeItem($index) { |
|
97 | 97 | return array_splice($this->content, $index, 1); |
98 | 98 | } |
99 | 99 | |
100 | - public function count(){ |
|
100 | + public function count() { |
|
101 | 101 | return \sizeof($this->content); |
102 | 102 | } |
103 | 103 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | return $this->addItem($function($object)); |
109 | 109 | } |
110 | 110 | |
111 | - public function apply($callBack){ |
|
112 | - foreach ($this->content as $item){ |
|
111 | + public function apply($callBack) { |
|
112 | + foreach ($this->content as $item) { |
|
113 | 113 | $callBack($item); |
114 | 114 | } |
115 | 115 | return $this; |
@@ -129,23 +129,23 @@ discard block |
||
129 | 129 | */ |
130 | 130 | abstract protected function createItem($value); |
131 | 131 | |
132 | - protected function createCondition($value){ |
|
132 | + protected function createCondition($value) { |
|
133 | 133 | return \is_object($value)===false; |
134 | 134 | } |
135 | 135 | |
136 | - protected function contentAs($tagName){ |
|
137 | - foreach ($this->content as $item){ |
|
136 | + protected function contentAs($tagName) { |
|
137 | + foreach ($this->content as $item) { |
|
138 | 138 | $item->setTagName($tagName); |
139 | 139 | } |
140 | 140 | return $this; |
141 | 141 | } |
142 | 142 | |
143 | - public function setProperties($properties){ |
|
143 | + public function setProperties($properties) { |
|
144 | 144 | $i=0; |
145 | - foreach ($properties as $k=>$v){ |
|
145 | + foreach ($properties as $k=>$v) { |
|
146 | 146 | $c=$this->content[$i++]; |
147 | - if(isset($c)) |
|
148 | - $c->setProperty($k,$v); |
|
147 | + if (isset($c)) |
|
148 | + $c->setProperty($k, $v); |
|
149 | 149 | else |
150 | 150 | return $this; |
151 | 151 | } |
@@ -158,15 +158,15 @@ discard block |
||
158 | 158 | * @param array|mixed $values |
159 | 159 | * @return $this |
160 | 160 | */ |
161 | - public function setPropertyValues($property,$values){ |
|
162 | - if(\is_array($values)===false){ |
|
163 | - $values=\array_fill(0, $this->count(),$values); |
|
161 | + public function setPropertyValues($property, $values) { |
|
162 | + if (\is_array($values)===false) { |
|
163 | + $values=\array_fill(0, $this->count(), $values); |
|
164 | 164 | } |
165 | - foreach ($values as $i=>$value){ |
|
166 | - if(isset($this->content[$i])){ |
|
167 | - $this->content[$i]->setProperty($property,$value); |
|
165 | + foreach ($values as $i=>$value) { |
|
166 | + if (isset($this->content[$i])) { |
|
167 | + $this->content[$i]->setProperty($property, $value); |
|
168 | 168 | } |
169 | - else{ |
|
169 | + else { |
|
170 | 170 | return $this; |
171 | 171 | } |
172 | 172 | } |
@@ -179,15 +179,15 @@ discard block |
||
179 | 179 | * @param array|mixed $values |
180 | 180 | * @return $this |
181 | 181 | */ |
182 | - public function addPropertyValues($property,$values){ |
|
183 | - if(\is_array($values)===false){ |
|
184 | - $values=\array_fill(0, $this->count(),$values); |
|
182 | + public function addPropertyValues($property, $values) { |
|
183 | + if (\is_array($values)===false) { |
|
184 | + $values=\array_fill(0, $this->count(), $values); |
|
185 | 185 | } |
186 | - foreach ($values as $i=>$value){ |
|
187 | - if(isset($this->content[$i])){ |
|
188 | - $this->content[$i++]->addToProperty($property,$value); |
|
186 | + foreach ($values as $i=>$value) { |
|
187 | + if (isset($this->content[$i])) { |
|
188 | + $this->content[$i++]->addToProperty($property, $value); |
|
189 | 189 | } |
190 | - else{ |
|
190 | + else { |
|
191 | 191 | return $this; |
192 | 192 | } |
193 | 193 | } |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
198 | 198 | $index=0; |
199 | 199 | $classname=\strtolower(JReflection::shortClassName($this)); |
200 | - foreach ($this->content as $item){ |
|
201 | - $this->setItemIdentifier($item,$classname,$index++); |
|
200 | + foreach ($this->content as $item) { |
|
201 | + $this->setItemIdentifier($item, $classname, $index++); |
|
202 | 202 | } |
203 | - return parent::compile($js,$view); |
|
203 | + return parent::compile($js, $view); |
|
204 | 204 | } |
205 | 205 | |
206 | - public function getItemById($identifier){ |
|
206 | + public function getItemById($identifier) { |
|
207 | 207 | return $this->getElementById($identifier, $this->content); |
208 | 208 | } |
209 | 209 | |
@@ -212,13 +212,13 @@ discard block |
||
212 | 212 | * @param string $target |
213 | 213 | * @return HtmlCollection |
214 | 214 | */ |
215 | - public function asLinks($hrefs=[],$target=NUll) { |
|
216 | - foreach ( $this->content as $index=>$item ) { |
|
217 | - if($item instanceof HtmlDoubleElement){ |
|
215 | + public function asLinks($hrefs=[], $target=NUll) { |
|
216 | + foreach ($this->content as $index=>$item) { |
|
217 | + if ($item instanceof HtmlDoubleElement) { |
|
218 | 218 | $href=""; |
219 | - if(isset($hrefs[$index])) |
|
219 | + if (isset($hrefs[$index])) |
|
220 | 220 | $href=$hrefs[$index]; |
221 | - $item->asLink($href,$target); |
|
221 | + $item->asLink($href, $target); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | return $this; |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @param int $length If length is omitted, removes everything from offset to the end of the array. If length is specified and is positive, then that many elements will be removed. If length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. If length is specified and is zero, no elements will be removed. Tip: to remove everything from offset to the end of the array when replacement is also specified, use count($input) for length. |
231 | 231 | * @return $this |
232 | 232 | */ |
233 | - public function splice($offset,$length=null){ |
|
234 | - $this->content=array_slice($this->content, $offset,$length); |
|
233 | + public function splice($offset, $length=null) { |
|
234 | + $this->content=array_slice($this->content, $offset, $length); |
|
235 | 235 | return $this; |
236 | 236 | } |
237 | 237 | } |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * @property string identifier |
12 | 12 | * @property BaseHtml _self |
13 | 13 | */ |
14 | -trait BaseHtmlEventsTrait{ |
|
14 | +trait BaseHtmlEventsTrait { |
|
15 | 15 | |
16 | - protected $_events=array (); |
|
16 | + protected $_events=array(); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param string $event |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | * @return BaseHtml |
24 | 24 | */ |
25 | 25 | public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
26 | - if ($stopPropagation === true) { |
|
27 | - $jsCode=Javascript::$stopPropagation . $jsCode; |
|
26 | + if ($stopPropagation===true) { |
|
27 | + $jsCode=Javascript::$stopPropagation.$jsCode; |
|
28 | 28 | } |
29 | - if ($preventDefault === true) { |
|
30 | - $jsCode=Javascript::$preventDefault . $jsCode; |
|
29 | + if ($preventDefault===true) { |
|
30 | + $jsCode=Javascript::$preventDefault.$jsCode; |
|
31 | 31 | } |
32 | 32 | return $this->_addEvent($event, $jsCode); |
33 | 33 | } |
34 | 34 | |
35 | - public function trigger($event,$params="[]"){ |
|
35 | + public function trigger($event, $params="[]") { |
|
36 | 36 | $this->executeOnRun('$("#'.$this->identifier.'").trigger("'.$event.'",'.$params.');'); |
37 | 37 | } |
38 | 38 | |
39 | - public function jsTrigger($event,$params="[this]"){ |
|
40 | - return $this->jsDoJquery("trigger",["'".$event."'",$params]); |
|
39 | + public function jsTrigger($event, $params="[this]") { |
|
40 | + return $this->jsDoJquery("trigger", ["'".$event."'", $params]); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | public function _addEvent($event, $jsCode) { |
49 | 49 | if (array_key_exists($event, $this->_events)) { |
50 | 50 | if (\is_array($this->_events[$event])) { |
51 | - if(array_search($jsCode, $this->_events[$event])===false){ |
|
51 | + if (array_search($jsCode, $this->_events[$event])===false) { |
|
52 | 52 | $this->_events[$event][]=$jsCode; |
53 | 53 | } |
54 | 54 | } else { |
55 | - $this->_events[$event]=array ($this->_events[$event],$jsCode ); |
|
55 | + $this->_events[$event]=array($this->_events[$event], $jsCode); |
|
56 | 56 | } |
57 | 57 | } else { |
58 | 58 | $this->_events[$event]=$jsCode; |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | return $this->onClick($jsCode); |
80 | 80 | } |
81 | 81 | |
82 | - public function onCreate($jsCode){ |
|
83 | - if(isset($this->_events["_create"])){ |
|
82 | + public function onCreate($jsCode) { |
|
83 | + if (isset($this->_events["_create"])) { |
|
84 | 84 | $this->_events["_create"][]=$jsCode; |
85 | - }else{ |
|
85 | + } else { |
|
86 | 86 | $this->_events["_create"]=[$jsCode]; |
87 | 87 | } |
88 | 88 | return $this; |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | public function addEventsOnRun(JsUtils $js=NULL) { |
92 | 92 | $this->_eventsOnCreate($js); |
93 | 93 | if (isset($this->_bsComponent)) { |
94 | - foreach ( $this->_events as $event => $jsCode ) { |
|
94 | + foreach ($this->_events as $event => $jsCode) { |
|
95 | 95 | $code=$jsCode; |
96 | 96 | if (\is_array($jsCode)) { |
97 | 97 | $code=""; |
98 | - foreach ( $jsCode as $jsC ) { |
|
98 | + foreach ($jsCode as $jsC) { |
|
99 | 99 | if ($jsC instanceof AjaxCall) { |
100 | - $code.="\n" . $jsC->compile($js); |
|
100 | + $code.="\n".$jsC->compile($js); |
|
101 | 101 | } else { |
102 | - $code.="\n" . $jsC; |
|
102 | + $code.="\n".$jsC; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | } elseif ($jsCode instanceof AjaxCall) { |
@@ -107,20 +107,20 @@ discard block |
||
107 | 107 | } |
108 | 108 | $this->_bsComponent->addEvent($event, $code); |
109 | 109 | } |
110 | - $this->_events=array (); |
|
110 | + $this->_events=array(); |
|
111 | 111 | return $this->_bsComponent->getScript(); |
112 | 112 | } |
113 | 113 | return ""; |
114 | 114 | } |
115 | 115 | |
116 | - protected function _eventsOnCreate(JsUtils $js=NULL){ |
|
117 | - if(isset($this->_events["_create"])){ |
|
116 | + protected function _eventsOnCreate(JsUtils $js=NULL) { |
|
117 | + if (isset($this->_events["_create"])) { |
|
118 | 118 | $create=$this->_events["_create"]; |
119 | - if(\is_array($create)){ |
|
119 | + if (\is_array($create)) { |
|
120 | 120 | $create=\implode("", $create); |
121 | 121 | } |
122 | - if(isset($js) && $create!=="") |
|
123 | - $js->exec($create,true); |
|
122 | + if (isset($js) && $create!=="") |
|
123 | + $js->exec($create, true); |
|
124 | 124 | unset($this->_events["_create"]); |
125 | 125 | } |
126 | 126 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @return $this |
135 | 135 | */ |
136 | 136 | public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) { |
137 | - $params=array ("url" => $url,"responseElement" => $responseElement ); |
|
137 | + $params=array("url" => $url, "responseElement" => $responseElement); |
|
138 | 138 | $params=array_merge($params, $parameters); |
139 | 139 | $this->_addEvent($event, new AjaxCall($operation, $params)); |
140 | 140 | return $this; |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | **/ |
178 | 178 | public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) { |
179 | 179 | $allParameters=[]; |
180 | - if(isset($parameters["params"])){ |
|
180 | + if (isset($parameters["params"])) { |
|
181 | 181 | $allParameters[]=JsUtils::_correctParams($parameters["params"]); |
182 | 182 | } |
183 | - if(isset($params)){ |
|
183 | + if (isset($params)) { |
|
184 | 184 | $allParameters[]=JsUtils::_correctParams($params); |
185 | 185 | } |
186 | 186 | $parameters["params"]=\implode("+'&'+", $allParameters); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | public function jsDoJquery($jqueryCall, $param="") { |
230 | - return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . Javascript::prep_value($param) . ");"; |
|
230 | + return "$('#".$this->identifier."').".$jqueryCall."(".Javascript::prep_value($param).");"; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | public function executeOnRun($jsCode) { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | } |
248 | 248 | |
249 | 249 | public function jsToggle($value) { |
250 | - return $this->jsDoJquery("toggle",$value); |
|
250 | + return $this->jsDoJquery("toggle", $value); |
|
251 | 251 | } |
252 | 252 | /** |
253 | 253 | * @return array |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
18 | 18 | |
19 | 19 | abstract public function getUrl($url); |
20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
21 | 21 | |
22 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
23 | - if(isset($this->params["ajax"])){ |
|
22 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
23 | + if (isset($this->params["ajax"])) { |
|
24 | 24 | extract($this->params["ajax"]); |
25 | 25 | } |
26 | 26 | extract($parameters); |
@@ -30,109 +30,109 @@ discard block |
||
30 | 30 | $originalSelector=$responseElement; |
31 | 31 | $responseElement=$this->_getResponseElement($responseElement); |
32 | 32 | $retour.="var self=this;\n"; |
33 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
34 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
35 | - }elseif($hasLoader==="internal"){ |
|
33 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
34 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
35 | + }elseif ($hasLoader==="internal") { |
|
36 | 36 | $retour.="\n$(this).addClass('loading');"; |
37 | 37 | } |
38 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
38 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
39 | 39 | |
40 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
40 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
41 | 41 | |
42 | - if(isset($params)){ |
|
42 | + if (isset($params)) { |
|
43 | 43 | $ajaxParameters["data"]=self::_correctParams($params); |
44 | 44 | } |
45 | - if(isset($headers)){ |
|
45 | + if (isset($headers)) { |
|
46 | 46 | $ajaxParameters["headers"]=$headers; |
47 | 47 | } |
48 | 48 | $this->createAjaxParameters($ajaxParameters, $parameters); |
49 | 49 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
51 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
51 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
52 | 52 | if ($immediatly) |
53 | 53 | $this->jquery_code_for_compile[]=$retour; |
54 | 54 | return $retour; |
55 | 55 | } |
56 | 56 | |
57 | - protected function createAjaxParameters(&$original,$parameters){ |
|
58 | - $validParameters=["dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
59 | - foreach ($validParameters as $param=>$mask){ |
|
60 | - if(isset($parameters[$param])){ |
|
57 | + protected function createAjaxParameters(&$original, $parameters) { |
|
58 | + $validParameters=["dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
59 | + foreach ($validParameters as $param=>$mask) { |
|
60 | + if (isset($parameters[$param])) { |
|
61 | 61 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
67 | - $s = ''; foreach ($ajaxParameters as $k=>$v) { if ($s !== '') { $s .= ','; } $s .= "'{$k}':{$v}"; } |
|
66 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
67 | + $s=''; foreach ($ajaxParameters as $k=>$v) { if ($s!=='') { $s.=','; } $s.="'{$k}':{$v}"; } |
|
68 | 68 | return $s; |
69 | 69 | } |
70 | 70 | |
71 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
72 | - if(isset($jsCondition)){ |
|
71 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
72 | + if (isset($jsCondition)) { |
|
73 | 73 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
74 | 74 | } |
75 | 75 | return $jsSource; |
76 | 76 | } |
77 | 77 | |
78 | 78 | |
79 | - protected function _getAjaxUrl($url,$attr){ |
|
79 | + protected function _getAjaxUrl($url, $attr) { |
|
80 | 80 | $url=$this->_correctAjaxUrl($url); |
81 | 81 | $retour="url='".$url."';"; |
82 | 82 | $slash="/"; |
83 | - if(JString::endswith($url, "/")===true){ |
|
83 | + if (JString::endswith($url, "/")===true) { |
|
84 | 84 | $slash=""; |
85 | 85 | } |
86 | - if(JString::isNotNull($attr)){ |
|
87 | - if ($attr==="value"){ |
|
86 | + if (JString::isNotNull($attr)) { |
|
87 | + if ($attr==="value") { |
|
88 | 88 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
89 | - }elseif ($attr==="html"){ |
|
89 | + }elseif ($attr==="html") { |
|
90 | 90 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
91 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
91 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
92 | 92 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
93 | - }elseif($attr!==null && $attr!=="") |
|
93 | + }elseif ($attr!==null && $attr!=="") |
|
94 | 94 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
95 | 95 | } |
96 | 96 | return $retour; |
97 | 97 | } |
98 | 98 | |
99 | - protected function onPopstate(){ |
|
99 | + protected function onPopstate() { |
|
100 | 100 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
101 | 101 | } |
102 | 102 | |
103 | - protected function autoActiveLinks($previousURL="window.location.href"){ |
|
104 | - $result= "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
103 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
104 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
105 | 105 | $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
106 | 106 | return $result; |
107 | 107 | } |
108 | 108 | |
109 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
110 | - $retour="";$call=null; |
|
109 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
110 | + $retour=""; $call=null; |
|
111 | 111 | if (JString::isNotNull($responseElement)) { |
112 | - if(isset($ajaxTransition)){ |
|
112 | + if (isset($ajaxTransition)) { |
|
113 | 113 | $call=$this->setAjaxDataCall($ajaxTransition); |
114 | - }elseif(isset($this->ajaxTransition)){ |
|
114 | + }elseif (isset($this->ajaxTransition)) { |
|
115 | 115 | $call=$this->ajaxTransition; |
116 | 116 | } |
117 | - if(\is_callable($call)) |
|
118 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
117 | + if (\is_callable($call)) |
|
118 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
119 | 119 | else |
120 | 120 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
121 | 121 | } |
122 | - if(isset($history)){ |
|
123 | - if($this->params["autoActiveLinks"]){ |
|
122 | + if (isset($history)) { |
|
123 | + if ($this->params["autoActiveLinks"]) { |
|
124 | 124 | $retour.=$this->autoActiveLinks("url"); |
125 | 125 | } |
126 | 126 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
127 | 127 | } |
128 | - if($hasLoader==="internal"){ |
|
128 | + if ($hasLoader==="internal") { |
|
129 | 129 | $retour.="\n$(self).removeClass('loading');"; |
130 | 130 | } |
131 | 131 | $retour.="\t".$jsCallback."\n"; |
132 | 132 | return $retour; |
133 | 133 | } |
134 | 134 | |
135 | - protected function _getResponseElement($responseElement){ |
|
135 | + protected function _getResponseElement($responseElement) { |
|
136 | 136 | if (JString::isNotNull($responseElement)) { |
137 | 137 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
138 | 138 | } |
@@ -142,33 +142,33 @@ discard block |
||
142 | 142 | protected function _correctAjaxUrl($url) { |
143 | 143 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
144 | 144 | $url=substr($url, 0, strlen($url)-1); |
145 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
145 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
146 | 146 | $url=$this->getUrl($url); |
147 | 147 | } |
148 | 148 | return $url; |
149 | 149 | } |
150 | 150 | |
151 | - public static function _correctParams($params){ |
|
152 | - if(JString::isNull($params)){ |
|
151 | + public static function _correctParams($params) { |
|
152 | + if (JString::isNull($params)) { |
|
153 | 153 | return ""; |
154 | 154 | } |
155 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
155 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
156 | 156 | return '$.param('.$params.')'; |
157 | 157 | } |
158 | 158 | return $params; |
159 | 159 | } |
160 | 160 | |
161 | - public static function _implodeParams($parameters){ |
|
161 | + public static function _implodeParams($parameters) { |
|
162 | 162 | $allParameters=[]; |
163 | - foreach ($parameters as $params){ |
|
164 | - if(isset($params)) |
|
163 | + foreach ($parameters as $params) { |
|
164 | + if (isset($params)) |
|
165 | 165 | $allParameters[]=self::_correctParams($params); |
166 | 166 | } |
167 | 167 | return \implode("+'&'+", $allParameters); |
168 | 168 | } |
169 | 169 | |
170 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
171 | - if(!isset($ajaxLoader)){ |
|
170 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
171 | + if (!isset($ajaxLoader)) { |
|
172 | 172 | $ajaxLoader=$this->ajaxLoader; |
173 | 173 | } |
174 | 174 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -176,19 +176,19 @@ discard block |
||
176 | 176 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
177 | 177 | } |
178 | 178 | |
179 | - protected function setAjaxDataCall($params){ |
|
179 | + protected function setAjaxDataCall($params) { |
|
180 | 180 | $result=null; |
181 | - if(!\is_callable($params)){ |
|
182 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
183 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
181 | + if (!\is_callable($params)) { |
|
182 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
183 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
184 | 184 | }; |
185 | 185 | } |
186 | 186 | return $result; |
187 | 187 | } |
188 | 188 | |
189 | - protected function setDefaultParameters(&$parameters,$default){ |
|
190 | - foreach ($default as $k=>$v){ |
|
191 | - if(!isset($parameters[$k])) |
|
189 | + protected function setDefaultParameters(&$parameters, $default) { |
|
190 | + foreach ($default as $k=>$v) { |
|
191 | + if (!isset($parameters[$k])) |
|
192 | 192 | $parameters[$k]=$v; |
193 | 193 | } |
194 | 194 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | * @param string $url The url of the request |
203 | 203 | * @param string $responseElement selector of the HTML element displaying the answer |
204 | 204 | */ |
205 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
206 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
205 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
206 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | * @param string $responseElement selector of the HTML element displaying the answer |
213 | 213 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
214 | 214 | */ |
215 | - public function get($url, $responseElement="",$parameters=[]) { |
|
215 | + public function get($url, $responseElement="", $parameters=[]) { |
|
216 | 216 | $parameters["immediatly"]=true; |
217 | - return $this->_get($url,$responseElement,$parameters); |
|
217 | + return $this->_get($url, $responseElement, $parameters); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | * @param string $responseElement selector of the HTML element displaying the answer |
225 | 225 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
226 | 226 | */ |
227 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
227 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
228 | 228 | $parameters["immediatly"]=true; |
229 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
229 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * @param string $responseElement selector of the HTML element displaying the answer |
237 | 237 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
238 | 238 | */ |
239 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
239 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
240 | 240 | $parameters["immediatly"]=false; |
241 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
241 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * @param string $method Method used |
248 | 248 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
249 | 249 | */ |
250 | - private function _json($url, $method="get",$parameters=[]) { |
|
251 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
250 | + private function _json($url, $method="get", $parameters=[]) { |
|
251 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
252 | 252 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
253 | 253 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
254 | 254 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";" |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
257 | 257 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
258 | 258 | $parameters["jsCallback"]=$retour; |
259 | - return $this->_ajax($method, $url,null,$parameters); |
|
259 | + return $this->_ajax($method, $url, null, $parameters); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
267 | 267 | */ |
268 | 268 | public function json($url, $method="get", $parameters=[]) { |
269 | - return $this->_json($url,$method,$parameters); |
|
269 | + return $this->_json($url, $method, $parameters); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | * @param string $method default get |
278 | 278 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
279 | 279 | */ |
280 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
281 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
282 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
280 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
281 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
282 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
292 | 292 | $parameters["immediatly"]=false; |
293 | - return $this->_json($url,$method,$parameters); |
|
293 | + return $this->_json($url, $method, $parameters); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -301,27 +301,27 @@ discard block |
||
301 | 301 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
302 | 302 | */ |
303 | 303 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
304 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
304 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
305 | 305 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
306 | 306 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
307 | 307 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
308 | - if($context===null){ |
|
308 | + if ($context===null) { |
|
309 | 309 | $parent="$('".$maskSelector."').parent()"; |
310 | - $newElm = "$('#'+newId)"; |
|
311 | - }else{ |
|
310 | + $newElm="$('#'+newId)"; |
|
311 | + } else { |
|
312 | 312 | $parent=$context; |
313 | - $newElm = $context.".find('#'+newId)"; |
|
313 | + $newElm=$context.".find('#'+newId)"; |
|
314 | 314 | } |
315 | 315 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
316 | 316 | $retour=$parent.".find('.{$rowClass}').remove();"; |
317 | 317 | $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
318 | 318 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
319 | - $retour.= $appendTo; |
|
319 | + $retour.=$appendTo; |
|
320 | 320 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
321 | 321 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
322 | 322 | $retour.="\t".$jsCallback; |
323 | 323 | $parameters["jsCallback"]=$retour; |
324 | - return $this->_ajax($method, $url,null,$parameters); |
|
324 | + return $this->_ajax($method, $url, null, $parameters); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
333 | 333 | */ |
334 | 334 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
335 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
335 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | * @param string $method Method used, default : get |
356 | 356 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
357 | 357 | */ |
358 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
359 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
360 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
358 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
359 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
360 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | */ |
370 | 370 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
371 | 371 | $parameters["immediatly"]=false; |
372 | - return $this->_get($url, $responseElement,$parameters); |
|
372 | + return $this->_get($url, $responseElement, $parameters); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
383 | 383 | */ |
384 | 384 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
385 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
386 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
385 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
386 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -396,8 +396,8 @@ discard block |
||
396 | 396 | * @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
397 | 397 | */ |
398 | 398 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
399 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
400 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
399 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
400 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -431,15 +431,15 @@ discard block |
||
431 | 431 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true) |
432 | 432 | * @return $this |
433 | 433 | */ |
434 | - public function getHref($element,$responseElement="",$parameters=array()){ |
|
434 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
435 | 435 | $parameters["attr"]="href"; |
436 | - if(JString::isNull($responseElement)){ |
|
436 | + if (JString::isNull($responseElement)) { |
|
437 | 437 | $responseElement='%$(self).attr("data-target")%'; |
438 | 438 | } |
439 | - if(!isset($parameters["historize"])){ |
|
439 | + if (!isset($parameters["historize"])) { |
|
440 | 440 | $parameters["historize"]=true; |
441 | 441 | } |
442 | - return $this->getOnClick($element, "",$responseElement,$parameters); |
|
442 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,20 +449,20 @@ discard block |
||
449 | 449 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
450 | 450 | * @return $this |
451 | 451 | */ |
452 | - public function postHref($element,$responseElement="",$parameters=array()){ |
|
452 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
453 | 453 | $parameters["attr"]="href"; |
454 | - if(JString::isNull($responseElement)){ |
|
454 | + if (JString::isNull($responseElement)) { |
|
455 | 455 | $responseElement='%$(this).attr("data-target")%'; |
456 | 456 | } |
457 | - if(!isset($parameters["historize"])){ |
|
457 | + if (!isset($parameters["historize"])) { |
|
458 | 458 | $parameters["historize"]=true; |
459 | 459 | } |
460 | - return $this->postOnClick($element, "","{}",$responseElement,$parameters); |
|
460 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
461 | 461 | } |
462 | 462 | |
463 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
463 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
464 | 464 | $parameters["params"]=$params; |
465 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
465 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * @param string $params JSON parameters |
473 | 473 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
474 | 474 | */ |
475 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
476 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
475 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
476 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | * @param string $responseElement selector of the HTML element displaying the answer |
485 | 485 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
486 | 486 | */ |
487 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
487 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
488 | 488 | $parameters["immediatly"]=false; |
489 | 489 | return $this->_post($url, $params, $responseElement, $parameters); |
490 | 490 | } |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
501 | 501 | */ |
502 | 502 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
503 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
504 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
503 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
504 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -518,33 +518,33 @@ discard block |
||
518 | 518 | } |
519 | 519 | |
520 | 520 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
521 | - if(isset($this->params["ajax"])){ |
|
521 | + if (isset($this->params["ajax"])) { |
|
522 | 522 | extract($this->params["ajax"]); |
523 | 523 | } |
524 | - $params="{}";$validation=false; |
|
524 | + $params="{}"; $validation=false; |
|
525 | 525 | \extract($parameters); |
526 | - $async=($async)?"true":"false"; |
|
526 | + $async=($async) ? "true" : "false"; |
|
527 | 527 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
528 | 528 | $retour=$this->_getAjaxUrl($url, $attr); |
529 | 529 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
530 | 530 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
531 | - if(isset($params)){ |
|
531 | + if (isset($params)) { |
|
532 | 532 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
533 | 533 | } |
534 | 534 | $responseElement=$this->_getResponseElement($responseElement); |
535 | 535 | $retour.="var self=this;\n"; |
536 | - if($hasLoader===true){ |
|
537 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
538 | - }elseif($hasLoader==="internal"){ |
|
536 | + if ($hasLoader===true) { |
|
537 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
538 | + }elseif ($hasLoader==="internal") { |
|
539 | 539 | $retour.="\n$(this).addClass('loading');"; |
540 | 540 | } |
541 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
542 | - if(isset($headers)){ |
|
541 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
542 | + if (isset($headers)) { |
|
543 | 543 | $ajaxParameters["headers"]=$headers; |
544 | 544 | } |
545 | 545 | $this->createAjaxParameters($ajaxParameters, $parameters); |
546 | 546 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
547 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
547 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
548 | 548 | |
549 | 549 | if ($validation) { |
550 | 550 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -594,8 +594,8 @@ discard block |
||
594 | 594 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
595 | 595 | */ |
596 | 596 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
597 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
598 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
597 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
598 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | /** |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | trait JsUtilsActionsTrait { |
13 | 13 | |
14 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
14 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
15 | 15 | /** |
16 | 16 | * show or hide with effect |
17 | 17 | * |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @param boolean $immediatly defers the execution if set to false |
23 | 23 | * @return string |
24 | 24 | */ |
25 | - protected function _showHideWithEffect($action,$element='this', $speed='', $callback='', $immediatly=false) { |
|
25 | + protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) { |
|
26 | 26 | $element=Javascript::prep_element($element); |
27 | 27 | $speed=$this->_validate_speed($speed); |
28 | 28 | if ($callback!='') { |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | * @return string |
40 | 40 | */ |
41 | 41 | private function _validate_speed($speed) { |
42 | - if (in_array($speed, array ( |
|
43 | - 'slow','normal','fast' |
|
42 | + if (in_array($speed, array( |
|
43 | + 'slow', 'normal', 'fast' |
|
44 | 44 | ))) { |
45 | 45 | $speed='"'.$speed.'"'; |
46 | 46 | } elseif (preg_match("/[^0-9]/", $speed)) { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param string $param |
58 | 58 | * @param boolean $immediatly delayed if false |
59 | 59 | */ |
60 | - public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) { |
|
60 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
61 | 61 | $element=Javascript::prep_element($element); |
62 | 62 | if (isset($param)) { |
63 | 63 | $param=Javascript::prep_value($param); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param boolean $immediatly delayed if false |
78 | 78 | * @return string |
79 | 79 | */ |
80 | - public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) { |
|
80 | + public function _genericCallElement($jQueryCall, $to='this', $element, $immediatly=false) { |
|
81 | 81 | $to=Javascript::prep_element($to); |
82 | 82 | $element=Javascript::prep_element($element); |
83 | 83 | $str="$({$to}).{$jQueryCall}({$element});"; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return string |
95 | 95 | */ |
96 | 96 | public function addClass($element='this', $class='', $immediatly=false) { |
97 | - return $this->_genericCallValue('addClass',$element, $class, $immediatly); |
|
97 | + return $this->_genericCallValue('addClass', $element, $class, $immediatly); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @param boolean $immediatly defers the execution if set to false |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - public function after($to, $element, $immediatly=false){ |
|
108 | - return $this->_genericCallElement('after',$to, $element, $immediatly); |
|
107 | + public function after($to, $element, $immediatly=false) { |
|
108 | + return $this->_genericCallElement('after', $to, $element, $immediatly); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * @param boolean $immediatly defers the execution if set to false |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - public function before($to, $element, $immediatly=false){ |
|
119 | - return $this->_genericCallElement('before',$to, $element, $immediatly); |
|
118 | + public function before($to, $element, $immediatly=false) { |
|
119 | + return $this->_genericCallElement('before', $to, $element, $immediatly); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | * @param string $value |
145 | 145 | * @param boolean $immediatly defers the execution if set to false |
146 | 146 | */ |
147 | - public function val($element='this',$value='',$immediatly=false){ |
|
148 | - return $this->_genericCallValue('val',$element,$value,$immediatly); |
|
147 | + public function val($element='this', $value='', $immediatly=false) { |
|
148 | + return $this->_genericCallValue('val', $element, $value, $immediatly); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param boolean $immediatly defers the execution if set to false |
156 | 156 | */ |
157 | 157 | public function html($element='this', $value='', $immediatly=false) { |
158 | - return $this->_genericCallValue('html',$element, $value, $immediatly); |
|
158 | + return $this->_genericCallValue('html', $element, $value, $immediatly); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | $animations="\t\t\t"; |
176 | 176 | if (\is_array($params)) { |
177 | - foreach ( $params as $param => $value ) { |
|
177 | + foreach ($params as $param => $value) { |
|
178 | 178 | $animations.=$param.': \''.$value.'\', '; |
179 | 179 | } |
180 | 180 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function append($to, $element, $immediatly=false) { |
206 | - return $this->_genericCallElement('append',$to, $element, $immediatly); |
|
206 | + return $this->_genericCallElement('append', $to, $element, $immediatly); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @return string |
215 | 215 | */ |
216 | 216 | public function prepend($to, $element, $immediatly=false) { |
217 | - return $this->_genericCallElement('prepend',$to, $element, $immediatly); |
|
217 | + return $this->_genericCallElement('prepend', $to, $element, $immediatly); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @return string |
228 | 228 | */ |
229 | 229 | public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
230 | - return $this->_showHideWithEffect("fadeIn",$element,$speed,$callback,$immediatly); |
|
230 | + return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @return string |
241 | 241 | */ |
242 | 242 | public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
243 | - return $this->_showHideWithEffect("fadeOut",$element,$speed,$callback,$immediatly); |
|
243 | + return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return string |
254 | 254 | */ |
255 | 255 | public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
256 | - return $this->_showHideWithEffect("slideUp",$element,$speed,$callback,$immediatly); |
|
256 | + return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @return string |
266 | 266 | */ |
267 | 267 | public function removeClass($element='this', $class='', $immediatly=false) { |
268 | - return $this->_genericCallValue('removeClass',$element, $class, $immediatly); |
|
268 | + return $this->_genericCallValue('removeClass', $element, $class, $immediatly); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return string |
279 | 279 | */ |
280 | 280 | public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
281 | - return $this->_showHideWithEffect("slideDown",$element,$speed,$callback,$immediatly); |
|
281 | + return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return string |
292 | 292 | */ |
293 | 293 | public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
294 | - return $this->_showHideWithEffect("slideToggle",$element,$speed,$callback,$immediatly); |
|
294 | + return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * @return string |
305 | 305 | */ |
306 | 306 | public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
307 | - return $this->_showHideWithEffect("hide",$element,$speed,$callback,$immediatly); |
|
307 | + return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @return string |
318 | 318 | */ |
319 | 319 | public function toggle($element='this', $speed='', $callback='', $immediatly=false) { |
320 | - return $this->_showHideWithEffect("toggle",$element,$speed,$callback,$immediatly); |
|
320 | + return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @return string |
330 | 330 | */ |
331 | 331 | public function toggleClass($element='this', $class='', $immediatly=false) { |
332 | - return $this->_genericCallValue('toggleClass',$element, $class, $immediatly); |
|
332 | + return $this->_genericCallValue('toggleClass', $element, $class, $immediatly); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @return string |
358 | 358 | */ |
359 | 359 | public function show($element='this', $speed='', $callback='', $immediatly=false) { |
360 | - return $this->_showHideWithEffect("show",$element,$speed,$callback,$immediatly); |
|
360 | + return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | */ |
370 | 370 | public function sortable($element, $options=array()) { |
371 | 371 | if (count($options)>0) { |
372 | - $sort_options=array (); |
|
373 | - foreach ( $options as $k => $v ) { |
|
372 | + $sort_options=array(); |
|
373 | + foreach ($options as $k => $v) { |
|
374 | 374 | $sort_options[]="\n\t\t".$k.': '.$v.""; |
375 | 375 | } |
376 | 376 | $sort_options=implode(",", $sort_options); |
@@ -467,8 +467,8 @@ discard block |
||
467 | 467 | * @param boolean $immediatly |
468 | 468 | * @return string |
469 | 469 | */ |
470 | - private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="",$immediatly=true) { |
|
471 | - return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation,$immediatly); |
|
470 | + private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
471 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | $preventDefault=false; |
487 | 487 | $immediatly=true; |
488 | 488 | extract($parameters); |
489 | - return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback,$immediatly); |
|
489 | + return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
@@ -527,11 +527,11 @@ discard block |
||
527 | 527 | $preventDefault=false; |
528 | 528 | $immediatly=true; |
529 | 529 | extract($parameters); |
530 | - $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation,$immediatly); |
|
530 | + $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
531 | 531 | return $script; |
532 | 532 | } |
533 | 533 | |
534 | - public function setJsonToElement($json,$elementClass="_element",$immediatly=true){ |
|
534 | + public function setJsonToElement($json, $elementClass="_element", $immediatly=true) { |
|
535 | 535 | $retour="var data={$json};" |
536 | 536 | ."\n\tdata=($.isPlainObject(data))?data:JSON.parse(data);" |
537 | 537 | ."\n\tvar pk=data['pk'];var object=data['object'];" |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | ."\n\t});" |
543 | 543 | ."\n}};\n"; |
544 | 544 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
545 | - return $this->exec($retour,$immediatly); |
|
545 | + return $this->exec($retour, $immediatly); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -550,10 +550,10 @@ discard block |
||
550 | 550 | * @param string $element The element selector |
551 | 551 | * @param array $parameters default : array("attr"=>"id","preventDefault"=>false,"stopPropagation"=>false,"immediatly"=>true) |
552 | 552 | */ |
553 | - public function setDraggable($element,$parameters=[]){ |
|
553 | + public function setDraggable($element, $parameters=[]) { |
|
554 | 554 | $attr="id"; |
555 | 555 | extract($parameters); |
556 | - $script=$this->_add_event($element, Javascript::draggable($attr), "dragstart",$parameters); |
|
556 | + $script=$this->_add_event($element, Javascript::draggable($attr), "dragstart", $parameters); |
|
557 | 557 | return $script; |
558 | 558 | } |
559 | 559 | |
@@ -563,13 +563,13 @@ discard block |
||
563 | 563 | * @param array $parameters default : array("attr"=>"id","stopPropagation"=>false,"immediatly"=>true,"jqueryDone"=>"append") |
564 | 564 | * @param string $jsCallback the js script to call when element is dropped |
565 | 565 | */ |
566 | - public function asDropZone($element,$jsCallback="",$parameters=[]){ |
|
566 | + public function asDropZone($element, $jsCallback="", $parameters=[]) { |
|
567 | 567 | $stopPropagation=false; |
568 | 568 | $immediatly=true; |
569 | 569 | $jqueryDone="append"; |
570 | - $script=$this->_add_event($element, '', "dragover",true,$stopPropagation,$immediatly); |
|
570 | + $script=$this->_add_event($element, '', "dragover", true, $stopPropagation, $immediatly); |
|
571 | 571 | extract($parameters); |
572 | - $script.=$this->_add_event($element, Javascript::dropZone($jqueryDone,$jsCallback), "drop",true,$stopPropagation,$immediatly); |
|
572 | + $script.=$this->_add_event($element, Javascript::dropZone($jqueryDone, $jsCallback), "drop", true, $stopPropagation, $immediatly); |
|
573 | 573 | return $script; |
574 | 574 | } |
575 | 575 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param string $event |
22 | 22 | * @param boolean $multiple |
23 | 23 | */ |
24 | - public function __construct($table,$class="active",$event="click",$multiple=false){ |
|
24 | + public function __construct($table, $class="active", $event="click", $multiple=false) { |
|
25 | 25 | $this->table=$table; |
26 | 26 | $this->class=$class; |
27 | 27 | $this->event=$event; |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | return $this; |
56 | 56 | } |
57 | 57 | |
58 | - public function run(){ |
|
58 | + public function run() { |
|
59 | 59 | $multiple=""; |
60 | - if(!$this->multiple){ |
|
60 | + if (!$this->multiple) { |
|
61 | 61 | $multiple="$(this).closest('tbody').children('tr').removeClass('".$this->class."');"; |
62 | 62 | } |
63 | - $this->table->onRow($this->event, $multiple."$(this).toggleClass('".$this->class."');".$this->table->jsTrigger("activeRowChange","[this]"),false,false); |
|
63 | + $this->table->onRow($this->event, $multiple."$(this).toggleClass('".$this->class."');".$this->table->jsTrigger("activeRowChange", "[this]"), false, false); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | } |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | |
32 | 32 | public function __construct($identifier, $rowCount, $colCount) { |
33 | 33 | parent::__construct($identifier, "table", "ui table"); |
34 | - $this->content=array (); |
|
34 | + $this->content=array(); |
|
35 | 35 | $this->setRowCount($rowCount, $colCount); |
36 | - $this->_variations=[ Variation::CELLED,Variation::PADDED,Variation::COMPACT ]; |
|
37 | - $this->_compileParts=["thead","tbody","tfoot"]; |
|
36 | + $this->_variations=[Variation::CELLED, Variation::PADDED, Variation::COMPACT]; |
|
37 | + $this->_compileParts=["thead", "tbody", "tfoot"]; |
|
38 | 38 | $this->_afterCompileEvents=[]; |
39 | 39 | } |
40 | 40 | |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | * @return HtmlTableContent |
45 | 45 | */ |
46 | 46 | public function getPart($key) { |
47 | - if (\array_key_exists($key, $this->content) === false) { |
|
47 | + if (\array_key_exists($key, $this->content)===false) { |
|
48 | 48 | $this->content[$key]=new HtmlTableContent("", $key); |
49 | - if ($key !== "tbody") { |
|
49 | + if ($key!=="tbody") { |
|
50 | 50 | $this->content[$key]->setRowCount(1, $this->_colCount); |
51 | 51 | } |
52 | 52 | } |
53 | 53 | return $this->content[$key]; |
54 | 54 | } |
55 | 55 | |
56 | - protected function _getFirstPart(){ |
|
57 | - if(isset($this->content["thead"])){ |
|
56 | + protected function _getFirstPart() { |
|
57 | + if (isset($this->content["thead"])) { |
|
58 | 58 | return $this->content["thead"]; |
59 | 59 | } |
60 | 60 | return $this->content["tbody"]; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return boolean |
100 | 100 | */ |
101 | 101 | public function hasPart($key) { |
102 | - return \array_key_exists($key, $this->content) === true; |
|
102 | + return \array_key_exists($key, $this->content)===true; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | return $this->colAlign($colIndex, "colLeft"); |
233 | 233 | } |
234 | 234 | |
235 | - public function setColAlignment($colIndex,$alignment){ |
|
236 | - switch ($alignment){ |
|
235 | + public function setColAlignment($colIndex, $alignment) { |
|
236 | + switch ($alignment) { |
|
237 | 237 | case TextAlignment::LEFT: |
238 | 238 | $function="colLeft"; |
239 | 239 | break; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | |
256 | 256 | private function colAlign($colIndex, $function) { |
257 | 257 | if (\is_array($colIndex)) { |
258 | - foreach ( $colIndex as $cIndex ) { |
|
258 | + foreach ($colIndex as $cIndex) { |
|
259 | 259 | $this->colAlign($cIndex, $function); |
260 | 260 | } |
261 | 261 | } else { |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @see HtmlSemDoubleElement::compile() |
317 | 317 | */ |
318 | 318 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
319 | - if(\sizeof($this->_compileParts)<3){ |
|
319 | + if (\sizeof($this->_compileParts)<3) { |
|
320 | 320 | $this->_template="%content%"; |
321 | 321 | $this->refresh($js); |
322 | 322 | } |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | } |
326 | 326 | |
327 | 327 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
328 | - parent::compile_once($js,$view); |
|
328 | + parent::compile_once($js, $view); |
|
329 | 329 | if ($this->propertyContains("class", "sortable")) { |
330 | - $this->addEvent("execute", "$('#" . $this->identifier . "').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
330 | + $this->addEvent("execute", "$('#".$this->identifier."').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
@@ -340,13 +340,13 @@ discard block |
||
340 | 340 | public function fromDatabaseObject($object, $function) { |
341 | 341 | $result=$function($object); |
342 | 342 | if (\is_array($result)) { |
343 | - $result= $this->addRow($function($object)); |
|
343 | + $result=$this->addRow($function($object)); |
|
344 | 344 | } else { |
345 | - $result= $this->getBody()->_addRow($result); |
|
345 | + $result=$this->getBody()->_addRow($result); |
|
346 | 346 | } |
347 | - if(isset($this->_afterCompileEvents["onNewRow"])){ |
|
348 | - if(\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
349 | - $this->_afterCompileEvents["onNewRow"]($result,$object); |
|
347 | + if (isset($this->_afterCompileEvents["onNewRow"])) { |
|
348 | + if (\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
349 | + $this->_afterCompileEvents["onNewRow"]($result, $object); |
|
350 | 350 | } |
351 | 351 | return $result; |
352 | 352 | } |
@@ -361,21 +361,21 @@ discard block |
||
361 | 361 | return $this; |
362 | 362 | } |
363 | 363 | |
364 | - public function refresh($js){ |
|
364 | + public function refresh($js) { |
|
365 | 365 | $this->_footer=$this->getFooter(); |
366 | - if(isset($js)){ |
|
367 | - $js->exec('$("#'.$this->identifier.' tfoot").replaceWith("'.\addslashes($this->_footer).'");',true); |
|
366 | + if (isset($js)) { |
|
367 | + $js->exec('$("#'.$this->identifier.' tfoot").replaceWith("'.\addslashes($this->_footer).'");', true); |
|
368 | 368 | } |
369 | 369 | } |
370 | 370 | |
371 | - public function run(JsUtils $js){ |
|
372 | - if(!$this->_runned){ |
|
373 | - if(isset($this->_activeRowSelector)){ |
|
371 | + public function run(JsUtils $js) { |
|
372 | + if (!$this->_runned) { |
|
373 | + if (isset($this->_activeRowSelector)) { |
|
374 | 374 | $this->_activeRowSelector->run(); |
375 | 375 | } |
376 | 376 | } |
377 | - $result= parent::run($js); |
|
378 | - if(isset($this->_footer)) |
|
377 | + $result=parent::run($js); |
|
378 | + if (isset($this->_footer)) |
|
379 | 379 | $this->_footer->run($js); |
380 | 380 | $this->_runned=true; |
381 | 381 | return $result; |
@@ -399,47 +399,47 @@ discard block |
||
399 | 399 | * @param boolean $multiple |
400 | 400 | * @return HtmlTable |
401 | 401 | */ |
402 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
403 | - $this->_activeRowSelector=new ActiveRow($this,$class,$event,$multiple); |
|
402 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
403 | + $this->_activeRowSelector=new ActiveRow($this, $class, $event, $multiple); |
|
404 | 404 | return $this; |
405 | 405 | } |
406 | 406 | |
407 | - public function hideColumn($colIndex){ |
|
408 | - if(isset($this->content["thead"])){ |
|
407 | + public function hideColumn($colIndex) { |
|
408 | + if (isset($this->content["thead"])) { |
|
409 | 409 | $this->content["thead"]->hideColumn($colIndex); |
410 | 410 | } |
411 | 411 | $this->content["tbody"]->hideColumn($colIndex); |
412 | - if(isset($this->content["tfoot"])){ |
|
412 | + if (isset($this->content["tfoot"])) { |
|
413 | 413 | $this->content["tfoot"]->hideColumn($colIndex); |
414 | 414 | } |
415 | 415 | return $this; |
416 | 416 | } |
417 | 417 | |
418 | - public function setColWidth($colIndex,$width){ |
|
418 | + public function setColWidth($colIndex, $width) { |
|
419 | 419 | $part=$this->_getFirstPart(); |
420 | - if($part!==null && $part->count()>0) |
|
420 | + if ($part!==null && $part->count()>0) |
|
421 | 421 | $part->getCell(0, $colIndex)->setWidth($width); |
422 | 422 | return $this; |
423 | 423 | } |
424 | 424 | |
425 | - public function setColWidths($widths){ |
|
425 | + public function setColWidths($widths) { |
|
426 | 426 | $part=$this->_getFirstPart(); |
427 | - if($part!==null && $part->count()>0){ |
|
427 | + if ($part!==null && $part->count()>0) { |
|
428 | 428 | $count=$part->getColCount(); |
429 | - if(!\is_array($widths)){ |
|
429 | + if (!\is_array($widths)) { |
|
430 | 430 | $widths=\array_fill(0, $count, $widths); |
431 | 431 | } |
432 | - $max=\min(\sizeof($widths),$count); |
|
433 | - for($i=0;$i<$max;$i++){ |
|
432 | + $max=\min(\sizeof($widths), $count); |
|
433 | + for ($i=0; $i<$max; $i++) { |
|
434 | 434 | $part->getCell(0, $i)->setWidth($widths[$i]); |
435 | 435 | } |
436 | 436 | } |
437 | 437 | return $this; |
438 | 438 | } |
439 | 439 | |
440 | - public function mergeIdentiqualValues($colIndex,$function="strip_tags"){ |
|
440 | + public function mergeIdentiqualValues($colIndex, $function="strip_tags") { |
|
441 | 441 | $body=$this->getBody(); |
442 | - $body->mergeIdentiqualValues($colIndex,$function); |
|
442 | + $body->mergeIdentiqualValues($colIndex, $function); |
|
443 | 443 | return $this; |
444 | 444 | } |
445 | 445 | /** |
@@ -453,11 +453,11 @@ discard block |
||
453 | 453 | * @param mixed $_innerScript |
454 | 454 | */ |
455 | 455 | public function setInnerScript($_innerScript) { |
456 | - $this->_innerScript = $_innerScript; |
|
456 | + $this->_innerScript=$_innerScript; |
|
457 | 457 | } |
458 | 458 | |
459 | - public function onActiveRowChange($jsCode){ |
|
460 | - $this->on("activeRowChange",$jsCode); |
|
459 | + public function onActiveRowChange($jsCode) { |
|
460 | + $this->on("activeRowChange", $jsCode); |
|
461 | 461 | return $this; |
462 | 462 | } |
463 | 463 |
@@ -8,12 +8,12 @@ discard block |
||
8 | 8 | * @author jc |
9 | 9 | * @property HtmlTable $_self |
10 | 10 | */ |
11 | -trait TableTrait{ |
|
11 | +trait TableTrait { |
|
12 | 12 | |
13 | 13 | abstract public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false); |
14 | 14 | abstract public function getOn($event, $url, $responseElement="", $parameters=array()); |
15 | 15 | |
16 | - protected function addToPropertyTable($property,$value){ |
|
16 | + protected function addToPropertyTable($property, $value) { |
|
17 | 17 | return $this->_self->addToProperty($property, $value); |
18 | 18 | } |
19 | 19 | |
@@ -24,15 +24,15 @@ discard block |
||
24 | 24 | public function setBasic($very=false) { |
25 | 25 | $table=$this->_self; |
26 | 26 | if ($very) |
27 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
28 | - return $table->addToPropertyCtrl("class", "basic", array ("basic" )); |
|
27 | + $table->addToPropertyCtrl("class", "very", array("very")); |
|
28 | + return $table->addToPropertyCtrl("class", "basic", array("basic")); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function setCompact($very=false) { |
32 | 32 | $table=$this->_self; |
33 | 33 | if ($very) |
34 | - $table->addToPropertyCtrl("class", "very", array ("very" )); |
|
35 | - return $table->addToPropertyCtrl("class", "compact", array ("compact" )); |
|
34 | + $table->addToPropertyCtrl("class", "very", array("very")); |
|
35 | + return $table->addToPropertyCtrl("class", "compact", array("compact")); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function setCollapsing() { |
@@ -71,37 +71,37 @@ discard block |
||
71 | 71 | return $this->addToPropertyTable("class", "striped"); |
72 | 72 | } |
73 | 73 | |
74 | - public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false){ |
|
75 | - return $this->onRow("click", $jsCode,$stopPropagation,$preventDefault); |
|
74 | + public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false) { |
|
75 | + return $this->onRow("click", $jsCode, $stopPropagation, $preventDefault); |
|
76 | 76 | } |
77 | 77 | |
78 | - public function onRow($event,$jsCode, $stopPropagation=false, $preventDefault=false){ |
|
79 | - return $this->_self->addEvent($event."{{tbody tr}}",$jsCode,$stopPropagation,$preventDefault); |
|
78 | + public function onRow($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
|
79 | + return $this->_self->addEvent($event."{{tbody tr}}", $jsCode, $stopPropagation, $preventDefault); |
|
80 | 80 | } |
81 | 81 | |
82 | - public function getOnRow($event, $url, $responseElement="", $parameters=array()){ |
|
83 | - $parameters=\array_merge($parameters,["stopPropagation"=>false,"preventDefault"=>false]); |
|
84 | - return $this->_self->getOn($event."{{tbody tr}}", $url,$responseElement,$parameters); |
|
82 | + public function getOnRow($event, $url, $responseElement="", $parameters=array()) { |
|
83 | + $parameters=\array_merge($parameters, ["stopPropagation"=>false, "preventDefault"=>false]); |
|
84 | + return $this->_self->getOn($event."{{tbody tr}}", $url, $responseElement, $parameters); |
|
85 | 85 | } |
86 | 86 | |
87 | - public function onPageChange($jsCode){ |
|
87 | + public function onPageChange($jsCode) { |
|
88 | 88 | $this->_self->_addEvent("pageChange", $jsCode); |
89 | 89 | return $this; |
90 | 90 | } |
91 | 91 | |
92 | - public function onSearchTerminate($jsCode){ |
|
92 | + public function onSearchTerminate($jsCode) { |
|
93 | 93 | $this->_self->_addEvent("searchTerminate", $jsCode); |
94 | 94 | return $this; |
95 | 95 | } |
96 | 96 | |
97 | - public function getEventsScript(){ |
|
97 | + public function getEventsScript() { |
|
98 | 98 | return $this->_self->getBsComponent()->getScript(); |
99 | 99 | } |
100 | 100 | |
101 | 101 | public function addEventsOnRun(JsUtils $js=NULL) { |
102 | 102 | $script=parent::addEventsOnRun($js); |
103 | 103 | $innerScript=$this->_self->getInnerScript(); |
104 | - if(!isset($innerScript)){ |
|
104 | + if (!isset($innerScript)) { |
|
105 | 105 | $this->_self->setInnerScript($script); |
106 | 106 | } |
107 | 107 | return $script; |