Passed
Push — master ( dff881...d19663 )
by Jean-Christophe
01:58
created
Ajax/common/Widget.php 1 patch
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 use Ajax\semantic\html\modules\HtmlModal;
21 21
 
22 22
 abstract class Widget extends HtmlDoubleElement {
23
-	use FieldAsTrait,FormTrait;
23
+	use FieldAsTrait, FormTrait;
24 24
 
25 25
 	/**
26 26
 	 * @var string classname
@@ -53,17 +53,17 @@  discard block
 block discarded – undo
53 53
 	protected $_generated;
54 54
 
55 55
 
56
-	public function __construct($identifier,$model,$modelInstance=NULL) {
56
+	public function __construct($identifier, $model, $modelInstance=NULL) {
57 57
 		parent::__construct($identifier);
58 58
 		$this->_template="%wrapContentBefore%%content%%wrapContentAfter%";
59 59
 		$this->setModel($model);
60
-		if(isset($modelInstance)){
60
+		if (isset($modelInstance)) {
61 61
 			$this->show($modelInstance);
62 62
 		}
63 63
 		$this->_generated=false;
64 64
 	}
65 65
 
66
-	protected function _init($instanceViewer,$contentKey,$content,$edition){
66
+	protected function _init($instanceViewer, $contentKey, $content, $edition) {
67 67
 		$this->_instanceViewer=$instanceViewer;
68 68
 		$this->content=[$contentKey=>$content];
69 69
 		$this->_self=$content;
@@ -75,31 +75,31 @@  discard block
 block discarded – undo
75 75
 	 * @param int|string $fieldName
76 76
 	 * @return int|string|boolean
77 77
 	 */
78
-	protected function _getIndex($fieldName){
78
+	protected function _getIndex($fieldName) {
79 79
 		$index=$fieldName;
80
-		if(\is_string($fieldName)){
80
+		if (\is_string($fieldName)) {
81 81
 			$fields=$this->_instanceViewer->getVisibleProperties();
82 82
 			$index=\array_search($fieldName, $fields);
83 83
 		}
84 84
 		return $index;
85 85
 	}
86 86
 
87
-	protected function _getFieldIdentifier($prefix,$name=""){
87
+	protected function _getFieldIdentifier($prefix, $name="") {
88 88
 		return $this->identifier."-{$prefix}-".$this->_instanceViewer->getIdentifier();
89 89
 	}
90 90
 
91
-	protected function _getFieldName($index){
91
+	protected function _getFieldName($index) {
92 92
 		return $this->_instanceViewer->getFieldName($index);
93 93
 	}
94 94
 
95
-	protected function _getFieldCaption($index){
95
+	protected function _getFieldCaption($index) {
96 96
 		return $this->_instanceViewer->getCaption($index);
97 97
 	}
98 98
 
99
-	abstract protected  function _setToolbarPosition($table,$captions=NULL);
99
+	abstract protected  function _setToolbarPosition($table, $captions=NULL);
100 100
 
101
-	public function show($modelInstance){
102
-		if(\is_array($modelInstance)){
101
+	public function show($modelInstance) {
102
+		if (\is_array($modelInstance)) {
103 103
 			$modelInstance=\json_decode(\json_encode($modelInstance), FALSE);
104 104
 		}
105 105
 		$this->_modelInstance=$modelInstance;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
 	abstract public function getHtmlComponent();
127 127
 
128
-	public function setAttached($value=true){
128
+	public function setAttached($value=true) {
129 129
 		return $this->getHtmlComponent()->setAttached($value);
130 130
 	}
131 131
 
@@ -136,59 +136,59 @@  discard block
 block discarded – undo
136 136
 	 * @param callable $callback function called after the field compilation
137 137
 	 * @return Widget
138 138
 	 */
139
-	public function afterCompile($index,$callback){
139
+	public function afterCompile($index, $callback) {
140 140
 		$index=$this->_getIndex($index);
141 141
 		$this->_instanceViewer->afterCompile($index, $callback);
142 142
 		return $this;
143 143
 	}
144 144
 
145
-	public function setColor($color){
145
+	public function setColor($color) {
146 146
 		return $this->getHtmlComponent()->setColor($color);
147 147
 	}
148 148
 
149 149
 
150
-	public function setCaptions($captions){
150
+	public function setCaptions($captions) {
151 151
 		$this->_instanceViewer->setCaptions($captions);
152 152
 		return $this;
153 153
 	}
154 154
 
155
-	public function setCaption($index,$caption){
155
+	public function setCaption($index, $caption) {
156 156
 		$this->_instanceViewer->setCaption($this->_getIndex($index), $caption);
157 157
 		return $this;
158 158
 	}
159 159
 
160
-	public function setFields($fields){
160
+	public function setFields($fields) {
161 161
 		$this->_instanceViewer->setVisibleProperties($fields);
162 162
 		return $this;
163 163
 	}
164 164
 
165
-	public function addField($field){
165
+	public function addField($field) {
166 166
 		$this->_instanceViewer->addField($field);
167 167
 		return $this;
168 168
 	}
169 169
 
170
-	public function addFields($fields){
170
+	public function addFields($fields) {
171 171
 		$this->_instanceViewer->addFields($fields);
172 172
 		return $this;
173 173
 	}
174 174
 
175
-	public function addMessage($attributes=NULL,$fieldName="message"){
175
+	public function addMessage($attributes=NULL, $fieldName="message") {
176 176
 		$this->_instanceViewer->addField($fieldName);
177 177
 		$count=$this->_instanceViewer->visiblePropertiesCount();
178
-		return $this->fieldAsMessage($count-1,$attributes);
178
+		return $this->fieldAsMessage($count-1, $attributes);
179 179
 	}
180 180
 
181
-	public function addErrorMessage(){
182
-		return $this->addMessage(["error"=>true],"message");
181
+	public function addErrorMessage() {
182
+		return $this->addMessage(["error"=>true], "message");
183 183
 	}
184 184
 
185
-	public function insertField($index,$field){
185
+	public function insertField($index, $field) {
186 186
 		$index=$this->_getIndex($index);
187 187
 		$this->_instanceViewer->insertField($index, $field);
188 188
 		return $this;
189 189
 	}
190 190
 
191
-	public function insertInField($index,$field){
191
+	public function insertInField($index, $field) {
192 192
 		$index=$this->_getIndex($index);
193 193
 		$this->_instanceViewer->insertInField($index, $field);
194 194
 		return $this;
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 	 * @param callable $callback function parameters are : $value : the field value, $instance : the active instance of model, $fieldIndex : the field index, $rowIndex : the row index
201 201
 	 * @return Widget
202 202
 	 */
203
-	public function setValueFunction($index,$callback){
203
+	public function setValueFunction($index, $callback) {
204 204
 		$index=$this->_getIndex($index);
205 205
 		$this->_instanceViewer->setValueFunction($index, $callback);
206 206
 		return $this;
207 207
 	}
208 208
 
209
-	public function setIdentifierFunction($callback){
209
+	public function setIdentifierFunction($callback) {
210 210
 		$this->_instanceViewer->setIdentifierFunction($callback);
211 211
 		return $this;
212 212
 	}
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 	/**
215 215
 	 * @return \Ajax\semantic\html\collections\menus\HtmlMenu
216 216
 	 */
217
-	public function getToolbar(){
218
-		if(isset($this->_toolbar)===false){
217
+	public function getToolbar() {
218
+		if (isset($this->_toolbar)===false) {
219 219
 			$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier);
220 220
 		}
221 221
 		return $this->_toolbar;
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
 	 * @param callable $callback function to call on $element
228 228
 	 * @return \Ajax\common\html\HtmlDoubleElement
229 229
 	 */
230
-	public function addInToolbar($element,$callback=NULL){
230
+	public function addInToolbar($element, $callback=NULL) {
231 231
 		$tb=$this->getToolbar();
232
-		if($element instanceof BaseWidget){
233
-			if($element->getIdentifier()===""){
232
+		if ($element instanceof BaseWidget) {
233
+			if ($element->getIdentifier()==="") {
234 234
 				$element->setIdentifier("tb-item-".$this->identifier."-".$tb->count());
235 235
 			}
236 236
 		}
237
-		if(isset($callback)){
238
-			if(\is_callable($callback)){
237
+		if (isset($callback)) {
238
+			if (\is_callable($callback)) {
239 239
 				$callback($element);
240 240
 			}
241 241
 		}
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
 	 * @param callable $callback function($element)
249 249
 	 * @return \Ajax\common\html\HtmlDoubleElement
250 250
 	 */
251
-	public function addItemInToolbar($caption,$icon=NULL,$callback=NULL){
252
-		$result=$this->addInToolbar($caption,$callback);
253
-		if(isset($icon) && method_exists($result, "addIcon"))
251
+	public function addItemInToolbar($caption, $icon=NULL, $callback=NULL) {
252
+		$result=$this->addInToolbar($caption, $callback);
253
+		if (isset($icon) && method_exists($result, "addIcon"))
254 254
 			$result->addIcon($icon);
255 255
 		return $result;
256 256
 	}
@@ -260,14 +260,14 @@  discard block
 block discarded – undo
260 260
 	 * @param callable $callback function($element)
261 261
 	 * @return \Ajax\common\Widget
262 262
 	 */
263
-	public function addItemsInToolbar(array $items,$callback=NULL){
264
-		if(JArray::isAssociative($items)){
265
-			foreach ($items as $icon=>$item){
266
-				$this->addItemInToolbar($item,$icon,$callback);
263
+	public function addItemsInToolbar(array $items, $callback=NULL) {
264
+		if (JArray::isAssociative($items)) {
265
+			foreach ($items as $icon=>$item) {
266
+				$this->addItemInToolbar($item, $icon, $callback);
267 267
 			}
268
-		}else{
269
-			foreach ($items as $item){
270
-				$this->addItemInToolbar($item,null,$callback);
268
+		} else {
269
+			foreach ($items as $item) {
270
+				$this->addItemInToolbar($item, null, $callback);
271 271
 			}
272 272
 		}
273 273
 		return $this;
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
 	 * @param callable $callback function($element)
280 280
 	 * @return \Ajax\common\html\HtmlDoubleElement
281 281
 	 */
282
-	public function addDropdownInToolbar($value,$items,$callback=NULL){
282
+	public function addDropdownInToolbar($value, $items, $callback=NULL) {
283 283
 		$dd=$value;
284 284
 		if (\is_string($value)) {
285
-			$dd=new HtmlDropdown("dropdown-". $this->identifier."-".$value, $value, $items);
285
+			$dd=new HtmlDropdown("dropdown-".$this->identifier."-".$value, $value, $items);
286 286
 		}
287
-		return $this->addInToolbar($dd,$callback);
287
+		return $this->addInToolbar($dd, $callback);
288 288
 	}
289 289
 
290 290
 	/**
@@ -293,9 +293,9 @@  discard block
 block discarded – undo
293 293
 	 * @param callable $callback function($element)
294 294
 	 * @return \Ajax\common\html\HtmlDoubleElement
295 295
 	 */
296
-	public function addButtonInToolbar($caption,$cssStyle=null,$callback=NULL){
297
-		$bt=new HtmlButton("bt-".$caption,$caption,$cssStyle);
298
-		return $this->addInToolbar($bt,$callback);
296
+	public function addButtonInToolbar($caption, $cssStyle=null, $callback=NULL) {
297
+		$bt=new HtmlButton("bt-".$caption, $caption, $cssStyle);
298
+		return $this->addInToolbar($bt, $callback);
299 299
 	}
300 300
 
301 301
 	/**
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 	 * @param callable $callback function($element)
305 305
 	 * @return \Ajax\common\html\HtmlDoubleElement
306 306
 	 */
307
-	public function addButtonsInToolbar(array $captions,$asIcon=false,$callback=NULL){
308
-		$bts=new HtmlButtonGroups("",$captions,$asIcon);
309
-		return $this->addInToolbar($bts,$callback);
307
+	public function addButtonsInToolbar(array $captions, $asIcon=false, $callback=NULL) {
308
+		$bts=new HtmlButtonGroups("", $captions, $asIcon);
309
+		return $this->addInToolbar($bts, $callback);
310 310
 	}
311 311
 
312 312
 	/**
@@ -316,15 +316,15 @@  discard block
 block discarded – undo
316 316
 	 * @param boolean $labeled
317 317
 	 * @return \Ajax\common\html\HtmlDoubleElement
318 318
 	 */
319
-	public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){
320
-		$bt=new HtmlButton("",$caption);
321
-		$bt->addIcon($icon,$before,$labeled);
319
+	public function addLabelledIconButtonInToolbar($caption, $icon, $before=true, $labeled=false) {
320
+		$bt=new HtmlButton("", $caption);
321
+		$bt->addIcon($icon, $before, $labeled);
322 322
 		return $this->addInToolbar($bt);
323 323
 	}
324 324
 
325
-	public function addSubmitInToolbar($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){
326
-		$button=new HtmlButton($identifier,$value,$cssStyle);
327
-		$this->_buttonAsSubmit($button,"click",$url,$responseElement,$parameters);
325
+	public function addSubmitInToolbar($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) {
326
+		$button=new HtmlButton($identifier, $value, $cssStyle);
327
+		$this->_buttonAsSubmit($button, "click", $url, $responseElement, $parameters);
328 328
 		return $this->addInToolbar($button);
329 329
 	}
330 330
 
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 	 * @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model
355 355
 	 * @return \Ajax\common\Widget
356 356
 	 */
357
-	public function setDefaultValueFunction($defaultValueFunction){
357
+	public function setDefaultValueFunction($defaultValueFunction) {
358 358
 		$this->_instanceViewer->setDefaultValueFunction($defaultValueFunction);
359 359
 		return $this;
360 360
 	}
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	/**
363 363
 	 * @return callable
364 364
 	 */
365
-	public function getDefaultValueFunction(){
365
+	public function getDefaultValueFunction() {
366 366
 		return $this->_instanceViewer->getDefaultValueFunction();
367 367
 	}
368 368
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 * @param string|boolean $disable
371 371
 	 * @return string
372 372
 	 */
373
-	public function jsDisabled($disable=true){
373
+	public function jsDisabled($disable=true) {
374 374
 		return "$('#".$this->identifier." .ui.input,#".$this->identifier." .ui.dropdown,#".$this->identifier." .ui.checkbox').toggleClass('disabled',".$disable.");";
375 375
 	}
376 376
 
@@ -379,12 +379,12 @@  discard block
 block discarded – undo
379 379
 	 * @param callable $callback function($element)
380 380
 	 * @return \Ajax\common\html\HtmlDoubleElement
381 381
 	 */
382
-	public function addEditButtonInToolbar($caption,$callback=NULL){
383
-		$bt=new HtmlButton($this->identifier."-editBtn",$caption);
382
+	public function addEditButtonInToolbar($caption, $callback=NULL) {
383
+		$bt=new HtmlButton($this->identifier."-editBtn", $caption);
384 384
 		$bt->setToggle();
385 385
 		$bt->setActive($this->_edition);
386 386
 		$bt->onClick($this->jsDisabled(Javascript::prep_value("!$(event.target).hasClass('active')")));
387
-		return $this->addInToolbar($bt,$callback);
387
+		return $this->addInToolbar($bt, $callback);
388 388
 	}
389 389
 
390 390
 	public function setToolbar(HtmlMenu $_toolbar) {
@@ -398,34 +398,34 @@  discard block
 block discarded – undo
398 398
 	}
399 399
 
400 400
 	public function getForm() {
401
-		if(!isset($this->_form)){
401
+		if (!isset($this->_form)) {
402 402
 			$this->_form=new HtmlForm("frm-".$this->identifier);
403 403
 			$this->setEdition(true);
404 404
 		}
405 405
 		return $this->_form;
406 406
 	}
407 407
 
408
-	public function run(JsUtils $js){
408
+	public function run(JsUtils $js) {
409 409
 		parent::run($js);
410
-		if(isset($this->_form)){
410
+		if (isset($this->_form)) {
411 411
 			$this->runForm($js);
412 412
 		}
413 413
 	}
414 414
 
415
-	protected function runForm(JsUtils $js){
415
+	protected function runForm(JsUtils $js) {
416 416
 		$fields=$this->getContentInstances(HtmlFormField::class);
417
-		foreach ($fields as $field){
417
+		foreach ($fields as $field) {
418 418
 			$this->_form->addField($field);
419 419
 		}
420 420
 		return $this->_form->run($js);
421 421
 	}
422 422
 
423
-	protected function _compileForm(){
424
-		if(isset($this->_form)){
423
+	protected function _compileForm() {
424
+		if (isset($this->_form)) {
425 425
 			$noValidate="";
426
-			if(\sizeof($this->_form->getValidationParams())>0)
426
+			if (\sizeof($this->_form->getValidationParams())>0)
427 427
 				$noValidate="novalidate";
428
-			$this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">","</form>");
428
+			$this->wrapContent("<form class='ui form' id='frm-".$this->identifier."' name='frm-".$this->identifier."' ".$noValidate.">", "</form>");
429 429
 		}
430 430
 	}
431 431
 
@@ -440,32 +440,32 @@  discard block
 block discarded – undo
440 440
 		return $this;
441 441
 	}
442 442
 
443
-	public function moveFieldTo($from,$to){
443
+	public function moveFieldTo($from, $to) {
444 444
 		return $this->_instanceViewer->moveFieldTo($from, $to);
445 445
 	}
446 446
 
447
-	public function swapFields($index1,$index2){
447
+	public function swapFields($index1, $index2) {
448 448
 		$index1=$this->_getIndex($index1);
449 449
 		$index2=$this->_getIndex($index2);
450 450
 		return $this->_instanceViewer->swapFields($index1, $index2);
451 451
 	}
452 452
 
453
-	public function removeField($index){
453
+	public function removeField($index) {
454 454
 		$index=$this->_getIndex($index);
455 455
 		$this->_instanceViewer->removeField($index);
456 456
 		return $this;
457 457
 	}
458 458
 
459
-	public function asModal($header=null){
460
-		$modal=new HtmlModal("modal-".$this->identifier,$header);
459
+	public function asModal($header=null) {
460
+		$modal=new HtmlModal("modal-".$this->identifier, $header);
461 461
 		$modal->setContent($this);
462
-		if(isset($this->_form)){
462
+		if (isset($this->_form)) {
463 463
 			$this->_form->onSuccess($modal->jsHide());
464 464
 		}
465 465
 		return $modal;
466 466
 	}
467 467
 
468 468
 	public function addToProperty($name, $value, $separator=" ") {
469
-		return $this->getHtmlComponent()->addToProperty($name,$value,$separator);
469
+		return $this->getHtmlComponent()->addToProperty($name, $value, $separator);
470 470
 	}
471 471
 }
Please login to merge, or discard this patch.
Ajax/common/traits/JsUtilsInternalTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 namespace Ajax\common\traits;
3 3
 use Ajax\common\BaseGui;
4 4
 
5
-trait JsUtilsInternalTrait{
5
+trait JsUtilsInternalTrait {
6 6
 
7
-	protected $jquery_code_for_compile=array ();
8
-	protected $jquery_code_for_compile_at_last=array ();
7
+	protected $jquery_code_for_compile=array();
8
+	protected $jquery_code_for_compile_at_last=array();
9 9
 
10 10
 	protected function _addToCompile($jsScript) {
11 11
 		$this->jquery_code_for_compile[]=$jsScript;
@@ -15,29 +15,29 @@  discard block
 block discarded – undo
15 15
 	 * @param BaseGui $library
16 16
 	 * @param mixed $view
17 17
 	 */
18
-	protected function _compileLibrary(BaseGui $library, &$view=NULL){
19
-		if(isset($view))
18
+	protected function _compileLibrary(BaseGui $library, &$view=NULL) {
19
+		if (isset($view))
20 20
 			$library->compileHtml($this, $view);
21 21
 		if ($library->isAutoCompile()) {
22 22
 			$library->compile(true);
23 23
 		}
24 24
 	}
25 25
 
26
-	protected function defer($script){
26
+	protected function defer($script) {
27 27
 		$result="window.defer=function (method) {if (window.jQuery) method(); else setTimeout(function() { defer(method) }, 50);};";
28 28
 		$result.="window.defer(function(){".$script."})";
29 29
 		return $result;
30 30
 	}
31 31
 
32
-	protected function ready($script){
32
+	protected function ready($script) {
33 33
 		$result='$(document).ready(function() {'."\n";
34 34
 		$result.=$script.'})';
35 35
 		return $result;
36 36
 	}
37 37
 
38 38
 	protected function minify($input) {
39
-		if(trim($input) === "") return $input;
40
-		$input= preg_replace(
39
+		if (trim($input)==="") return $input;
40
+		$input=preg_replace(
41 41
 				array(
42 42
 						// Remove comment(s)
43 43
 						'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
Please login to merge, or discard this patch.
Ajax/common/html/traits/BaseHtmlEventsTrait.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
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,11 +23,11 @@  discard block
 block discarded – undo
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
 	}
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 	public function _addEvent($event, $jsCode) {
41 41
 		if (array_key_exists($event, $this->_events)) {
42 42
 			if (\is_array($this->_events[$event])) {
43
-				if(array_search($jsCode, $this->_events[$event])===false){
43
+				if (array_search($jsCode, $this->_events[$event])===false) {
44 44
 					$this->_events[$event][]=$jsCode;
45 45
 				}
46 46
 			} else {
47
-				$this->_events[$event]=array ($this->_events[$event],$jsCode );
47
+				$this->_events[$event]=array($this->_events[$event], $jsCode);
48 48
 			}
49 49
 		} else {
50 50
 			$this->_events[$event]=$jsCode;
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 		return $this->onClick($jsCode);
72 72
 	}
73 73
 
74
-	public function onCreate($jsCode){
75
-		if(isset($this->_events["_create"])){
74
+	public function onCreate($jsCode) {
75
+		if (isset($this->_events["_create"])) {
76 76
 			$this->_events["_create"][]=$jsCode;
77
-		}else{
77
+		} else {
78 78
 			$this->_events["_create"]=[$jsCode];
79 79
 		}
80 80
 		return $this;
@@ -83,15 +83,15 @@  discard block
 block discarded – undo
83 83
 	public function addEventsOnRun(JsUtils $js=NULL) {
84 84
 		$this->_eventsOnCreate($js);
85 85
 		if (isset($this->_bsComponent)) {
86
-			foreach ( $this->_events as $event => $jsCode ) {
86
+			foreach ($this->_events as $event => $jsCode) {
87 87
 				$code=$jsCode;
88 88
 				if (\is_array($jsCode)) {
89 89
 					$code="";
90
-					foreach ( $jsCode as $jsC ) {
90
+					foreach ($jsCode as $jsC) {
91 91
 						if ($jsC instanceof AjaxCall) {
92
-							$code.="\n" . $jsC->compile($js);
92
+							$code.="\n".$jsC->compile($js);
93 93
 						} else {
94
-							$code.="\n" . $jsC;
94
+							$code.="\n".$jsC;
95 95
 						}
96 96
 					}
97 97
 				} elseif ($jsCode instanceof AjaxCall) {
@@ -99,18 +99,18 @@  discard block
 block discarded – undo
99 99
 				}
100 100
 				$this->_bsComponent->addEvent($event, $code);
101 101
 			}
102
-			$this->_events=array ();
102
+			$this->_events=array();
103 103
 		}
104 104
 	}
105 105
 
106
-	protected function _eventsOnCreate(JsUtils $js=NULL){
107
-		if(isset($this->_events["_create"])){
106
+	protected function _eventsOnCreate(JsUtils $js=NULL) {
107
+		if (isset($this->_events["_create"])) {
108 108
 			$create=$this->_events["_create"];
109
-			if(\is_array($create)){
109
+			if (\is_array($create)) {
110 110
 				$create=\implode("", $create);
111 111
 			}
112
-			if(isset($js) && $create!=="")
113
-				$js->exec($create,true);
112
+			if (isset($js) && $create!=="")
113
+				$js->exec($create, true);
114 114
 			unset($this->_events["_create"]);
115 115
 		}
116 116
 	}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @return $this
125 125
 	 */
126 126
 	public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) {
127
-		$params=array ("url" => $url,"responseElement" => $responseElement );
127
+		$params=array("url" => $url, "responseElement" => $responseElement);
128 128
 		$params=array_merge($params, $parameters);
129 129
 		$this->_addEvent($event, new AjaxCall($operation, $params));
130 130
 		return $this;
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
 	 **/
168 168
 	public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) {
169 169
 		$allParameters=[];
170
-		if(isset($parameters["params"])){
170
+		if (isset($parameters["params"])) {
171 171
 			$allParameters[]=JsUtils::_correctParams($parameters["params"]);
172 172
 		}
173
-		if(isset($params)){
173
+		if (isset($params)) {
174 174
 			$allParameters[]=JsUtils::_correctParams($params);
175 175
 		}
176 176
 		$parameters["params"]=\implode("+'&'+", $allParameters);
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	}
218 218
 
219 219
 	public function jsDoJquery($jqueryCall, $param="") {
220
-		return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . Javascript::prep_value($param) . ");";
220
+		return "$('#".$this->identifier."').".$jqueryCall."(".Javascript::prep_value($param).");";
221 221
 	}
222 222
 
223 223
 	public function executeOnRun($jsCode) {
@@ -237,6 +237,6 @@  discard block
 block discarded – undo
237 237
 	}
238 238
 
239 239
 	public function jsToggle($value) {
240
-		return $this->jsDoJquery("toggle",$value);
240
+		return $this->jsDoJquery("toggle", $value);
241 241
 	}
242 242
 }
Please login to merge, or discard this patch.
Ajax/common/traits/JsUtilsAjaxTrait.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
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,100 +30,100 @@  discard block
 block discarded – undo
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 _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){
104
-		$retour="";$call=null;
103
+	protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) {
104
+		$retour=""; $call=null;
105 105
 		if (JString::isNotNull($responseElement)) {
106
-			if(isset($ajaxTransition)){
106
+			if (isset($ajaxTransition)) {
107 107
 				$call=$this->setAjaxDataCall($ajaxTransition);
108
-			}elseif(isset($this->ajaxTransition)){
108
+			}elseif (isset($this->ajaxTransition)) {
109 109
 				$call=$this->ajaxTransition;
110 110
 			}
111
-			if(\is_callable($call))
112
-				$retour="\t".$call($responseElement,$jqueryDone).";\n";
111
+			if (\is_callable($call))
112
+				$retour="\t".$call($responseElement, $jqueryDone).";\n";
113 113
 			else
114 114
 				$retour="\t{$responseElement}.{$jqueryDone}( data );\n";
115 115
 		}
116
-		if(isset($history)){
116
+		if (isset($history)) {
117 117
 			$retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);";
118 118
 		}
119
-		if($hasLoader==="internal"){
119
+		if ($hasLoader==="internal") {
120 120
 			$retour.="\n$(self).removeClass('loading');";
121 121
 		}
122 122
 		$retour.="\t".$jsCallback."\n";
123 123
 		return $retour;
124 124
 	}
125 125
 
126
-	protected function _getResponseElement($responseElement){
126
+	protected function _getResponseElement($responseElement) {
127 127
 		if (JString::isNotNull($responseElement)) {
128 128
 			$responseElement=Javascript::prep_value($responseElement);
129 129
 			$responseElement=Javascript::prep_jquery_selector($responseElement);
@@ -134,33 +134,33 @@  discard block
 block discarded – undo
134 134
 	protected function _correctAjaxUrl($url) {
135 135
 		if ($url!=="/" && JString::endsWith($url, "/")===true)
136 136
 			$url=substr($url, 0, strlen($url)-1);
137
-			if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) {
137
+			if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) {
138 138
 				$url=$this->getUrl($url);
139 139
 			}
140 140
 			return $url;
141 141
 	}
142 142
 
143
-	public static function _correctParams($params){
144
-		if(JString::isNull($params)){
143
+	public static function _correctParams($params) {
144
+		if (JString::isNull($params)) {
145 145
 			return "";
146 146
 		}
147
-		if(\preg_match("@^\{.*?\}$@", $params)){
147
+		if (\preg_match("@^\{.*?\}$@", $params)) {
148 148
 			return '$.param('.$params.')';
149 149
 		}
150 150
 		return $params;
151 151
 	}
152 152
 
153
-	public static function _implodeParams($parameters){
153
+	public static function _implodeParams($parameters) {
154 154
 		$allParameters=[];
155
-		foreach ($parameters as $params){
156
-			if(isset($params))
155
+		foreach ($parameters as $params) {
156
+			if (isset($params))
157 157
 				$allParameters[]=self::_correctParams($params);
158 158
 		}
159 159
 		return \implode("+'&'+", $allParameters);
160 160
 	}
161 161
 
162
-	protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) {
163
-		if(!isset($ajaxLoader)){
162
+	protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) {
163
+		if (!isset($ajaxLoader)) {
164 164
 			$ajaxLoader=$this->ajaxLoader;
165 165
 		}
166 166
 		$loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>';
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
 		$retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
169 169
 	}
170 170
 
171
-	protected function setAjaxDataCall($params){
171
+	protected function setAjaxDataCall($params) {
172 172
 		$result=null;
173
-		if(!\is_callable($params)){
174
-			$result=function ($responseElement,$jqueryDone="html") use($params){
175
-				return AjaxTransition::{$params}($responseElement,$jqueryDone);
173
+		if (!\is_callable($params)) {
174
+			$result=function($responseElement, $jqueryDone="html") use($params){
175
+				return AjaxTransition::{$params}($responseElement, $jqueryDone);
176 176
 			};
177 177
 		}
178 178
 		return $result;
179 179
 	}
180 180
 
181
-	protected function setDefaultParameters(&$parameters,$default){
182
-		foreach ($default as $k=>$v){
183
-			if(!isset($parameters[$k]))
181
+	protected function setDefaultParameters(&$parameters, $default) {
182
+		foreach ($default as $k=>$v) {
183
+			if (!isset($parameters[$k]))
184 184
 				$parameters[$k]=$v;
185 185
 		}
186 186
 	}
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
 	 * @param string $url The url of the request
195 195
 	 * @param string $responseElement selector of the HTML element displaying the answer
196 196
 	 */
197
-	private function _get($url, $responseElement="",$parameters=[]) {
198
-		return $this->_ajax("get", $url,$responseElement,$parameters);
197
+	private function _get($url, $responseElement="", $parameters=[]) {
198
+		return $this->_ajax("get", $url, $responseElement, $parameters);
199 199
 	}
200 200
 
201 201
 	/**
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 	 * @param string $responseElement selector of the HTML element displaying the answer
205 205
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
206 206
 	 */
207
-	public function get($url, $responseElement="",$parameters=[]) {
207
+	public function get($url, $responseElement="", $parameters=[]) {
208 208
 		$parameters["immediatly"]=true;
209
-		return $this->_get($url,$responseElement,$parameters);
209
+		return $this->_get($url, $responseElement, $parameters);
210 210
 	}
211 211
 
212 212
 	/**
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 * @param string $responseElement selector of the HTML element displaying the answer
217 217
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
218 218
 	 */
219
-	public function ajax($method,$url, $responseElement="", $parameters=[]) {
219
+	public function ajax($method, $url, $responseElement="", $parameters=[]) {
220 220
 		$parameters["immediatly"]=true;
221
-		return $this->_ajax($method,$url,$responseElement,$parameters);
221
+		return $this->_ajax($method, $url, $responseElement, $parameters);
222 222
 	}
223 223
 
224 224
 	/**
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
 	 * @param string $responseElement selector of the HTML element displaying the answer
229 229
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false)
230 230
 	 */
231
-	public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) {
231
+	public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) {
232 232
 		$parameters["immediatly"]=false;
233
-		return $this->_ajax($method,$url,$responseElement,$parameters);
233
+		return $this->_ajax($method, $url, $responseElement, $parameters);
234 234
 	}
235 235
 
236 236
 	/**
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
 	 * @param string $method Method used
240 240
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false)
241 241
 	 */
242
-	private function _json($url, $method="get",$parameters=[]) {
243
-		$parameters=\array_merge($parameters,["hasLoader"=>false]);
242
+	private function _json($url, $method="get", $parameters=[]) {
243
+		$parameters=\array_merge($parameters, ["hasLoader"=>false]);
244 244
 		$jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
245 245
 		$context=isset($parameters['context']) ? $parameters['context'] : "document";
246 246
 		$retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n\tfor(var key in data){"
247 247
 				."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n";
248 248
 				$retour.="\t$(document).trigger('jsonReady',[data]);\n";
249 249
 		$parameters["jsCallback"]=$retour;
250
-		return $this->_ajax($method, $url,null,$parameters);
250
+		return $this->_ajax($method, $url, null, $parameters);
251 251
 	}
252 252
 
253 253
 	/**
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false)
258 258
 	 */
259 259
 	public function json($url, $method="get", $parameters=[]) {
260
-		return $this->_json($url,$method,$parameters);
260
+		return $this->_json($url, $method, $parameters);
261 261
 	}
262 262
 
263 263
 	/**
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
 	 * @param string $method default get
269 269
 	 * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true)
270 270
 	 */
271
-	public function jsonOn($event,$element, $url,$method="get",$parameters=array()) {
272
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
273
-		return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
271
+	public function jsonOn($event, $element, $url, $method="get", $parameters=array()) {
272
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
273
+		return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
274 274
 	}
275 275
 
276 276
 	/**
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 */
282 282
 	public function jsonDeferred($url, $method="get", $parameters=[]) {
283 283
 		$parameters["immediatly"]=false;
284
-		return $this->_json($url,$method,$parameters);
284
+		return $this->_json($url, $method, $parameters);
285 285
 	}
286 286
 
287 287
 	/**
@@ -292,26 +292,26 @@  discard block
 block discarded – undo
292 292
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json")
293 293
 	 */
294 294
 	private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
295
-		$parameters=\array_merge($parameters,["hasLoader"=>false]);
295
+		$parameters=\array_merge($parameters, ["hasLoader"=>false]);
296 296
 		$rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json";
297 297
 		$jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : "";
298 298
 		$context=isset($parameters['context']) ? $parameters['context'] : null;
299
-		if($context===null){
299
+		if ($context===null) {
300 300
 			$parent="$('".$maskSelector."').parent()";
301
-			$newElm = "$('#'+newId)";
302
-		}else{
301
+			$newElm="$('#'+newId)";
302
+		} else {
303 303
 			$parent=$context;
304
-			$newElm = $context.".find('#'+newId)";
304
+			$newElm=$context.".find('#'+newId)";
305 305
 		}
306 306
 		$appendTo="\t\tnewElm.appendTo(".$parent.");\n";
307 307
 		$retour=$parent.".find('.{$rowClass}').remove();";
308 308
 		$retour.="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\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();
309 309
 		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";
310
-		$retour.= $appendTo;
310
+		$retour.=$appendTo;
311 311
 		$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";
312 312
 		$retour.="\t$(document).trigger('jsonReady',[data]);\n";
313 313
 		$parameters["jsCallback"]=$retour;
314
-		return $this->_ajax($method, $url,null,$parameters);
314
+		return $this->_ajax($method, $url, null, $parameters);
315 315
 	}
316 316
 
317 317
 	/**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json")
323 323
 	 */
324 324
 	public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) {
325
-		return $this->_jsonArray($maskSelector, $url,$method,$parameters);
325
+		return $this->_jsonArray($maskSelector, $url, $method, $parameters);
326 326
 	}
327 327
 
328 328
 	/**
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 	 * @param string $method Method used, default : get
346 346
 	 * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true)
347 347
 	 */
348
-	public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) {
349
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
350
-		return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
348
+	public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) {
349
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
350
+		return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
351 351
 	}
352 352
 
353 353
 	/**
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	public function getDeferred($url, $responseElement="", $parameters=[]) {
361 361
 		$parameters["immediatly"]=false;
362
-		return $this->_get($url, $responseElement,$parameters);
362
+		return $this->_get($url, $responseElement, $parameters);
363 363
 	}
364 364
 
365 365
 	/**
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
 	 * @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)
373 373
 	 */
374 374
 	public function getOn($event, $element, $url, $responseElement="", $parameters=array()) {
375
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
376
-		return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
375
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
376
+		return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
377 377
 	}
378 378
 
379 379
 	/**
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 	 * @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)
387 387
 	 */
388 388
 	public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) {
389
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]);
390
-		return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
389
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]);
390
+		return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
391 391
 	}
392 392
 
393 393
 	/**
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
 	 * @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)
422 422
 	 * @return $this
423 423
 	 */
424
-	public function getHref($element,$responseElement="",$parameters=array()){
424
+	public function getHref($element, $responseElement="", $parameters=array()) {
425 425
 		$parameters["attr"]="href";
426
-		if(JString::isNull($responseElement)){
426
+		if (JString::isNull($responseElement)) {
427 427
 			$responseElement='$($(this).attr("data-target"))';
428 428
 		}
429
-		if(!isset($parameters["historize"])){
429
+		if (!isset($parameters["historize"])) {
430 430
 			$parameters["historize"]=true;
431 431
 		}
432
-		return $this->getOnClick($element, "",$responseElement,$parameters);
432
+		return $this->getOnClick($element, "", $responseElement, $parameters);
433 433
 	}
434 434
 	
435 435
 	/**
@@ -439,20 +439,20 @@  discard block
 block discarded – undo
439 439
 	 * @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)
440 440
 	 * @return $this
441 441
 	 */
442
-	public function postHref($element,$responseElement="",$parameters=array()){
442
+	public function postHref($element, $responseElement="", $parameters=array()) {
443 443
 		$parameters["attr"]="href";
444
-		if(JString::isNull($responseElement)){
444
+		if (JString::isNull($responseElement)) {
445 445
 			$responseElement='$($(this).attr("data-target"))';
446 446
 		}
447
-		if(!isset($parameters["historize"])){
447
+		if (!isset($parameters["historize"])) {
448 448
 			$parameters["historize"]=true;
449 449
 		}
450
-		return $this->postOnClick($element, "","{}",$responseElement,$parameters);
450
+		return $this->postOnClick($element, "", "{}", $responseElement, $parameters);
451 451
 	}
452 452
 
453
-	private function _post($url, $params="{}",$responseElement="", $parameters=[]) {
453
+	private function _post($url, $params="{}", $responseElement="", $parameters=[]) {
454 454
 		$parameters["params"]=$params;
455
-		return $this->_ajax("POST", $url,$responseElement,$parameters);
455
+		return $this->_ajax("POST", $url, $responseElement, $parameters);
456 456
 	}
457 457
 
458 458
 	/**
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 	 * @param string $params JSON parameters
463 463
 	 * @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)
464 464
 	 */
465
-	public function post($url, $params="{}",$responseElement="", $parameters=[]) {
466
-		return $this->_post($url, $params,$responseElement, $parameters);
465
+	public function post($url, $params="{}", $responseElement="", $parameters=[]) {
466
+		return $this->_post($url, $params, $responseElement, $parameters);
467 467
 	}
468 468
 
469 469
 	/**
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 	 * @param string $responseElement selector of the HTML element displaying the answer
475 475
 	 * @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)
476 476
 	 */
477
-	public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) {
477
+	public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) {
478 478
 		$parameters["immediatly"]=false;
479 479
 		return $this->_post($url, $params, $responseElement, $parameters);
480 480
 	}
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
 	 * @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)
491 491
 	 */
492 492
 	public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) {
493
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
494
-		return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
493
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
494
+		return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
495 495
 	}
496 496
 
497 497
 	/**
@@ -508,33 +508,33 @@  discard block
 block discarded – undo
508 508
 	}
509 509
 
510 510
 	private function _postForm($url, $form, $responseElement, $parameters=[]) {
511
-		if(isset($this->params["ajax"])){
511
+		if (isset($this->params["ajax"])) {
512 512
 			extract($this->params["ajax"]);
513 513
 		}
514
-		$params="{}";$validation=false;
514
+		$params="{}"; $validation=false;
515 515
 		\extract($parameters);
516
-		$async=($async)?"true":"false";
516
+		$async=($async) ? "true" : "false";
517 517
 		$jsCallback=isset($jsCallback) ? $jsCallback : "";
518 518
 		$retour=$this->_getAjaxUrl($url, $attr);
519 519
 		$retour.="\n$('#".$form."').trigger('ajaxSubmit');";
520 520
 		$retour.="\nvar params=$('#".$form."').serialize();\n";
521
-		if(isset($params)){
521
+		if (isset($params)) {
522 522
 			$retour.="params+='&'+".self::_correctParams($params).";\n";
523 523
 		}
524 524
 		$responseElement=$this->_getResponseElement($responseElement);
525 525
 		$retour.="var self=this;\n";
526
-		if($hasLoader===true){
527
-			$this->addLoading($retour, $responseElement,$ajaxLoader);
528
-		}elseif($hasLoader==="internal"){
526
+		if ($hasLoader===true) {
527
+			$this->addLoading($retour, $responseElement, $ajaxLoader);
528
+		}elseif ($hasLoader==="internal") {
529 529
 			$retour.="\n$(this).addClass('loading');";
530 530
 		}
531
-		$ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async];
532
-		if(isset($headers)){
531
+		$ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async];
532
+		if (isset($headers)) {
533 533
 			$ajaxParameters["headers"]=$headers;
534 534
 		}
535 535
 		$this->createAjaxParameters($ajaxParameters, $parameters);
536 536
 		$retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n";
537
-		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n";
537
+		$retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n";
538 538
 
539 539
 		if ($validation) {
540 540
 			$retour="$('#".$form."').validate({submitHandler: function(form) {
@@ -584,8 +584,8 @@  discard block
 block discarded – undo
584 584
 	 * @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)
585 585
 	 */
586 586
 	public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) {
587
-		$this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]);
588
-		return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]);
587
+		$this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]);
588
+		return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]);
589 589
 	}
590 590
 
591 591
 	/**
Please login to merge, or discard this patch.