@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @return mixed |
| 38 | 38 | */ |
| 39 | 39 | public function getLibraryId() { |
| 40 | - if( isset($this->_libraryId)){ |
|
| 40 | + if (isset($this->_libraryId)) { |
|
| 41 | 41 | return $this->_libraryId; |
| 42 | 42 | } |
| 43 | 43 | return $this->identifier; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param mixed $_libraryId |
| 48 | 48 | */ |
| 49 | 49 | public function setLibraryId($_libraryId) { |
| 50 | - $this->_libraryId = $_libraryId; |
|
| 50 | + $this->_libraryId=$_libraryId; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | } |
@@ -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 | |
@@ -581,16 +581,16 @@ discard block |
||
| 581 | 581 | * @param boolean $immediatly delayed if false |
| 582 | 582 | * @return string |
| 583 | 583 | */ |
| 584 | - public function interval($jsCode,$time,$globalName=null,$immediatly=true){ |
|
| 585 | - if(!Javascript::isFunction($jsCode)){ |
|
| 584 | + public function interval($jsCode, $time, $globalName=null, $immediatly=true) { |
|
| 585 | + if (!Javascript::isFunction($jsCode)) { |
|
| 586 | 586 | $jsCode="function(){\n".$jsCode."\n}"; |
| 587 | 587 | } |
| 588 | - if(isset($globalName)){ |
|
| 588 | + if (isset($globalName)) { |
|
| 589 | 589 | $script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
| 590 | - }else{ |
|
| 590 | + } else { |
|
| 591 | 591 | $script="setInterval({$jsCode},{$time});"; |
| 592 | 592 | } |
| 593 | - return $this->exec($script,$immediatly); |
|
| 593 | + return $this->exec($script, $immediatly); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -599,8 +599,8 @@ discard block |
||
| 599 | 599 | * @param boolean $immediatly delayed if false |
| 600 | 600 | * @return string |
| 601 | 601 | */ |
| 602 | - public function clearInterval($globalName,$immediatly=true){ |
|
| 603 | - return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}",$immediatly); |
|
| 602 | + public function clearInterval($globalName, $immediatly=true) { |
|
| 603 | + return $this->exec("if(window.{$globalName}){clearInterval(window.{$globalName});}", $immediatly); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -613,17 +613,17 @@ discard block |
||
| 613 | 613 | * @param boolean $immediatly delayed if false |
| 614 | 614 | * @return string |
| 615 | 615 | */ |
| 616 | - public function counter($counterSelector,$value=0,$limit=0,$globalName=null,$countDown=true,$immediatly=true){ |
|
| 616 | + public function counter($counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true, $immediatly=true) { |
|
| 617 | 617 | $stop=""; |
| 618 | - if($countDown){ |
|
| 618 | + if ($countDown) { |
|
| 619 | 619 | $stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
| 620 | - }else{ |
|
| 621 | - if($limit!=0){ |
|
| 620 | + } else { |
|
| 621 | + if ($limit!=0) { |
|
| 622 | 622 | $stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | 625 | $global=""; |
| 626 | - if(isset($globalName)){ |
|
| 626 | + if (isset($globalName)) { |
|
| 627 | 627 | $global="\nwindow.{$globalName}=interval;"; |
| 628 | 628 | } |
| 629 | 629 | $timer="var startTimer=function(duration, display) {var timer = duration, minutes, seconds; |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | ".$global." |
| 640 | 640 | }"; |
| 641 | 641 | $element='$("'.$counterSelector.'")'; |
| 642 | - return $this->exec($timer."\nstartTimer(".$value.",".$element.");",$immediatly); |
|
| 642 | + return $this->exec($timer."\nstartTimer(".$value.",".$element.");", $immediatly); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | /** |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | * @param boolean $countDown count down if true or elapse if false |
| 654 | 654 | * @return string |
| 655 | 655 | */ |
| 656 | - public function counterOn($element,$event,$counterSelector,$value=0,$limit=0,$globalName=null,$countDown=true){ |
|
| 657 | - return $this->execOn($event, $element, $this->counter($counterSelector,$value,$limit,$globalName,$countDown,false)); |
|
| 656 | + public function counterOn($element, $event, $counterSelector, $value=0, $limit=0, $globalName=null, $countDown=true) { |
|
| 657 | + return $this->execOn($event, $element, $this->counter($counterSelector, $value, $limit, $globalName, $countDown, false)); |
|
| 658 | 658 | } |
| 659 | 659 | } |
@@ -29,8 +29,9 @@ discard block |
||
| 29 | 29 | $callback=", function(){\n{$callback}\n}"; |
| 30 | 30 | } |
| 31 | 31 | $str="$({$element}).{$action}({$speed}{$callback});"; |
| 32 | - if ($immediatly) |
|
| 33 | - $this->jquery_code_for_compile[]=$str; |
|
| 32 | + if ($immediatly) { |
|
| 33 | + $this->jquery_code_for_compile[]=$str; |
|
| 34 | + } |
|
| 34 | 35 | return $str; |
| 35 | 36 | } |
| 36 | 37 | /** |
@@ -62,10 +63,12 @@ discard block |
||
| 62 | 63 | if (isset($param)) { |
| 63 | 64 | $param=Javascript::prep_value($param); |
| 64 | 65 | $str="$({$element}).{$jQueryCall}({$param});"; |
| 65 | - } else |
|
| 66 | - $str="$({$element}).{$jQueryCall}();"; |
|
| 67 | - if ($immediatly) |
|
| 68 | - $this->jquery_code_for_compile[]=$str; |
|
| 66 | + } else { |
|
| 67 | + $str="$({$element}).{$jQueryCall}();"; |
|
| 68 | + } |
|
| 69 | + if ($immediatly) { |
|
| 70 | + $this->jquery_code_for_compile[]=$str; |
|
| 71 | + } |
|
| 69 | 72 | return $str; |
| 70 | 73 | } |
| 71 | 74 | |
@@ -81,8 +84,9 @@ discard block |
||
| 81 | 84 | $to=Javascript::prep_element($to); |
| 82 | 85 | $element=Javascript::prep_element($element); |
| 83 | 86 | $str="$({$to}).{$jQueryCall}({$element});"; |
| 84 | - if ($immediatly) |
|
| 85 | - $this->jquery_code_for_compile[]=$str; |
|
| 87 | + if ($immediatly) { |
|
| 88 | + $this->jquery_code_for_compile[]=$str; |
|
| 89 | + } |
|
| 86 | 90 | return $str; |
| 87 | 91 | } |
| 88 | 92 | /** |
@@ -131,10 +135,12 @@ discard block |
||
| 131 | 135 | if (isset($value)) { |
| 132 | 136 | $value=Javascript::prep_value($value); |
| 133 | 137 | $str="$({$element}).attr(\"$attributeName\",{$value});"; |
| 134 | - } else |
|
| 135 | - $str="$({$element}).attr(\"$attributeName\");"; |
|
| 136 | - if ($immediatly) |
|
| 137 | - $this->jquery_code_for_compile[]=$str; |
|
| 138 | + } else { |
|
| 139 | + $str="$({$element}).attr(\"$attributeName\");"; |
|
| 140 | + } |
|
| 141 | + if ($immediatly) { |
|
| 142 | + $this->jquery_code_for_compile[]=$str; |
|
| 143 | + } |
|
| 138 | 144 | return $str; |
| 139 | 145 | } |
| 140 | 146 | |
@@ -190,8 +196,9 @@ discard block |
||
| 190 | 196 | |
| 191 | 197 | $str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
| 192 | 198 | |
| 193 | - if ($immediatly) |
|
| 194 | - $this->jquery_code_for_compile[]=$str; |
|
| 199 | + if ($immediatly) { |
|
| 200 | + $this->jquery_code_for_compile[]=$str; |
|
| 201 | + } |
|
| 195 | 202 | return $str; |
| 196 | 203 | } |
| 197 | 204 | |
@@ -342,8 +349,9 @@ discard block |
||
| 342 | 349 | $element=Javascript::prep_element($element); |
| 343 | 350 | $str="$({$element}).trigger(\"$event\");"; |
| 344 | 351 | |
| 345 | - if ($immediatly) |
|
| 346 | - $this->jquery_code_for_compile[]=$str; |
|
| 352 | + if ($immediatly) { |
|
| 353 | + $this->jquery_code_for_compile[]=$str; |
|
| 354 | + } |
|
| 347 | 355 | return $str; |
| 348 | 356 | } |
| 349 | 357 | |
@@ -405,8 +413,9 @@ discard block |
||
| 405 | 413 | $str.="else{".$jsCodeIfFalse."}"; |
| 406 | 414 | } |
| 407 | 415 | |
| 408 | - if ($immediatly) |
|
| 409 | - $this->jquery_code_for_compile[]=$str; |
|
| 416 | + if ($immediatly) { |
|
| 417 | + $this->jquery_code_for_compile[]=$str; |
|
| 418 | + } |
|
| 410 | 419 | return $str; |
| 411 | 420 | } |
| 412 | 421 | |
@@ -422,11 +431,13 @@ discard block |
||
| 422 | 431 | private function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
| 423 | 432 | $param=Javascript::prep_value($param); |
| 424 | 433 | $callback=""; |
| 425 | - if ($jsCallback!="") |
|
| 426 | - $callback=", function(event){\n{$jsCallback}\n}"; |
|
| 434 | + if ($jsCallback!="") { |
|
| 435 | + $callback=", function(event){\n{$jsCallback}\n}"; |
|
| 436 | + } |
|
| 427 | 437 | $script="$(".Javascript::prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
| 428 | - if ($immediatly) |
|
| 429 | - $this->jquery_code_for_compile[]=$script; |
|
| 438 | + if ($immediatly) { |
|
| 439 | + $this->jquery_code_for_compile[]=$script; |
|
| 440 | + } |
|
| 430 | 441 | return $script; |
| 431 | 442 | } |
| 432 | 443 | |
@@ -497,8 +508,9 @@ discard block |
||
| 497 | 508 | */ |
| 498 | 509 | public function exec($js, $immediatly=false) { |
| 499 | 510 | $script=$js."\n"; |
| 500 | - if ($immediatly) |
|
| 501 | - $this->jquery_code_for_compile[]=$script; |
|
| 511 | + if ($immediatly) { |
|
| 512 | + $this->jquery_code_for_compile[]=$script; |
|
| 513 | + } |
|
| 502 | 514 | return $script; |
| 503 | 515 | } |
| 504 | 516 | |
@@ -587,7 +599,7 @@ discard block |
||
| 587 | 599 | } |
| 588 | 600 | if(isset($globalName)){ |
| 589 | 601 | $script="if(window.{$globalName}){clearInterval(window.{$globalName});}\nwindow.{$globalName}=setInterval({$jsCode},{$time});"; |
| 590 | - }else{ |
|
| 602 | + } else{ |
|
| 591 | 603 | $script="setInterval({$jsCode},{$time});"; |
| 592 | 604 | } |
| 593 | 605 | return $this->exec($script,$immediatly); |
@@ -617,7 +629,7 @@ discard block |
||
| 617 | 629 | $stop=""; |
| 618 | 630 | if($countDown){ |
| 619 | 631 | $stop="if (--timer < ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
| 620 | - }else{ |
|
| 632 | + } else{ |
|
| 621 | 633 | if($limit!=0){ |
| 622 | 634 | $stop="if (++timer > ".$limit.") {clearInterval(interval);display.trigger({type:'counter-end',value: timer,limit:".$limit."});}"; |
| 623 | 635 | } |
@@ -30,15 +30,15 @@ discard block |
||
| 30 | 30 | return $this->content; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function addContent($content,$before=false) { |
|
| 33 | + public function addContent($content, $before=false) { |
|
| 34 | 34 | if (!\is_array($this->content)) { |
| 35 | - if(isset($this->content)) |
|
| 36 | - $this->content=array ($this->content); |
|
| 35 | + if (isset($this->content)) |
|
| 36 | + $this->content=array($this->content); |
|
| 37 | 37 | else |
| 38 | 38 | $this->content=array(); |
| 39 | 39 | } |
| 40 | - if($before) |
|
| 41 | - array_unshift($this->content,$content); |
|
| 40 | + if ($before) |
|
| 41 | + array_unshift($this->content, $content); |
|
| 42 | 42 | else |
| 43 | 43 | $this->content []=$content; |
| 44 | 44 | return $this; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | if ($this->content instanceof HtmlDoubleElement) { |
| 54 | 54 | $this->content->run($js); |
| 55 | 55 | } else if (\is_array($this->content)) { |
| 56 | - foreach ( $this->content as $itemContent ) { |
|
| 56 | + foreach ($this->content as $itemContent) { |
|
| 57 | 57 | if ($itemContent instanceof HtmlDoubleElement) { |
| 58 | 58 | $itemContent->run($js); |
| 59 | 59 | } |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | return $this; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function getContentInstances($class){ |
|
| 74 | - return $this->_getContentInstances($class,$this->content); |
|
| 73 | + public function getContentInstances($class) { |
|
| 74 | + return $this->_getContentInstances($class, $this->content); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - protected function _getContentInstances($class,$content){ |
|
| 77 | + protected function _getContentInstances($class, $content) { |
|
| 78 | 78 | $instances=[]; |
| 79 | - if($content instanceof $class){ |
|
| 79 | + if ($content instanceof $class) { |
|
| 80 | 80 | $instances[]=$content; |
| 81 | - }elseif($content instanceof HtmlDoubleElement){ |
|
| 82 | - $instances=\array_merge($instances,$content->getContentInstances($class)); |
|
| 83 | - }elseif (\is_array($content)){ |
|
| 84 | - foreach ($content as $element){ |
|
| 85 | - $instances=\array_merge($instances,$this->_getContentInstances($class, $element)); |
|
| 81 | + }elseif ($content instanceof HtmlDoubleElement) { |
|
| 82 | + $instances=\array_merge($instances, $content->getContentInstances($class)); |
|
| 83 | + }elseif (\is_array($content)) { |
|
| 84 | + foreach ($content as $element) { |
|
| 85 | + $instances=\array_merge($instances, $this->_getContentInstances($class, $element)); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | return $instances; |
@@ -92,36 +92,36 @@ discard block |
||
| 92 | 92 | * Transforms the element into a link |
| 93 | 93 | * @return HtmlDoubleElement |
| 94 | 94 | */ |
| 95 | - public function asLink($href=NULL,$target=NULL) { |
|
| 95 | + public function asLink($href=NULL, $target=NULL) { |
|
| 96 | 96 | if (isset($href)) |
| 97 | 97 | $this->setProperty("href", $href); |
| 98 | - if(isset($target)) |
|
| 98 | + if (isset($target)) |
|
| 99 | 99 | $this->setProperty("target", $target); |
| 100 | 100 | return $this->setTagName("a"); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - public function getTextContent(){ |
|
| 104 | - if(is_array($this->content)){ |
|
| 103 | + public function getTextContent() { |
|
| 104 | + if (is_array($this->content)) { |
|
| 105 | 105 | return strip_tags(implode("", $this->content)); |
| 106 | 106 | } |
| 107 | 107 | return strip_tags($this->content); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function asEditable(HtmlFormField $field,$asForm=false,$setValueProperty="val()"){ |
|
| 110 | + public function asEditable(HtmlFormField $field, $asForm=false, $setValueProperty="val()") { |
|
| 111 | 111 | $idF=$field->getIdentifier(); |
| 112 | 112 | $idE=$idF; |
| 113 | - if($asForm){ |
|
| 113 | + if ($asForm) { |
|
| 114 | 114 | $frm=new HtmlForm("frm-".$field->getIdentifier()); |
| 115 | 115 | $frm->setProperty("onsubmit", "return false;"); |
| 116 | 116 | $fields=$frm->addFields(); |
| 117 | 117 | $idE=$frm->getIdentifier(); |
| 118 | 118 | $fields->addItem($field); |
| 119 | - $fields->addButtonIcon("bt-okay", "check","green mini","\$('#".$idE."').trigger('validate',{value: $('#'+idF+' input').val()});"); |
|
| 120 | - $fields->addButtonIcon("bt-cancel", "close","mini","\$('#".$idE."').trigger('endEdit');"); |
|
| 119 | + $fields->addButtonIcon("bt-okay", "check", "green mini", "\$('#".$idE."').trigger('validate',{value: $('#'+idF+' input').val()});"); |
|
| 120 | + $fields->addButtonIcon("bt-cancel", "close", "mini", "\$('#".$idE."').trigger('endEdit');"); |
|
| 121 | 121 | $this->_editableContent=$frm; |
| 122 | 122 | $keypress=""; |
| 123 | 123 | $focusOut=""; |
| 124 | - }else{ |
|
| 124 | + } else { |
|
| 125 | 125 | $focusOut="if(e.relatedTarget==null)elm.trigger('endEdit');"; |
| 126 | 126 | $this->_editableContent=$field; |
| 127 | 127 | $keypress="$('#".$idF."').keyup(function(e){if(e.which == 13) {\$('#".$idE."').trigger('validate',{value: $('#'+idF+' input').val()});}if(e.keyCode===27) {\$('#".$idE."').trigger('endEdit');}});"; |
@@ -134,11 +134,11 @@ discard block |
||
| 134 | 134 | * {@inheritDoc} |
| 135 | 135 | * @see \Ajax\common\html\BaseHtml::compile_once() |
| 136 | 136 | */ |
| 137 | - protected function compile_once(\Ajax\JsUtils $js = NULL, &$view = NULL) { |
|
| 138 | - if(!$this->_compiled && isset($this->_editableContent)){ |
|
| 139 | - $this->wrap("",$this->_editableContent); |
|
| 137 | + protected function compile_once(\Ajax\JsUtils $js=NULL, &$view=NULL) { |
|
| 138 | + if (!$this->_compiled && isset($this->_editableContent)) { |
|
| 139 | + $this->wrap("", $this->_editableContent); |
|
| 140 | 140 | } |
| 141 | - parent::compile_once($js,$view); |
|
| 141 | + parent::compile_once($js, $view); |
|
| 142 | 142 | |
| 143 | 143 | } |
| 144 | 144 | |
@@ -32,15 +32,17 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | public function addContent($content,$before=false) { |
| 34 | 34 | if (!\is_array($this->content)) { |
| 35 | - if(isset($this->content)) |
|
| 36 | - $this->content=array ($this->content); |
|
| 37 | - else |
|
| 38 | - $this->content=array(); |
|
| 35 | + if(isset($this->content)) { |
|
| 36 | + $this->content=array ($this->content); |
|
| 37 | + } else { |
|
| 38 | + $this->content=array(); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + if($before) { |
|
| 42 | + array_unshift($this->content,$content); |
|
| 43 | + } else { |
|
| 44 | + $this->content []=$content; |
|
| 39 | 45 | } |
| 40 | - if($before) |
|
| 41 | - array_unshift($this->content,$content); |
|
| 42 | - else |
|
| 43 | - $this->content []=$content; |
|
| 44 | 46 | return $this; |
| 45 | 47 | } |
| 46 | 48 | |
@@ -78,9 +80,9 @@ discard block |
||
| 78 | 80 | $instances=[]; |
| 79 | 81 | if($content instanceof $class){ |
| 80 | 82 | $instances[]=$content; |
| 81 | - }elseif($content instanceof HtmlDoubleElement){ |
|
| 83 | + } elseif($content instanceof HtmlDoubleElement){ |
|
| 82 | 84 | $instances=\array_merge($instances,$content->getContentInstances($class)); |
| 83 | - }elseif (\is_array($content)){ |
|
| 85 | + } elseif (\is_array($content)){ |
|
| 84 | 86 | foreach ($content as $element){ |
| 85 | 87 | $instances=\array_merge($instances,$this->_getContentInstances($class, $element)); |
| 86 | 88 | } |
@@ -93,10 +95,12 @@ discard block |
||
| 93 | 95 | * @return HtmlDoubleElement |
| 94 | 96 | */ |
| 95 | 97 | public function asLink($href=NULL,$target=NULL) { |
| 96 | - if (isset($href)) |
|
| 97 | - $this->setProperty("href", $href); |
|
| 98 | - if(isset($target)) |
|
| 99 | - $this->setProperty("target", $target); |
|
| 98 | + if (isset($href)) { |
|
| 99 | + $this->setProperty("href", $href); |
|
| 100 | + } |
|
| 101 | + if(isset($target)) { |
|
| 102 | + $this->setProperty("target", $target); |
|
| 103 | + } |
|
| 100 | 104 | return $this->setTagName("a"); |
| 101 | 105 | } |
| 102 | 106 | |
@@ -121,7 +125,7 @@ discard block |
||
| 121 | 125 | $this->_editableContent=$frm; |
| 122 | 126 | $keypress=""; |
| 123 | 127 | $focusOut=""; |
| 124 | - }else{ |
|
| 128 | + } else{ |
|
| 125 | 129 | $focusOut="if(e.relatedTarget==null)elm.trigger('endEdit');"; |
| 126 | 130 | $this->_editableContent=$field; |
| 127 | 131 | $keypress="$('#".$idF."').keyup(function(e){if(e.which == 13) {\$('#".$idE."').trigger('validate',{value: $('#'+idF+' input').val()});}if(e.keyCode===27) {\$('#".$idE."').trigger('endEdit');}});"; |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @param string $hookKey |
| 10 | 10 | * @return boolean |
| 11 | 11 | */ |
| 12 | - public function hookExists($hookKey){ |
|
| 12 | + public function hookExists($hookKey) { |
|
| 13 | 13 | return isset($this->_hooks[$hookKey]); |
| 14 | 14 | } |
| 15 | 15 | |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | * @param string $hookKey |
| 18 | 18 | * @return callable|NULL |
| 19 | 19 | */ |
| 20 | - public function getHook($hookKey){ |
|
| 21 | - if(isset($this->_hooks[$hookKey])){ |
|
| 20 | + public function getHook($hookKey) { |
|
| 21 | + if (isset($this->_hooks[$hookKey])) { |
|
| 22 | 22 | return $this->_hooks[$hookKey]; |
| 23 | 23 | } |
| 24 | 24 | return null; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param String $hookKey |
| 30 | 30 | * @param callable $callable |
| 31 | 31 | */ |
| 32 | - public function addHook($hookKey,$callable){ |
|
| 32 | + public function addHook($hookKey, $callable) { |
|
| 33 | 33 | $this->_hooks[$hookKey]=$callable; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | * @param mixed|null $variable |
| 40 | 40 | * @return void|mixed |
| 41 | 41 | */ |
| 42 | - public function execHook($hookKey,...$variables){ |
|
| 43 | - if(($hook=$this->getHook($hookKey))!=null){ |
|
| 44 | - return call_user_func_array($hook,$variables); |
|
| 42 | + public function execHook($hookKey, ...$variables) { |
|
| 43 | + if (($hook=$this->getHook($hookKey))!=null) { |
|
| 44 | + return call_user_func_array($hook, $variables); |
|
| 45 | 45 | } |
| 46 | 46 | return; |
| 47 | 47 | } |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Ajax\common\html; |
| 4 | 4 | |
| 5 | -class HtmlContentOnly extends HtmlDoubleElement{ |
|
| 6 | - public function __construct($content,$identifier=""){ |
|
| 5 | +class HtmlContentOnly extends HtmlDoubleElement { |
|
| 6 | + public function __construct($content, $identifier="") { |
|
| 7 | 7 | parent::__construct($identifier); |
| 8 | 8 | $this->_template='%wrapContentBefore%%content%%wrapContentAfter%'; |
| 9 | 9 | $this->setContent($content); |
@@ -21,36 +21,36 @@ discard block |
||
| 21 | 21 | use BaseTrait; |
| 22 | 22 | |
| 23 | 23 | public function __construct($identifier, $modelInstance=NULL) { |
| 24 | - parent::__construct($identifier, null,$modelInstance); |
|
| 24 | + parent::__construct($identifier, null, $modelInstance); |
|
| 25 | 25 | $this->_form=new HtmlForm($identifier); |
| 26 | 26 | $this->_init(new FormInstanceViewer($identifier), "form", $this->_form, true); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
| 29 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
| 30 | 30 | return $this->identifier."-{$name}-".$this->_instanceViewer->getIdentifier(); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 34 | - if(!$this->_generated){ |
|
| 33 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 34 | + if (!$this->_generated) { |
|
| 35 | 35 | $this->_instanceViewer->setInstance($this->_modelInstance); |
| 36 | 36 | |
| 37 | 37 | $form=$this->content["form"]; |
| 38 | 38 | $this->_generateContent($form); |
| 39 | 39 | |
| 40 | - if(isset($this->_toolbar)){ |
|
| 40 | + if (isset($this->_toolbar)) { |
|
| 41 | 41 | $this->_setToolbarPosition($form); |
| 42 | 42 | } |
| 43 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]); |
|
| 43 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "form", PositionInTable::AFTERTABLE]); |
|
| 44 | 44 | $this->_generated=true; |
| 45 | 45 | } |
| 46 | - return parent::compile($js,$view); |
|
| 46 | + return parent::compile($js, $view); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @param HtmlForm $form |
| 51 | 51 | */ |
| 52 | - protected function _generateContent($form){ |
|
| 53 | - $values= $this->_instanceViewer->getValues(); |
|
| 52 | + protected function _generateContent($form) { |
|
| 53 | + $values=$this->_instanceViewer->getValues(); |
|
| 54 | 54 | $count=$this->_instanceViewer->count(); |
| 55 | 55 | $separators=$this->_instanceViewer->getSeparators(); |
| 56 | 56 | $headers=$this->_instanceViewer->getHeaders(); |
@@ -58,41 +58,41 @@ discard block |
||
| 58 | 58 | \sort($separators); |
| 59 | 59 | $size=\sizeof($separators); |
| 60 | 60 | $nb=0; |
| 61 | - if($size===1){ |
|
| 61 | + if ($size===1) { |
|
| 62 | 62 | $i=-1; |
| 63 | - foreach ($values as $v){ |
|
| 64 | - $this->_generateFields($form, [$v], $headers, $i, $wrappers,$nb++); |
|
| 63 | + foreach ($values as $v) { |
|
| 64 | + $this->_generateFields($form, [$v], $headers, $i, $wrappers, $nb++); |
|
| 65 | 65 | $i++; |
| 66 | 66 | } |
| 67 | - }else{ |
|
| 67 | + } else { |
|
| 68 | 68 | $separators[]=$count; |
| 69 | - for($i=0;$i<$size;$i++){ |
|
| 70 | - $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
|
| 71 | - $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers,$nb++); |
|
| 69 | + for ($i=0; $i<$size; $i++) { |
|
| 70 | + $fields=\array_slice($values, $separators[$i]+1, $separators[$i+1]-$separators[$i]); |
|
| 71 | + $this->_generateFields($form, $fields, $headers, $separators[$i], $wrappers, $nb++); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | - if($this->_hasRules && !$this->getForm()->hasValidationParams()){ |
|
| 74 | + if ($this->_hasRules && !$this->getForm()->hasValidationParams()) { |
|
| 75 | 75 | $this->setValidationParams(["inline"=>true]); |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - protected function _generateFields($form,$values,$headers,$sepFirst,$wrappers,$nb){ |
|
| 79 | + protected function _generateFields($form, $values, $headers, $sepFirst, $wrappers, $nb) { |
|
| 80 | 80 | $wrapper=null; |
| 81 | - if(isset($headers[$sepFirst+1])) |
|
| 82 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
| 83 | - if(isset($wrappers[$sepFirst+1])){ |
|
| 81 | + if (isset($headers[$sepFirst+1])) |
|
| 82 | + $form->addHeader($headers[$sepFirst+1], 4, true); |
|
| 83 | + if (isset($wrappers[$sepFirst+1])) { |
|
| 84 | 84 | $wrapper=$wrappers[$sepFirst+1]; |
| 85 | 85 | } |
| 86 | - if(\sizeof($values)===1){ |
|
| 86 | + if (\sizeof($values)===1) { |
|
| 87 | 87 | $added=$form->addField($values[0]); |
| 88 | - }elseif(\sizeof($values)>1){ |
|
| 88 | + }elseif (\sizeof($values)>1) { |
|
| 89 | 89 | $added=$form->addFields($values); |
| 90 | - }else |
|
| 90 | + } else |
|
| 91 | 91 | return; |
| 92 | - if(isset($wrapper)){ |
|
| 93 | - $added->wrap($wrapper[0],$wrapper[1]); |
|
| 92 | + if (isset($wrapper)) { |
|
| 93 | + $added->wrap($wrapper[0], $wrapper[1]); |
|
| 94 | 94 | } |
| 95 | - $this->execHook("onGenerateFields",$added,$nb); |
|
| 95 | + $this->execHook("onGenerateFields", $added, $nb); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -100,18 +100,18 @@ discard block |
||
| 100 | 100 | * the generated field is the first parameter |
| 101 | 101 | * @param callable $callback the fonction to call when a field is generated |
| 102 | 102 | */ |
| 103 | - public function onGenerateField($callback){ |
|
| 104 | - $this->addHook("onGenerateFields",$callback); |
|
| 103 | + public function onGenerateField($callback) { |
|
| 104 | + $this->addHook("onGenerateFields", $callback); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @return HtmlForm |
| 109 | 109 | */ |
| 110 | - public function getForm(){ |
|
| 110 | + public function getForm() { |
|
| 111 | 111 | return $this->content["form"]; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public function addSeparatorAfter($fieldNum){ |
|
| 114 | + public function addSeparatorAfter($fieldNum) { |
|
| 115 | 115 | $fieldNum=$this->_getIndex($fieldNum); |
| 116 | 116 | $this->_instanceViewer->addSeparatorAfter($fieldNum); |
| 117 | 117 | return $this; |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | return $this; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - public function fieldAsReset($index,$cssStyle=NULL,$attributes=NULL){ |
|
| 130 | - return $this->_fieldAs(function($id,$name,$value) use ($cssStyle){ |
|
| 131 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 129 | + public function fieldAsReset($index, $cssStyle=NULL, $attributes=NULL) { |
|
| 130 | + return $this->_fieldAs(function($id, $name, $value) use ($cssStyle){ |
|
| 131 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 132 | 132 | $button->setProperty("type", "reset"); |
| 133 | 133 | return $button; |
| 134 | - }, $index,$attributes); |
|
| 134 | + }, $index, $attributes); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -150,19 +150,19 @@ discard block |
||
| 150 | 150 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - public function addDividerBefore($index,$title){ |
|
| 153 | + public function addDividerBefore($index, $title) { |
|
| 154 | 154 | $index=$this->_getIndex($index); |
| 155 | 155 | $this->_instanceViewer->addHeaderDividerBefore($index, $title); |
| 156 | 156 | return $this; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function addWrapper($index,$contentBefore,$contentAfter=null){ |
|
| 159 | + public function addWrapper($index, $contentBefore, $contentAfter=null) { |
|
| 160 | 160 | $index=$this->_getIndex($index); |
| 161 | - $this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter); |
|
| 161 | + $this->_instanceViewer->addWrapper($index, $contentBefore, $contentAfter); |
|
| 162 | 162 | return $this; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - public function run(JsUtils $js){ |
|
| 165 | + public function run(JsUtils $js) { |
|
| 166 | 166 | parent::run($js); |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $this->_generateFields($form, [$v], $headers, $i, $wrappers,$nb++); |
| 65 | 65 | $i++; |
| 66 | 66 | } |
| 67 | - }else{ |
|
| 67 | + } else{ |
|
| 68 | 68 | $separators[]=$count; |
| 69 | 69 | for($i=0;$i<$size;$i++){ |
| 70 | 70 | $fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]); |
@@ -78,17 +78,19 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | protected function _generateFields($form,$values,$headers,$sepFirst,$wrappers,$nb){ |
| 80 | 80 | $wrapper=null; |
| 81 | - if(isset($headers[$sepFirst+1])) |
|
| 82 | - $form->addHeader($headers[$sepFirst+1],4,true); |
|
| 81 | + if(isset($headers[$sepFirst+1])) { |
|
| 82 | + $form->addHeader($headers[$sepFirst+1],4,true); |
|
| 83 | + } |
|
| 83 | 84 | if(isset($wrappers[$sepFirst+1])){ |
| 84 | 85 | $wrapper=$wrappers[$sepFirst+1]; |
| 85 | 86 | } |
| 86 | 87 | if(\sizeof($values)===1){ |
| 87 | 88 | $added=$form->addField($values[0]); |
| 88 | - }elseif(\sizeof($values)>1){ |
|
| 89 | + } elseif(\sizeof($values)>1){ |
|
| 89 | 90 | $added=$form->addFields($values); |
| 90 | - }else |
|
| 91 | - return; |
|
| 91 | + } else { |
|
| 92 | + return; |
|
| 93 | + } |
|
| 92 | 94 | if(isset($wrapper)){ |
| 93 | 95 | $added->wrap($wrapper[0],$wrapper[1]); |
| 94 | 96 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | abstract public function addToProperty($name, $value, $separator=" "); |
| 21 | 21 | abstract public function addLabel($caption, $style="label-default", $leftSeparator=" "); |
| 22 | - abstract public function addContent($content,$before=false); |
|
| 22 | + abstract public function addContent($content, $before=false); |
|
| 23 | 23 | abstract public function getField(); |
| 24 | 24 | abstract public function getDataField(); |
| 25 | 25 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function addLoading() { |
| 31 | - if ($this->_hasIcon === false) { |
|
| 31 | + if ($this->_hasIcon===false) { |
|
| 32 | 32 | throw new \Exception("Input must have an icon for showing a loader, use addIcon before"); |
| 33 | 33 | } |
| 34 | 34 | return $this->addToProperty("class", State::LOADING); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function labeled($label, $direction=Direction::LEFT, $icon=NULL) { |
| 44 | 44 | $field=$this->getField(); |
| 45 | - $labelO=$field->addLabel($label,$direction===Direction::LEFT,$icon); |
|
| 46 | - $field->addToProperty("class", $direction . " labeled"); |
|
| 45 | + $labelO=$field->addLabel($label, $direction===Direction::LEFT, $icon); |
|
| 46 | + $field->addToProperty("class", $direction." labeled"); |
|
| 47 | 47 | return $labelO; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @param string $checkboxType |
| 55 | 55 | * @return HtmlLabel |
| 56 | 56 | */ |
| 57 | - public function labeledCheckbox($direction=Direction::LEFT,$caption="",$value=NULL,$checkboxType=NULL){ |
|
| 58 | - return $this->labeled(new HtmlCheckbox("lbl-ck-".$this->getField()->getIdentifier(),$caption,$value,$checkboxType),$direction); |
|
| 57 | + public function labeledCheckbox($direction=Direction::LEFT, $caption="", $value=NULL, $checkboxType=NULL) { |
|
| 58 | + return $this->labeled(new HtmlCheckbox("lbl-ck-".$this->getField()->getIdentifier(), $caption, $value, $checkboxType), $direction); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return HtmlLabel |
| 65 | 65 | */ |
| 66 | 66 | public function labeledToCorner($icon, $direction=Direction::LEFT) { |
| 67 | - return $this->labeled("", $direction . " corner", $icon)->toCorner($direction); |
|
| 67 | + return $this->labeled("", $direction." corner", $icon)->toCorner($direction); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | public function addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false) { |
| 78 | 78 | $field=$this->getField(); |
| 79 | 79 | $actionO=$action; |
| 80 | - if (\is_object($action) === false) { |
|
| 81 | - $actionO=new HtmlButton("action-" . $this->identifier, $action); |
|
| 80 | + if (\is_object($action)===false) { |
|
| 81 | + $actionO=new HtmlButton("action-".$this->identifier, $action); |
|
| 82 | 82 | if (isset($icon)) |
| 83 | 83 | $actionO->addIcon($icon, true, $labeled); |
| 84 | 84 | } |
| 85 | - $field->addToProperty("class", $direction . " action"); |
|
| 86 | - $field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false); |
|
| 85 | + $field->addToProperty("class", $direction." action"); |
|
| 86 | + $field->addContent($actionO, \strstr($direction, Direction::LEFT)!==false); |
|
| 87 | 87 | return $actionO; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -93,50 +93,50 @@ discard block |
||
| 93 | 93 | * @param string $direction |
| 94 | 94 | * @return HtmlLabel |
| 95 | 95 | */ |
| 96 | - public function addDropdown($label="", $items=array(),$direction=Direction::RIGHT){ |
|
| 97 | - $labelO=new HtmlDropdown("dd-".$this->identifier,$label,$items); |
|
| 98 | - $labelO->asSelect("select-".$this->identifier,false,true); |
|
| 99 | - return $this->labeled($labelO,$direction); |
|
| 96 | + public function addDropdown($label="", $items=array(), $direction=Direction::RIGHT) { |
|
| 97 | + $labelO=new HtmlDropdown("dd-".$this->identifier, $label, $items); |
|
| 98 | + $labelO->asSelect("select-".$this->identifier, false, true); |
|
| 99 | + return $this->labeled($labelO, $direction); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function setTransparent() { |
| 103 | 103 | return $this->getField()->addToProperty("class", "transparent"); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - public function setReadonly(){ |
|
| 106 | + public function setReadonly() { |
|
| 107 | 107 | $this->getDataField()->setProperty("readonly", ""); |
| 108 | 108 | return $this; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - public function setName($name){ |
|
| 112 | - $this->getDataField()->setProperty("name",$name); |
|
| 111 | + public function setName($name) { |
|
| 112 | + $this->getDataField()->setProperty("name", $name); |
|
| 113 | 113 | return $this; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - public function setFluid(){ |
|
| 117 | - $this->getField()->addToProperty("class","fluid"); |
|
| 116 | + public function setFluid() { |
|
| 117 | + $this->getField()->addToProperty("class", "fluid"); |
|
| 118 | 118 | return $this; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | public function setDisabled($disable=true) { |
| 122 | 122 | $field=$this->getField(); |
| 123 | - if($disable) |
|
| 123 | + if ($disable) |
|
| 124 | 124 | $field->addToProperty("class", "disabled"); |
| 125 | 125 | return $this; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public function setJsContent($content){ |
|
| 128 | + public function setJsContent($content) { |
|
| 129 | 129 | $id=""; |
| 130 | 130 | $field=$this->getDataField(); |
| 131 | - if(isset($field)){ |
|
| 131 | + if (isset($field)) { |
|
| 132 | 132 | $id=$field->getIdentifier(); |
| 133 | 133 | } |
| 134 | - if($id!==''){ |
|
| 134 | + if ($id!=='') { |
|
| 135 | 135 | return '$("#'.$id.'").val('.$content.')'; |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - public function getJsContent(){ |
|
| 139 | + public function getJsContent() { |
|
| 140 | 140 | return $this->setJsContent(""); |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -79,8 +79,9 @@ discard block |
||
| 79 | 79 | $actionO=$action; |
| 80 | 80 | if (\is_object($action) === false) { |
| 81 | 81 | $actionO=new HtmlButton("action-" . $this->identifier, $action); |
| 82 | - if (isset($icon)) |
|
| 83 | - $actionO->addIcon($icon, true, $labeled); |
|
| 82 | + if (isset($icon)) { |
|
| 83 | + $actionO->addIcon($icon, true, $labeled); |
|
| 84 | + } |
|
| 84 | 85 | } |
| 85 | 86 | $field->addToProperty("class", $direction . " action"); |
| 86 | 87 | $field->addContent($actionO, \strstr($direction, Direction::LEFT) !== false); |
@@ -120,8 +121,9 @@ discard block |
||
| 120 | 121 | |
| 121 | 122 | public function setDisabled($disable=true) { |
| 122 | 123 | $field=$this->getField(); |
| 123 | - if($disable) |
|
| 124 | - $field->addToProperty("class", "disabled"); |
|
| 124 | + if($disable) { |
|
| 125 | + $field->addToProperty("class", "disabled"); |
|
| 126 | + } |
|
| 125 | 127 | return $this; |
| 126 | 128 | } |
| 127 | 129 | |
@@ -20,35 +20,35 @@ discard block |
||
| 20 | 20 | * @property string $identifier |
| 21 | 21 | */ |
| 22 | 22 | trait FieldsTrait { |
| 23 | - abstract public function addFields($fields=NULL,$label=NULL); |
|
| 23 | + abstract public function addFields($fields=NULL, $label=NULL); |
|
| 24 | 24 | abstract public function addItem($item); |
| 25 | 25 | abstract public function getItem($index); |
| 26 | 26 | abstract public function count(); |
| 27 | 27 | |
| 28 | - protected function createItem($value){ |
|
| 29 | - if(\is_array($value)){ |
|
| 30 | - $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
|
| 28 | + protected function createItem($value) { |
|
| 29 | + if (\is_array($value)) { |
|
| 30 | + $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id", ""), JArray::getDefaultValue($value, "label", null), JArray::getDefaultValue($value, "type", "text"), JArray::getDefaultValue($value, "value", ""), JArray::getDefaultValue($value, "placeholder", JArray::getDefaultValue($value, "label", null))); |
|
| 31 | 31 | return $itemO; |
| 32 | - }elseif(\is_object($value)){ |
|
| 32 | + }elseif (\is_object($value)) { |
|
| 33 | 33 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
| 34 | 34 | return $itemO; |
| 35 | - }else |
|
| 35 | + } else |
|
| 36 | 36 | return new HtmlFormInput($value); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - protected function createCondition($value){ |
|
| 39 | + protected function createCondition($value) { |
|
| 40 | 40 | return \is_object($value)===false || $value instanceof \Ajax\semantic\html\elements\HtmlInput; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function addInputs($inputs,$fieldslabel=null){ |
|
| 43 | + public function addInputs($inputs, $fieldslabel=null) { |
|
| 44 | 44 | $fields=array(); |
| 45 | - foreach ($inputs as $input){ |
|
| 45 | + foreach ($inputs as $input) { |
|
| 46 | 46 | \extract($input); |
| 47 | - $f=new HtmlFormInput("",""); |
|
| 47 | + $f=new HtmlFormInput("", ""); |
|
| 48 | 48 | $f->fromArray($input); |
| 49 | 49 | $fields[]=$f; |
| 50 | 50 | } |
| 51 | - return $this->addFields($fields,$fieldslabel); |
|
| 51 | + return $this->addFields($fields, $fieldslabel); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,35 +57,35 @@ discard block |
||
| 57 | 57 | * @param array|mixed $values |
| 58 | 58 | * @return HtmlFormFields |
| 59 | 59 | */ |
| 60 | - public function setFieldsPropertyValues($property,$values){ |
|
| 60 | + public function setFieldsPropertyValues($property, $values) { |
|
| 61 | 61 | $i=0; |
| 62 | - if(\is_array($values)===false){ |
|
| 63 | - $values=\array_fill(0, $this->count(),$values); |
|
| 62 | + if (\is_array($values)===false) { |
|
| 63 | + $values=\array_fill(0, $this->count(), $values); |
|
| 64 | 64 | } |
| 65 | - foreach ($values as $value){ |
|
| 65 | + foreach ($values as $value) { |
|
| 66 | 66 | $c=$this->content[$i++]; |
| 67 | - if(isset($c)){ |
|
| 67 | + if (isset($c)) { |
|
| 68 | 68 | $df=$c->getDataField(); |
| 69 | - $df->setProperty($property,$value); |
|
| 69 | + $df->setProperty($property, $value); |
|
| 70 | 70 | } |
| 71 | - else{ |
|
| 71 | + else { |
|
| 72 | 72 | return $this; |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | return $this; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function addFieldRule($index,$type,$prompt=NULL,$value=NULL){ |
|
| 78 | + public function addFieldRule($index, $type, $prompt=NULL, $value=NULL) { |
|
| 79 | 79 | $field=$this->getItem($index); |
| 80 | - if(isset($field)){ |
|
| 81 | - $field->addRule($type,$prompt,$value); |
|
| 80 | + if (isset($field)) { |
|
| 81 | + $field->addRule($type, $prompt, $value); |
|
| 82 | 82 | } |
| 83 | 83 | return $this; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function addFieldRules($index,$rules){ |
|
| 86 | + public function addFieldRules($index, $rules) { |
|
| 87 | 87 | $field=$this->getItem($index); |
| 88 | - if(isset($field)){ |
|
| 88 | + if (isset($field)) { |
|
| 89 | 89 | $field->addRules($rules); |
| 90 | 90 | } |
| 91 | 91 | return $this; |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | * @param boolean $multiple |
| 101 | 101 | * @return HtmlFormDropdown |
| 102 | 102 | */ |
| 103 | - public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){ |
|
| 104 | - return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple)); |
|
| 103 | + public function addDropdown($identifier, $items=array(), $label=NULL, $value=NULL, $multiple=false) { |
|
| 104 | + return $this->addItem(new HtmlFormDropdown($identifier, $items, $label, $value, $multiple)); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | * @param boolean $asIcons |
| 112 | 112 | * @return HtmlButtonGroups |
| 113 | 113 | */ |
| 114 | - public function addButtonGroups($identifier,$elements=[],$asIcons=false){ |
|
| 115 | - return $this->addItem(new HtmlButtonGroups($identifier,$elements,$asIcons)); |
|
| 114 | + public function addButtonGroups($identifier, $elements=[], $asIcons=false) { |
|
| 115 | + return $this->addItem(new HtmlButtonGroups($identifier, $elements, $asIcons)); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @param string $icon |
| 125 | 125 | * @return HtmlButtonGroups |
| 126 | 126 | */ |
| 127 | - public function addDropdownButton($identifier,$value,$items=[],$asCombo=false,$icon=null){ |
|
| 128 | - return $this->addItem(HtmlButton::dropdown($identifier, $value,$items,$asCombo,$icon)); |
|
| 127 | + public function addDropdownButton($identifier, $value, $items=[], $asCombo=false, $icon=null) { |
|
| 128 | + return $this->addItem(HtmlButton::dropdown($identifier, $value, $items, $asCombo, $icon)); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * @param string $placeholder |
| 137 | 137 | * @return HtmlFormInput |
| 138 | 138 | */ |
| 139 | - public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){ |
|
| 140 | - return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder)); |
|
| 139 | + public function addInput($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL) { |
|
| 140 | + return $this->addItem(new HtmlFormInput($identifier, $label, $type, $value, $placeholder)); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -148,22 +148,22 @@ discard block |
||
| 148 | 148 | * @param int $rows |
| 149 | 149 | * @return HtmlTextarea |
| 150 | 150 | */ |
| 151 | - public function addTextarea($identifier, $label,$value=NULL,$placeholder=NULL,$rows=5){ |
|
| 152 | - return $this->addItem(new HtmlFormTextarea($identifier,$label,$value,$placeholder,$rows)); |
|
| 151 | + public function addTextarea($identifier, $label, $value=NULL, $placeholder=NULL, $rows=5) { |
|
| 152 | + return $this->addItem(new HtmlFormTextarea($identifier, $label, $value, $placeholder, $rows)); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - public function addPassword($identifier, $label=NULL){ |
|
| 156 | - return $this->addItem(new HtmlFormInput($identifier,$label,"password","","")); |
|
| 155 | + public function addPassword($identifier, $label=NULL) { |
|
| 156 | + return $this->addItem(new HtmlFormInput($identifier, $label, "password", "", "")); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){ |
|
| 160 | - return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick)); |
|
| 159 | + public function addButton($identifier, $value, $cssStyle=NULL, $onClick=NULL) { |
|
| 160 | + return $this->addItem(new HtmlButton($identifier, $value, $cssStyle, $onClick)); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - public function addButtonIcon($identifier,$icon,$cssStyle=NULL,$onClick=NULL){ |
|
| 163 | + public function addButtonIcon($identifier, $icon, $cssStyle=NULL, $onClick=NULL) { |
|
| 164 | 164 | $bt=new HtmlButton($identifier); |
| 165 | 165 | $bt->asIcon($icon); |
| 166 | - if(isset($onClick)) |
|
| 166 | + if (isset($onClick)) |
|
| 167 | 167 | $bt->onClick($onClick); |
| 168 | 168 | if (isset($cssStyle)) |
| 169 | 169 | $bt->addClass($cssStyle); |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | * @param string $type |
| 178 | 178 | * @return HtmlFormCheckbox |
| 179 | 179 | */ |
| 180 | - public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){ |
|
| 181 | - return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type)); |
|
| 180 | + public function addCheckbox($identifier, $label=NULL, $value=NULL, $type=NULL) { |
|
| 181 | + return $this->addItem(new HtmlFormCheckbox($identifier, $label, $value, $type)); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function addRadio($identifier, $name,$label=NULL,$value=NULL){ |
|
| 185 | - return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value)); |
|
| 184 | + public function addRadio($identifier, $name, $label=NULL, $value=NULL) { |
|
| 185 | + return $this->addItem(new HtmlFormRadio($identifier, $name, $label, $value)); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - public function addElement($identifier,$content,$label,$tagName="div",$baseClass=""){ |
|
| 189 | - $div=new HtmlSemDoubleElement($identifier,$tagName,$baseClass,$content); |
|
| 190 | - return $this->addItem(new HtmlFormField("field-".$identifier, $div,$label)); |
|
| 188 | + public function addElement($identifier, $content, $label, $tagName="div", $baseClass="") { |
|
| 189 | + $div=new HtmlSemDoubleElement($identifier, $tagName, $baseClass, $content); |
|
| 190 | + return $this->addItem(new HtmlFormField("field-".$identifier, $div, $label)); |
|
| 191 | 191 | } |
| 192 | 192 | } |
@@ -29,11 +29,12 @@ discard block |
||
| 29 | 29 | if(\is_array($value)){ |
| 30 | 30 | $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
| 31 | 31 | return $itemO; |
| 32 | - }elseif(\is_object($value)){ |
|
| 32 | + } elseif(\is_object($value)){ |
|
| 33 | 33 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
| 34 | 34 | return $itemO; |
| 35 | - }else |
|
| 36 | - return new HtmlFormInput($value); |
|
| 35 | + } else { |
|
| 36 | + return new HtmlFormInput($value); |
|
| 37 | + } |
|
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | protected function createCondition($value){ |
@@ -67,8 +68,7 @@ discard block |
||
| 67 | 68 | if(isset($c)){ |
| 68 | 69 | $df=$c->getDataField(); |
| 69 | 70 | $df->setProperty($property,$value); |
| 70 | - } |
|
| 71 | - else{ |
|
| 71 | + } else{ |
|
| 72 | 72 | return $this; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -163,10 +163,12 @@ discard block |
||
| 163 | 163 | public function addButtonIcon($identifier,$icon,$cssStyle=NULL,$onClick=NULL){ |
| 164 | 164 | $bt=new HtmlButton($identifier); |
| 165 | 165 | $bt->asIcon($icon); |
| 166 | - if(isset($onClick)) |
|
| 167 | - $bt->onClick($onClick); |
|
| 168 | - if (isset($cssStyle)) |
|
| 169 | - $bt->addClass($cssStyle); |
|
| 166 | + if(isset($onClick)) { |
|
| 167 | + $bt->onClick($onClick); |
|
| 168 | + } |
|
| 169 | + if (isset($cssStyle)) { |
|
| 170 | + $bt->addClass($cssStyle); |
|
| 171 | + } |
|
| 170 | 172 | return $this->addItem($bt); |
| 171 | 173 | } |
| 172 | 174 | |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
| 19 | 19 | |
| 20 | 20 | abstract public function getUrl($url); |
| 21 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
| 22 | - abstract public function interval($jsCode,$time,$globalName=null,$immediatly=true); |
|
| 21 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 22 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
| 23 | 23 | |
| 24 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
| 25 | - if(isset($this->params["ajax"])){ |
|
| 24 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 25 | + if (isset($this->params["ajax"])) { |
|
| 26 | 26 | extract($this->params["ajax"]); |
| 27 | 27 | } |
| 28 | 28 | extract($parameters); |
@@ -32,121 +32,121 @@ discard block |
||
| 32 | 32 | $originalSelector=$responseElement; |
| 33 | 33 | $responseElement=$this->_getResponseElement($responseElement); |
| 34 | 34 | $retour.="var self=this;\n"; |
| 35 | - $before=isset($before)?$before:""; |
|
| 35 | + $before=isset($before) ? $before : ""; |
|
| 36 | 36 | $retour.=$before; |
| 37 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
| 38 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
| 39 | - }elseif($hasLoader==="internal"){ |
|
| 37 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 38 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 39 | + }elseif ($hasLoader==="internal") { |
|
| 40 | 40 | $retour.="\n$(this).addClass('loading');"; |
| 41 | 41 | } |
| 42 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
| 42 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
| 43 | 43 | |
| 44 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
| 44 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 45 | 45 | |
| 46 | - if(isset($params)){ |
|
| 47 | - $ajaxParameters["data"]=self::_correctParams($params,$parameters); |
|
| 46 | + if (isset($params)) { |
|
| 47 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
| 48 | 48 | } |
| 49 | - if(isset($headers)){ |
|
| 49 | + if (isset($headers)) { |
|
| 50 | 50 | $ajaxParameters["headers"]=$headers; |
| 51 | 51 | } |
| 52 | 52 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
| 54 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
| 55 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
| 54 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 55 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 56 | 56 | if ($immediatly) |
| 57 | 57 | $this->jquery_code_for_compile[]=$retour; |
| 58 | 58 | return $retour; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - protected function createAjaxParameters(&$original,$parameters){ |
|
| 62 | - $validParameters=["contentType"=>"%value%","dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
| 63 | - foreach ($validParameters as $param=>$mask){ |
|
| 64 | - if(isset($parameters[$param])){ |
|
| 61 | + protected function createAjaxParameters(&$original, $parameters) { |
|
| 62 | + $validParameters=["contentType"=>"%value%", "dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
| 63 | + foreach ($validParameters as $param=>$mask) { |
|
| 64 | + if (isset($parameters[$param])) { |
|
| 65 | 65 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
| 71 | - $s = ''; |
|
| 70 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
| 71 | + $s=''; |
|
| 72 | 72 | foreach ($ajaxParameters as $k=>$v) { |
| 73 | - if ($s !== '') { |
|
| 74 | - $s .= ','; |
|
| 73 | + if ($s!=='') { |
|
| 74 | + $s.=','; |
|
| 75 | 75 | } |
| 76 | - if(is_array($v)){ |
|
| 77 | - $s .= "'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 78 | - }else{ |
|
| 79 | - $s .= "'{$k}':{$v}"; |
|
| 76 | + if (is_array($v)) { |
|
| 77 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 78 | + } else { |
|
| 79 | + $s.="'{$k}':{$v}"; |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | return $s; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
| 86 | - if(isset($jsCondition)){ |
|
| 85 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
| 86 | + if (isset($jsCondition)) { |
|
| 87 | 87 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
| 88 | 88 | } |
| 89 | 89 | return $jsSource; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | - protected function _getAjaxUrl($url,$attr){ |
|
| 93 | + protected function _getAjaxUrl($url, $attr) { |
|
| 94 | 94 | $url=$this->_correctAjaxUrl($url); |
| 95 | 95 | $retour="url='".$url."';"; |
| 96 | 96 | $slash="/"; |
| 97 | - if(JString::endswith($url, "/")===true){ |
|
| 97 | + if (JString::endswith($url, "/")===true) { |
|
| 98 | 98 | $slash=""; |
| 99 | 99 | } |
| 100 | - if(JString::isNotNull($attr)){ |
|
| 101 | - if ($attr==="value"){ |
|
| 100 | + if (JString::isNotNull($attr)) { |
|
| 101 | + if ($attr==="value") { |
|
| 102 | 102 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 103 | - }elseif ($attr==="html"){ |
|
| 103 | + }elseif ($attr==="html") { |
|
| 104 | 104 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 105 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
| 105 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
| 106 | 106 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
| 107 | - }elseif($attr!==null && $attr!=="") |
|
| 107 | + }elseif ($attr!==null && $attr!=="") |
|
| 108 | 108 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
| 109 | 109 | } |
| 110 | 110 | return $retour; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - protected function onPopstate(){ |
|
| 113 | + protected function onPopstate() { |
|
| 114 | 114 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - protected function autoActiveLinks($previousURL="window.location.href"){ |
|
| 118 | - $result= "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 117 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 118 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 119 | 119 | $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
| 120 | 120 | return $result; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
| 124 | - $retour="";$call=null; |
|
| 123 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 124 | + $retour=""; $call=null; |
|
| 125 | 125 | if (JString::isNotNull($responseElement)) { |
| 126 | - if(isset($ajaxTransition)){ |
|
| 126 | + if (isset($ajaxTransition)) { |
|
| 127 | 127 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 128 | - }elseif(isset($this->ajaxTransition)){ |
|
| 128 | + }elseif (isset($this->ajaxTransition)) { |
|
| 129 | 129 | $call=$this->ajaxTransition; |
| 130 | 130 | } |
| 131 | - if(\is_callable($call)) |
|
| 132 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 131 | + if (\is_callable($call)) |
|
| 132 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 133 | 133 | else |
| 134 | 134 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
| 135 | 135 | } |
| 136 | - if(isset($history)){ |
|
| 137 | - if($this->params["autoActiveLinks"]){ |
|
| 136 | + if (isset($history)) { |
|
| 137 | + if ($this->params["autoActiveLinks"]) { |
|
| 138 | 138 | $retour.=$this->autoActiveLinks("url"); |
| 139 | 139 | } |
| 140 | 140 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
| 141 | 141 | } |
| 142 | - if($hasLoader==="internal"){ |
|
| 142 | + if ($hasLoader==="internal") { |
|
| 143 | 143 | $retour.="\n$(self).removeClass('loading');"; |
| 144 | 144 | } |
| 145 | 145 | $retour.="\t".$jsCallback."\n"; |
| 146 | 146 | return $retour; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - protected function _getResponseElement($responseElement){ |
|
| 149 | + protected function _getResponseElement($responseElement) { |
|
| 150 | 150 | if (JString::isNotNull($responseElement)) { |
| 151 | 151 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
| 152 | 152 | } |
@@ -156,37 +156,37 @@ discard block |
||
| 156 | 156 | protected function _correctAjaxUrl($url) { |
| 157 | 157 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
| 158 | 158 | $url=substr($url, 0, strlen($url)-1); |
| 159 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
| 159 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 160 | 160 | $url=$this->getUrl($url); |
| 161 | 161 | } |
| 162 | 162 | return $url; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - public static function _correctParams($params,$ajaxParameters=[]){ |
|
| 166 | - if(JString::isNull($params)){ |
|
| 165 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 166 | + if (JString::isNull($params)) { |
|
| 167 | 167 | return ""; |
| 168 | 168 | } |
| 169 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
| 170 | - if( !isset($ajaxParameters['contentType'])|| !UString::contains('json', $ajaxParameters['contentType'])){ |
|
| 169 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
| 170 | + if (!isset($ajaxParameters['contentType']) || !UString::contains('json', $ajaxParameters['contentType'])) { |
|
| 171 | 171 | return '$.param('.$params.')'; |
| 172 | - }else{ |
|
| 172 | + } else { |
|
| 173 | 173 | return 'JSON.stringify('.$params.')'; |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | return $params; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - public static function _implodeParams($parameters){ |
|
| 179 | + public static function _implodeParams($parameters) { |
|
| 180 | 180 | $allParameters=[]; |
| 181 | - foreach ($parameters as $params){ |
|
| 182 | - if(isset($params)) |
|
| 181 | + foreach ($parameters as $params) { |
|
| 182 | + if (isset($params)) |
|
| 183 | 183 | $allParameters[]=self::_correctParams($params); |
| 184 | 184 | } |
| 185 | 185 | return \implode("+'&'+", $allParameters); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
| 189 | - if(!isset($ajaxLoader)){ |
|
| 188 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 189 | + if (!isset($ajaxLoader)) { |
|
| 190 | 190 | $ajaxLoader=$this->ajaxLoader; |
| 191 | 191 | } |
| 192 | 192 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -194,19 +194,19 @@ discard block |
||
| 194 | 194 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - protected function setAjaxDataCall($params){ |
|
| 197 | + protected function setAjaxDataCall($params) { |
|
| 198 | 198 | $result=null; |
| 199 | - if(!\is_callable($params)){ |
|
| 200 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
| 201 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
| 199 | + if (!\is_callable($params)) { |
|
| 200 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
| 201 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
| 202 | 202 | }; |
| 203 | 203 | } |
| 204 | 204 | return $result; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - protected function setDefaultParameters(&$parameters,$default){ |
|
| 208 | - foreach ($default as $k=>$v){ |
|
| 209 | - if(!isset($parameters[$k])) |
|
| 207 | + protected function setDefaultParameters(&$parameters, $default) { |
|
| 208 | + foreach ($default as $k=>$v) { |
|
| 209 | + if (!isset($parameters[$k])) |
|
| 210 | 210 | $parameters[$k]=$v; |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | * @param string $url The url of the request |
| 221 | 221 | * @param string $responseElement selector of the HTML element displaying the answer |
| 222 | 222 | */ |
| 223 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
| 224 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
| 223 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
| 224 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | * @param string $responseElement selector of the HTML element displaying the answer |
| 231 | 231 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
| 232 | 232 | */ |
| 233 | - public function get($url, $responseElement="",$parameters=[]) { |
|
| 233 | + public function get($url, $responseElement="", $parameters=[]) { |
|
| 234 | 234 | $parameters["immediatly"]=true; |
| 235 | - return $this->_get($url,$responseElement,$parameters); |
|
| 235 | + return $this->_get($url, $responseElement, $parameters); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | * @param string $responseElement selector of the HTML element displaying the answer |
| 243 | 243 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
| 244 | 244 | */ |
| 245 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
| 245 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 246 | 246 | $parameters["immediatly"]=true; |
| 247 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
| 247 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | * @param array $parameters The ajax parameters, default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | - public function ajaxInterval($method,$url, $interval,$globalName=null,$responseElement="", $parameters=[]){ |
|
| 261 | - return $this->interval($this->ajaxDeferred($method, $url,$responseElement,$parameters), $interval,$globalName); |
|
| 260 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[]) { |
|
| 261 | + return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * @param string $responseElement selector of the HTML element displaying the answer |
| 269 | 269 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
| 270 | 270 | */ |
| 271 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
| 271 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
| 272 | 272 | $parameters["immediatly"]=false; |
| 273 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
| 273 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | * @param string $method Method used |
| 280 | 280 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
| 281 | 281 | */ |
| 282 | - private function _json($url, $method="get",$parameters=[]) { |
|
| 283 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
| 282 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 283 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
| 284 | 284 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
| 285 | 285 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
| 286 | 286 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";" |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
| 289 | 289 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 290 | 290 | $parameters["jsCallback"]=$retour; |
| 291 | - return $this->_ajax($method, $url,null,$parameters); |
|
| 291 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
| 299 | 299 | */ |
| 300 | 300 | public function json($url, $method="get", $parameters=[]) { |
| 301 | - return $this->_json($url,$method,$parameters); |
|
| 301 | + return $this->_json($url, $method, $parameters); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | * @param string $method default get |
| 310 | 310 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
| 311 | 311 | */ |
| 312 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
| 313 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 314 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 312 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
| 313 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 314 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
| 324 | 324 | $parameters["immediatly"]=false; |
| 325 | - return $this->_json($url,$method,$parameters); |
|
| 325 | + return $this->_json($url, $method, $parameters); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -333,27 +333,27 @@ discard block |
||
| 333 | 333 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
| 334 | 334 | */ |
| 335 | 335 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
| 336 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
| 336 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
| 337 | 337 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
| 338 | 338 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
| 339 | 339 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
| 340 | - if($context===null){ |
|
| 340 | + if ($context===null) { |
|
| 341 | 341 | $parent="$('".$maskSelector."').parent()"; |
| 342 | - $newElm = "$('#'+newId)"; |
|
| 343 | - }else{ |
|
| 342 | + $newElm="$('#'+newId)"; |
|
| 343 | + } else { |
|
| 344 | 344 | $parent=$context; |
| 345 | - $newElm = $context.".find('#'+newId)"; |
|
| 345 | + $newElm=$context.".find('#'+newId)"; |
|
| 346 | 346 | } |
| 347 | 347 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
| 348 | 348 | $retour=$parent.".find('.{$rowClass}').remove();"; |
| 349 | 349 | $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(); |
| 350 | 350 | 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"; |
| 351 | - $retour.= $appendTo; |
|
| 351 | + $retour.=$appendTo; |
|
| 352 | 352 | $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"; |
| 353 | 353 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 354 | 354 | $retour.="\t".$jsCallback; |
| 355 | 355 | $parameters["jsCallback"]=$retour; |
| 356 | - return $this->_ajax($method, $url,null,$parameters); |
|
| 356 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
| 365 | 365 | */ |
| 366 | 366 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
| 367 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
| 367 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -387,9 +387,9 @@ discard block |
||
| 387 | 387 | * @param string $method Method used, default : get |
| 388 | 388 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
| 389 | 389 | */ |
| 390 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
| 391 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 392 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 390 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
| 391 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 392 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | */ |
| 402 | 402 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
| 403 | 403 | $parameters["immediatly"]=false; |
| 404 | - return $this->_get($url, $responseElement,$parameters); |
|
| 404 | + return $this->_get($url, $responseElement, $parameters); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -414,8 +414,8 @@ discard block |
||
| 414 | 414 | * @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) |
| 415 | 415 | */ |
| 416 | 416 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
| 417 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 418 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 417 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 418 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -428,8 +428,8 @@ discard block |
||
| 428 | 428 | * @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) |
| 429 | 429 | */ |
| 430 | 430 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
| 431 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
| 432 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 431 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
| 432 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
@@ -463,15 +463,15 @@ discard block |
||
| 463 | 463 | * @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) |
| 464 | 464 | * @return $this |
| 465 | 465 | */ |
| 466 | - public function getHref($element,$responseElement="",$parameters=array()){ |
|
| 466 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 467 | 467 | $parameters["attr"]="href"; |
| 468 | - if(JString::isNull($responseElement)){ |
|
| 468 | + if (JString::isNull($responseElement)) { |
|
| 469 | 469 | $responseElement='%$(self).attr("data-target")%'; |
| 470 | 470 | } |
| 471 | - if(!isset($parameters["historize"])){ |
|
| 471 | + if (!isset($parameters["historize"])) { |
|
| 472 | 472 | $parameters["historize"]=true; |
| 473 | 473 | } |
| 474 | - return $this->getOnClick($element, "",$responseElement,$parameters); |
|
| 474 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -481,20 +481,20 @@ discard block |
||
| 481 | 481 | * @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) |
| 482 | 482 | * @return $this |
| 483 | 483 | */ |
| 484 | - public function postHref($element,$responseElement="",$parameters=array()){ |
|
| 484 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 485 | 485 | $parameters["attr"]="href"; |
| 486 | - if(JString::isNull($responseElement)){ |
|
| 486 | + if (JString::isNull($responseElement)) { |
|
| 487 | 487 | $responseElement='%$(this).attr("data-target")%'; |
| 488 | 488 | } |
| 489 | - if(!isset($parameters["historize"])){ |
|
| 489 | + if (!isset($parameters["historize"])) { |
|
| 490 | 490 | $parameters["historize"]=true; |
| 491 | 491 | } |
| 492 | - return $this->postOnClick($element, "","{}",$responseElement,$parameters); |
|
| 492 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 495 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 496 | 496 | $parameters["params"]=$params; |
| 497 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
| 497 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -504,8 +504,8 @@ discard block |
||
| 504 | 504 | * @param string $params JSON parameters |
| 505 | 505 | * @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) |
| 506 | 506 | */ |
| 507 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 508 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
| 507 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 508 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | /** |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | * @param string $responseElement selector of the HTML element displaying the answer |
| 517 | 517 | * @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) |
| 518 | 518 | */ |
| 519 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 519 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 520 | 520 | $parameters["immediatly"]=false; |
| 521 | 521 | return $this->_post($url, $params, $responseElement, $parameters); |
| 522 | 522 | } |
@@ -532,8 +532,8 @@ discard block |
||
| 532 | 532 | * @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) |
| 533 | 533 | */ |
| 534 | 534 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
| 535 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 536 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 535 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 536 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | /** |
@@ -550,33 +550,33 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
| 553 | - if(isset($this->params["ajax"])){ |
|
| 553 | + if (isset($this->params["ajax"])) { |
|
| 554 | 554 | extract($this->params["ajax"]); |
| 555 | 555 | } |
| 556 | - $params="{}";$validation=false; |
|
| 556 | + $params="{}"; $validation=false; |
|
| 557 | 557 | \extract($parameters); |
| 558 | - $async=($async)?"true":"false"; |
|
| 558 | + $async=($async) ? "true" : "false"; |
|
| 559 | 559 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 560 | 560 | $retour=$this->_getAjaxUrl($url, $attr); |
| 561 | 561 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
| 562 | 562 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
| 563 | - if(isset($params)){ |
|
| 563 | + if (isset($params)) { |
|
| 564 | 564 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
| 565 | 565 | } |
| 566 | 566 | $responseElement=$this->_getResponseElement($responseElement); |
| 567 | 567 | $retour.="var self=this;\n"; |
| 568 | - if($hasLoader===true){ |
|
| 569 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
| 570 | - }elseif($hasLoader==="internal"){ |
|
| 568 | + if ($hasLoader===true) { |
|
| 569 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 570 | + }elseif ($hasLoader==="internal") { |
|
| 571 | 571 | $retour.="\n$(this).addClass('loading');"; |
| 572 | 572 | } |
| 573 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
| 574 | - if(isset($headers)){ |
|
| 573 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
| 574 | + if (isset($headers)) { |
|
| 575 | 575 | $ajaxParameters["headers"]=$headers; |
| 576 | 576 | } |
| 577 | 577 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 578 | 578 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
| 579 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
| 579 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 580 | 580 | |
| 581 | 581 | if ($validation) { |
| 582 | 582 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -626,8 +626,8 @@ discard block |
||
| 626 | 626 | * @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) |
| 627 | 627 | */ |
| 628 | 628 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
| 629 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 630 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 629 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 630 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $retour.=$before; |
| 37 | 37 | if($hasLoader===true && JString::isNotNull($responseElement)){ |
| 38 | 38 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
| 39 | - }elseif($hasLoader==="internal"){ |
|
| 39 | + } elseif($hasLoader==="internal"){ |
|
| 40 | 40 | $retour.="\n$(this).addClass('loading');"; |
| 41 | 41 | } |
| 42 | 42 | $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
@@ -53,8 +53,9 @@ discard block |
||
| 53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
| 54 | 54 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
| 55 | 55 | $retour=$this->_addJsCondition($jsCondition,$retour); |
| 56 | - if ($immediatly) |
|
| 57 | - $this->jquery_code_for_compile[]=$retour; |
|
| 56 | + if ($immediatly) { |
|
| 57 | + $this->jquery_code_for_compile[]=$retour; |
|
| 58 | + } |
|
| 58 | 59 | return $retour; |
| 59 | 60 | } |
| 60 | 61 | |
@@ -75,7 +76,7 @@ discard block |
||
| 75 | 76 | } |
| 76 | 77 | if(is_array($v)){ |
| 77 | 78 | $s .= "'{$k}':{".self::implodeAjaxParameters($v)."}"; |
| 78 | - }else{ |
|
| 79 | + } else{ |
|
| 79 | 80 | $s .= "'{$k}':{$v}"; |
| 80 | 81 | } |
| 81 | 82 | } |
@@ -100,12 +101,13 @@ discard block |
||
| 100 | 101 | if(JString::isNotNull($attr)){ |
| 101 | 102 | if ($attr==="value"){ |
| 102 | 103 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 103 | - }elseif ($attr==="html"){ |
|
| 104 | + } elseif ($attr==="html"){ |
|
| 104 | 105 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 105 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
| 106 | + } elseif(\substr($attr, 0,3)==="js:"){ |
|
| 106 | 107 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
| 107 | - }elseif($attr!==null && $attr!=="") |
|
| 108 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 108 | + } elseif($attr!==null && $attr!=="") { |
|
| 109 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 110 | + } |
|
| 109 | 111 | } |
| 110 | 112 | return $retour; |
| 111 | 113 | } |
@@ -125,13 +127,14 @@ discard block |
||
| 125 | 127 | if (JString::isNotNull($responseElement)) { |
| 126 | 128 | if(isset($ajaxTransition)){ |
| 127 | 129 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 128 | - }elseif(isset($this->ajaxTransition)){ |
|
| 130 | + } elseif(isset($this->ajaxTransition)){ |
|
| 129 | 131 | $call=$this->ajaxTransition; |
| 130 | 132 | } |
| 131 | - if(\is_callable($call)) |
|
| 132 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 133 | - else |
|
| 134 | - $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 133 | + if(\is_callable($call)) { |
|
| 134 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 135 | + } else { |
|
| 136 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 137 | + } |
|
| 135 | 138 | } |
| 136 | 139 | if(isset($history)){ |
| 137 | 140 | if($this->params["autoActiveLinks"]){ |
@@ -154,8 +157,9 @@ discard block |
||
| 154 | 157 | } |
| 155 | 158 | |
| 156 | 159 | protected function _correctAjaxUrl($url) { |
| 157 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 158 | - $url=substr($url, 0, strlen($url)-1); |
|
| 160 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
| 161 | + $url=substr($url, 0, strlen($url)-1); |
|
| 162 | + } |
|
| 159 | 163 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
| 160 | 164 | $url=$this->getUrl($url); |
| 161 | 165 | } |
@@ -169,7 +173,7 @@ discard block |
||
| 169 | 173 | if(\preg_match("@^\{.*?\}$@", $params)){ |
| 170 | 174 | if( !isset($ajaxParameters['contentType'])|| !UString::contains('json', $ajaxParameters['contentType'])){ |
| 171 | 175 | return '$.param('.$params.')'; |
| 172 | - }else{ |
|
| 176 | + } else{ |
|
| 173 | 177 | return 'JSON.stringify('.$params.')'; |
| 174 | 178 | } |
| 175 | 179 | } |
@@ -179,8 +183,9 @@ discard block |
||
| 179 | 183 | public static function _implodeParams($parameters){ |
| 180 | 184 | $allParameters=[]; |
| 181 | 185 | foreach ($parameters as $params){ |
| 182 | - if(isset($params)) |
|
| 183 | - $allParameters[]=self::_correctParams($params); |
|
| 186 | + if(isset($params)) { |
|
| 187 | + $allParameters[]=self::_correctParams($params); |
|
| 188 | + } |
|
| 184 | 189 | } |
| 185 | 190 | return \implode("+'&'+", $allParameters); |
| 186 | 191 | } |
@@ -206,8 +211,9 @@ discard block |
||
| 206 | 211 | |
| 207 | 212 | protected function setDefaultParameters(&$parameters,$default){ |
| 208 | 213 | foreach ($default as $k=>$v){ |
| 209 | - if(!isset($parameters[$k])) |
|
| 210 | - $parameters[$k]=$v; |
|
| 214 | + if(!isset($parameters[$k])) { |
|
| 215 | + $parameters[$k]=$v; |
|
| 216 | + } |
|
| 211 | 217 | } |
| 212 | 218 | } |
| 213 | 219 | |
@@ -340,7 +346,7 @@ discard block |
||
| 340 | 346 | if($context===null){ |
| 341 | 347 | $parent="$('".$maskSelector."').parent()"; |
| 342 | 348 | $newElm = "$('#'+newId)"; |
| 343 | - }else{ |
|
| 349 | + } else{ |
|
| 344 | 350 | $parent=$context; |
| 345 | 351 | $newElm = $context.".find('#'+newId)"; |
| 346 | 352 | } |
@@ -567,7 +573,7 @@ discard block |
||
| 567 | 573 | $retour.="var self=this;\n"; |
| 568 | 574 | if($hasLoader===true){ |
| 569 | 575 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
| 570 | - }elseif($hasLoader==="internal"){ |
|
| 576 | + } elseif($hasLoader==="internal"){ |
|
| 571 | 577 | $retour.="\n$(this).addClass('loading');"; |
| 572 | 578 | } |
| 573 | 579 | $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
@@ -585,8 +591,9 @@ discard block |
||
| 585 | 591 | $retour.="$('#".$form."').submit();\n"; |
| 586 | 592 | } |
| 587 | 593 | $retour=$this->_addJsCondition($jsCondition, $retour); |
| 588 | - if ($immediatly) |
|
| 589 | - $this->jquery_code_for_compile[]=$retour; |
|
| 594 | + if ($immediatly) { |
|
| 595 | + $this->jquery_code_for_compile[]=$retour; |
|
| 596 | + } |
|
| 590 | 597 | return $retour; |
| 591 | 598 | } |
| 592 | 599 | |