@@ -2,10 +2,10 @@ discard block |
||
| 2 | 2 | namespace Ajax\common\traits; |
| 3 | 3 | use Ajax\common\BaseGui; |
| 4 | 4 | |
| 5 | -trait JsUtilsInternalTrait{ |
|
| 5 | +trait JsUtilsInternalTrait { |
|
| 6 | 6 | |
| 7 | - protected $jquery_code_for_compile=array (); |
|
| 8 | - protected $jquery_code_for_compile_at_last=array (); |
|
| 7 | + protected $jquery_code_for_compile=array(); |
|
| 8 | + protected $jquery_code_for_compile_at_last=array(); |
|
| 9 | 9 | |
| 10 | 10 | protected function _addToCompile($jsScript) { |
| 11 | 11 | $this->jquery_code_for_compile[]=$jsScript; |
@@ -15,29 +15,29 @@ discard block |
||
| 15 | 15 | * @param BaseGui $library |
| 16 | 16 | * @param mixed $view |
| 17 | 17 | */ |
| 18 | - protected function _compileLibrary(BaseGui $library, &$view=NULL){ |
|
| 19 | - if(isset($view)) |
|
| 18 | + protected function _compileLibrary(BaseGui $library, &$view=NULL) { |
|
| 19 | + if (isset($view)) |
|
| 20 | 20 | $library->compileHtml($this, $view); |
| 21 | 21 | if ($library->isAutoCompile()) { |
| 22 | 22 | $library->compile(true); |
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - protected function defer($script){ |
|
| 26 | + protected function defer($script) { |
|
| 27 | 27 | $result="window.defer=function (method) {if (window.jQuery) method(); else setTimeout(function() { defer(method) }, 50);};"; |
| 28 | 28 | $result.="window.defer(function(){".$script."})"; |
| 29 | 29 | return $result; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - protected function ready($script){ |
|
| 32 | + protected function ready($script) { |
|
| 33 | 33 | $result='$(document).ready(function() {'."\n"; |
| 34 | 34 | $result.=$script.'})'; |
| 35 | 35 | return $result; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | protected function minify($input) { |
| 39 | - if(trim($input) === "") return $input; |
|
| 40 | - $input= preg_replace( |
|
| 39 | + if (trim($input)==="") return $input; |
|
| 40 | + $input=preg_replace( |
|
| 41 | 41 | array( |
| 42 | 42 | // Remove comment(s) |
| 43 | 43 | '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | * @param mixed $view |
| 17 | 17 | */ |
| 18 | 18 | protected function _compileLibrary(BaseGui $library, &$view=NULL){ |
| 19 | - if(isset($view)) |
|
| 20 | - $library->compileHtml($this, $view); |
|
| 19 | + if(isset($view)) { |
|
| 20 | + $library->compileHtml($this, $view); |
|
| 21 | + } |
|
| 21 | 22 | if ($library->isAutoCompile()) { |
| 22 | 23 | $library->compile(true); |
| 23 | 24 | } |
@@ -36,7 +37,9 @@ discard block |
||
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | protected function minify($input) { |
| 39 | - if(trim($input) === "") return $input; |
|
| 40 | + if(trim($input) === "") { |
|
| 41 | + return $input; |
|
| 42 | + } |
|
| 40 | 43 | $input= preg_replace( |
| 41 | 44 | array( |
| 42 | 45 | // Remove comment(s) |
@@ -6,16 +6,16 @@ discard block |
||
| 6 | 6 | public static $preventDefault="\nif(event && event.preventDefault) event.preventDefault();\n"; |
| 7 | 7 | public static $stopPropagation="\nif(event && event.stopPropagation) event.stopPropagation();\n"; |
| 8 | 8 | |
| 9 | - public static function draggable($attr="id"){ |
|
| 9 | + public static function draggable($attr="id") { |
|
| 10 | 10 | return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;dt.setData("text/plain",JSON.stringify({id:$(event.target).attr("id"),data:$(event.target).attr("'.$attr.'")}));'; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | - public static function dropZone($jqueryDone,$jsCallback=""){ |
|
| 13 | + public static function dropZone($jqueryDone, $jsCallback="") { |
|
| 14 | 14 | return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;var _data=JSON.parse(dt.getData("text/plain"));$(event.target).'.$jqueryDone.'($("#"+_data.id));var data=_data.data;'.$jsCallback; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public static function containsCode($expression){ |
|
| 18 | - return strrpos($expression, 'this')!==false||strrpos($expression, 'event')!==false||strrpos($expression, 'self')!==false; |
|
| 17 | + public static function containsCode($expression) { |
|
| 18 | + return strrpos($expression, 'this')!==false || strrpos($expression, 'event')!==false || strrpos($expression, 'self')!==false; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | $value=implode(",", $value); |
| 47 | 47 | } |
| 48 | 48 | if (self::containsCode($value)===false) { |
| 49 | - $value=\str_replace(["\\","\""], ["\\\\","\\\""], $value); |
|
| 49 | + $value=\str_replace(["\\", "\""], ["\\\\", "\\\""], $value); |
|
| 50 | 50 | $value='"'.$value.'"'; |
| 51 | 51 | } |
| 52 | - return trim($value,"%"); |
|
| 52 | + return trim($value, "%"); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public static function prep_jquery_selector($value){ |
|
| 56 | - if(JString::startswith($value, '$(')===false){ |
|
| 55 | + public static function prep_jquery_selector($value) { |
|
| 56 | + if (JString::startswith($value, '$(')===false) { |
|
| 57 | 57 | return '$('.self::prep_value($value).')'; |
| 58 | 58 | } |
| 59 | 59 | return $value; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | $retour.="var self=this;\n"; |
| 33 | 33 | if($hasLoader===true && JString::isNotNull($responseElement)){ |
| 34 | 34 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
| 35 | - }elseif($hasLoader==="internal"){ |
|
| 35 | + } elseif($hasLoader==="internal"){ |
|
| 36 | 36 | $retour.="\n$(this).addClass('loading');"; |
| 37 | 37 | } |
| 38 | 38 | $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
@@ -49,8 +49,9 @@ discard block |
||
| 49 | 49 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
| 50 | 50 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
| 51 | 51 | $retour=$this->_addJsCondition($jsCondition,$retour); |
| 52 | - if ($immediatly) |
|
| 53 | - $this->jquery_code_for_compile[]=$retour; |
|
| 52 | + if ($immediatly) { |
|
| 53 | + $this->jquery_code_for_compile[]=$retour; |
|
| 54 | + } |
|
| 54 | 55 | return $retour; |
| 55 | 56 | } |
| 56 | 57 | |
@@ -86,12 +87,13 @@ discard block |
||
| 86 | 87 | if(JString::isNotNull($attr)){ |
| 87 | 88 | if ($attr==="value"){ |
| 88 | 89 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 89 | - }elseif ($attr==="html"){ |
|
| 90 | + } elseif ($attr==="html"){ |
|
| 90 | 91 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 91 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
| 92 | + } elseif(\substr($attr, 0,3)==="js:"){ |
|
| 92 | 93 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
| 93 | - }elseif($attr!==null && $attr!=="") |
|
| 94 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 94 | + } elseif($attr!==null && $attr!=="") { |
|
| 95 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 96 | + } |
|
| 95 | 97 | } |
| 96 | 98 | return $retour; |
| 97 | 99 | } |
@@ -111,13 +113,14 @@ discard block |
||
| 111 | 113 | if (JString::isNotNull($responseElement)) { |
| 112 | 114 | if(isset($ajaxTransition)){ |
| 113 | 115 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 114 | - }elseif(isset($this->ajaxTransition)){ |
|
| 116 | + } elseif(isset($this->ajaxTransition)){ |
|
| 115 | 117 | $call=$this->ajaxTransition; |
| 116 | 118 | } |
| 117 | - if(\is_callable($call)) |
|
| 118 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 119 | - else |
|
| 120 | - $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 119 | + if(\is_callable($call)) { |
|
| 120 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 121 | + } else { |
|
| 122 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 123 | + } |
|
| 121 | 124 | } |
| 122 | 125 | if(isset($history)){ |
| 123 | 126 | if($this->params["autoActiveLinks"]){ |
@@ -140,8 +143,9 @@ discard block |
||
| 140 | 143 | } |
| 141 | 144 | |
| 142 | 145 | protected function _correctAjaxUrl($url) { |
| 143 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 144 | - $url=substr($url, 0, strlen($url)-1); |
|
| 146 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
| 147 | + $url=substr($url, 0, strlen($url)-1); |
|
| 148 | + } |
|
| 145 | 149 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
| 146 | 150 | $url=$this->getUrl($url); |
| 147 | 151 | } |
@@ -161,8 +165,9 @@ discard block |
||
| 161 | 165 | public static function _implodeParams($parameters){ |
| 162 | 166 | $allParameters=[]; |
| 163 | 167 | foreach ($parameters as $params){ |
| 164 | - if(isset($params)) |
|
| 165 | - $allParameters[]=self::_correctParams($params); |
|
| 168 | + if(isset($params)) { |
|
| 169 | + $allParameters[]=self::_correctParams($params); |
|
| 170 | + } |
|
| 166 | 171 | } |
| 167 | 172 | return \implode("+'&'+", $allParameters); |
| 168 | 173 | } |
@@ -188,8 +193,9 @@ discard block |
||
| 188 | 193 | |
| 189 | 194 | protected function setDefaultParameters(&$parameters,$default){ |
| 190 | 195 | foreach ($default as $k=>$v){ |
| 191 | - if(!isset($parameters[$k])) |
|
| 192 | - $parameters[$k]=$v; |
|
| 196 | + if(!isset($parameters[$k])) { |
|
| 197 | + $parameters[$k]=$v; |
|
| 198 | + } |
|
| 193 | 199 | } |
| 194 | 200 | } |
| 195 | 201 | |
@@ -307,7 +313,7 @@ discard block |
||
| 307 | 313 | if($context===null){ |
| 308 | 314 | $parent="$('".$maskSelector."').parent()"; |
| 309 | 315 | $newElm = "$('#'+newId)"; |
| 310 | - }else{ |
|
| 316 | + } else{ |
|
| 311 | 317 | $parent=$context; |
| 312 | 318 | $newElm = $context.".find('#'+newId)"; |
| 313 | 319 | } |
@@ -533,7 +539,7 @@ discard block |
||
| 533 | 539 | $retour.="var self=this;\n"; |
| 534 | 540 | if($hasLoader===true){ |
| 535 | 541 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
| 536 | - }elseif($hasLoader==="internal"){ |
|
| 542 | + } elseif($hasLoader==="internal"){ |
|
| 537 | 543 | $retour.="\n$(this).addClass('loading');"; |
| 538 | 544 | } |
| 539 | 545 | $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
@@ -551,8 +557,9 @@ discard block |
||
| 551 | 557 | $retour.="$('#".$form."').submit();\n"; |
| 552 | 558 | } |
| 553 | 559 | $retour=$this->_addJsCondition($jsCondition, $retour); |
| 554 | - if ($immediatly) |
|
| 555 | - $this->jquery_code_for_compile[]=$retour; |
|
| 560 | + if ($immediatly) { |
|
| 561 | + $this->jquery_code_for_compile[]=$retour; |
|
| 562 | + } |
|
| 556 | 563 | return $retour; |
| 557 | 564 | } |
| 558 | 565 | |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
| 18 | 18 | |
| 19 | 19 | abstract public function getUrl($url); |
| 20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
| 20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 21 | 21 | |
| 22 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
| 23 | - if(isset($this->params["ajax"])){ |
|
| 22 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 23 | + if (isset($this->params["ajax"])) { |
|
| 24 | 24 | extract($this->params["ajax"]); |
| 25 | 25 | } |
| 26 | 26 | extract($parameters); |
@@ -30,109 +30,109 @@ discard block |
||
| 30 | 30 | $originalSelector=$responseElement; |
| 31 | 31 | $responseElement=$this->_getResponseElement($responseElement); |
| 32 | 32 | $retour.="var self=this;\n"; |
| 33 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
| 34 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
| 35 | - }elseif($hasLoader==="internal"){ |
|
| 33 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 34 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 35 | + }elseif ($hasLoader==="internal") { |
|
| 36 | 36 | $retour.="\n$(this).addClass('loading');"; |
| 37 | 37 | } |
| 38 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
| 38 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
| 39 | 39 | |
| 40 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
| 40 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 41 | 41 | |
| 42 | - if(isset($params)){ |
|
| 42 | + if (isset($params)) { |
|
| 43 | 43 | $ajaxParameters["data"]=self::_correctParams($params); |
| 44 | 44 | } |
| 45 | - if(isset($headers)){ |
|
| 45 | + if (isset($headers)) { |
|
| 46 | 46 | $ajaxParameters["headers"]=$headers; |
| 47 | 47 | } |
| 48 | 48 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 49 | 49 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
| 50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
| 51 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
| 50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 51 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 52 | 52 | if ($immediatly) |
| 53 | 53 | $this->jquery_code_for_compile[]=$retour; |
| 54 | 54 | return $retour; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - protected function createAjaxParameters(&$original,$parameters){ |
|
| 58 | - $validParameters=["dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
| 59 | - foreach ($validParameters as $param=>$mask){ |
|
| 60 | - if(isset($parameters[$param])){ |
|
| 57 | + protected function createAjaxParameters(&$original, $parameters) { |
|
| 58 | + $validParameters=["dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
| 59 | + foreach ($validParameters as $param=>$mask) { |
|
| 60 | + if (isset($parameters[$param])) { |
|
| 61 | 61 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
| 67 | - $s = ''; foreach ($ajaxParameters as $k=>$v) { if ($s !== '') { $s .= ','; } $s .= "'{$k}':{$v}"; } |
|
| 66 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
| 67 | + $s=''; foreach ($ajaxParameters as $k=>$v) { if ($s!=='') { $s.=','; } $s.="'{$k}':{$v}"; } |
|
| 68 | 68 | return $s; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
| 72 | - if(isset($jsCondition)){ |
|
| 71 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
| 72 | + if (isset($jsCondition)) { |
|
| 73 | 73 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
| 74 | 74 | } |
| 75 | 75 | return $jsSource; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | |
| 79 | - protected function _getAjaxUrl($url,$attr){ |
|
| 79 | + protected function _getAjaxUrl($url, $attr) { |
|
| 80 | 80 | $url=$this->_correctAjaxUrl($url); |
| 81 | 81 | $retour="url='".$url."';"; |
| 82 | 82 | $slash="/"; |
| 83 | - if(JString::endswith($url, "/")===true){ |
|
| 83 | + if (JString::endswith($url, "/")===true) { |
|
| 84 | 84 | $slash=""; |
| 85 | 85 | } |
| 86 | - if(JString::isNotNull($attr)){ |
|
| 87 | - if ($attr==="value"){ |
|
| 86 | + if (JString::isNotNull($attr)) { |
|
| 87 | + if ($attr==="value") { |
|
| 88 | 88 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 89 | - }elseif ($attr==="html"){ |
|
| 89 | + }elseif ($attr==="html") { |
|
| 90 | 90 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 91 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
| 91 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
| 92 | 92 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
| 93 | - }elseif($attr!==null && $attr!=="") |
|
| 93 | + }elseif ($attr!==null && $attr!=="") |
|
| 94 | 94 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
| 95 | 95 | } |
| 96 | 96 | return $retour; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - protected function onPopstate(){ |
|
| 99 | + protected function onPopstate() { |
|
| 100 | 100 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - protected function autoActiveLinks($previousURL="window.location.href"){ |
|
| 104 | - $result= "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 103 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 104 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 105 | 105 | $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
| 106 | 106 | return $result; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
| 110 | - $retour="";$call=null; |
|
| 109 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 110 | + $retour=""; $call=null; |
|
| 111 | 111 | if (JString::isNotNull($responseElement)) { |
| 112 | - if(isset($ajaxTransition)){ |
|
| 112 | + if (isset($ajaxTransition)) { |
|
| 113 | 113 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 114 | - }elseif(isset($this->ajaxTransition)){ |
|
| 114 | + }elseif (isset($this->ajaxTransition)) { |
|
| 115 | 115 | $call=$this->ajaxTransition; |
| 116 | 116 | } |
| 117 | - if(\is_callable($call)) |
|
| 118 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 117 | + if (\is_callable($call)) |
|
| 118 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 119 | 119 | else |
| 120 | 120 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
| 121 | 121 | } |
| 122 | - if(isset($history)){ |
|
| 123 | - if($this->params["autoActiveLinks"]){ |
|
| 122 | + if (isset($history)) { |
|
| 123 | + if ($this->params["autoActiveLinks"]) { |
|
| 124 | 124 | $retour.=$this->autoActiveLinks("url"); |
| 125 | 125 | } |
| 126 | 126 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
| 127 | 127 | } |
| 128 | - if($hasLoader==="internal"){ |
|
| 128 | + if ($hasLoader==="internal") { |
|
| 129 | 129 | $retour.="\n$(self).removeClass('loading');"; |
| 130 | 130 | } |
| 131 | 131 | $retour.="\t".$jsCallback."\n"; |
| 132 | 132 | return $retour; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - protected function _getResponseElement($responseElement){ |
|
| 135 | + protected function _getResponseElement($responseElement) { |
|
| 136 | 136 | if (JString::isNotNull($responseElement)) { |
| 137 | 137 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
| 138 | 138 | } |
@@ -142,33 +142,33 @@ discard block |
||
| 142 | 142 | protected function _correctAjaxUrl($url) { |
| 143 | 143 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
| 144 | 144 | $url=substr($url, 0, strlen($url)-1); |
| 145 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
| 145 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 146 | 146 | $url=$this->getUrl($url); |
| 147 | 147 | } |
| 148 | 148 | return $url; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - public static function _correctParams($params){ |
|
| 152 | - if(JString::isNull($params)){ |
|
| 151 | + public static function _correctParams($params) { |
|
| 152 | + if (JString::isNull($params)) { |
|
| 153 | 153 | return ""; |
| 154 | 154 | } |
| 155 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
| 155 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
| 156 | 156 | return '$.param('.$params.')'; |
| 157 | 157 | } |
| 158 | 158 | return $params; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public static function _implodeParams($parameters){ |
|
| 161 | + public static function _implodeParams($parameters) { |
|
| 162 | 162 | $allParameters=[]; |
| 163 | - foreach ($parameters as $params){ |
|
| 164 | - if(isset($params)) |
|
| 163 | + foreach ($parameters as $params) { |
|
| 164 | + if (isset($params)) |
|
| 165 | 165 | $allParameters[]=self::_correctParams($params); |
| 166 | 166 | } |
| 167 | 167 | return \implode("+'&'+", $allParameters); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
| 171 | - if(!isset($ajaxLoader)){ |
|
| 170 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 171 | + if (!isset($ajaxLoader)) { |
|
| 172 | 172 | $ajaxLoader=$this->ajaxLoader; |
| 173 | 173 | } |
| 174 | 174 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -176,19 +176,19 @@ discard block |
||
| 176 | 176 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - protected function setAjaxDataCall($params){ |
|
| 179 | + protected function setAjaxDataCall($params) { |
|
| 180 | 180 | $result=null; |
| 181 | - if(!\is_callable($params)){ |
|
| 182 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
| 183 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
| 181 | + if (!\is_callable($params)) { |
|
| 182 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
| 183 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
| 184 | 184 | }; |
| 185 | 185 | } |
| 186 | 186 | return $result; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - protected function setDefaultParameters(&$parameters,$default){ |
|
| 190 | - foreach ($default as $k=>$v){ |
|
| 191 | - if(!isset($parameters[$k])) |
|
| 189 | + protected function setDefaultParameters(&$parameters, $default) { |
|
| 190 | + foreach ($default as $k=>$v) { |
|
| 191 | + if (!isset($parameters[$k])) |
|
| 192 | 192 | $parameters[$k]=$v; |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | * @param string $url The url of the request |
| 203 | 203 | * @param string $responseElement selector of the HTML element displaying the answer |
| 204 | 204 | */ |
| 205 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
| 206 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
| 205 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
| 206 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | * @param string $responseElement selector of the HTML element displaying the answer |
| 213 | 213 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
| 214 | 214 | */ |
| 215 | - public function get($url, $responseElement="",$parameters=[]) { |
|
| 215 | + public function get($url, $responseElement="", $parameters=[]) { |
|
| 216 | 216 | $parameters["immediatly"]=true; |
| 217 | - return $this->_get($url,$responseElement,$parameters); |
|
| 217 | + return $this->_get($url, $responseElement, $parameters); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | * @param string $responseElement selector of the HTML element displaying the answer |
| 225 | 225 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
| 226 | 226 | */ |
| 227 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
| 227 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 228 | 228 | $parameters["immediatly"]=true; |
| 229 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
| 229 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | * @param string $responseElement selector of the HTML element displaying the answer |
| 237 | 237 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
| 238 | 238 | */ |
| 239 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
| 239 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
| 240 | 240 | $parameters["immediatly"]=false; |
| 241 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
| 241 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -247,15 +247,15 @@ discard block |
||
| 247 | 247 | * @param string $method Method used |
| 248 | 248 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
| 249 | 249 | */ |
| 250 | - private function _json($url, $method="get",$parameters=[]) { |
|
| 251 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
| 250 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 251 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
| 252 | 252 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
| 253 | 253 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
| 254 | 254 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n\tfor(var key in data){" |
| 255 | 255 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
| 256 | 256 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 257 | 257 | $parameters["jsCallback"]=$retour; |
| 258 | - return $this->_ajax($method, $url,null,$parameters); |
|
| 258 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
| 266 | 266 | */ |
| 267 | 267 | public function json($url, $method="get", $parameters=[]) { |
| 268 | - return $this->_json($url,$method,$parameters); |
|
| 268 | + return $this->_json($url, $method, $parameters); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | * @param string $method default get |
| 277 | 277 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
| 278 | 278 | */ |
| 279 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
| 280 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 281 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 279 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
| 280 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 281 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | */ |
| 290 | 290 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
| 291 | 291 | $parameters["immediatly"]=false; |
| 292 | - return $this->_json($url,$method,$parameters); |
|
| 292 | + return $this->_json($url, $method, $parameters); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -300,27 +300,27 @@ discard block |
||
| 300 | 300 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
| 301 | 301 | */ |
| 302 | 302 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
| 303 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
| 303 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
| 304 | 304 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
| 305 | 305 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
| 306 | 306 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
| 307 | - if($context===null){ |
|
| 307 | + if ($context===null) { |
|
| 308 | 308 | $parent="$('".$maskSelector."').parent()"; |
| 309 | - $newElm = "$('#'+newId)"; |
|
| 310 | - }else{ |
|
| 309 | + $newElm="$('#'+newId)"; |
|
| 310 | + } else { |
|
| 311 | 311 | $parent=$context; |
| 312 | - $newElm = $context.".find('#'+newId)"; |
|
| 312 | + $newElm=$context.".find('#'+newId)"; |
|
| 313 | 313 | } |
| 314 | 314 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
| 315 | 315 | $retour=$parent.".find('.{$rowClass}').remove();"; |
| 316 | 316 | $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(); |
| 317 | 317 | 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"; |
| 318 | - $retour.= $appendTo; |
|
| 318 | + $retour.=$appendTo; |
|
| 319 | 319 | $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"; |
| 320 | 320 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 321 | 321 | $retour.="\t".$jsCallback; |
| 322 | 322 | $parameters["jsCallback"]=$retour; |
| 323 | - return $this->_ajax($method, $url,null,$parameters); |
|
| 323 | + return $this->_ajax($method, $url, null, $parameters); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
| 332 | 332 | */ |
| 333 | 333 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
| 334 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
| 334 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | * @param string $method Method used, default : get |
| 355 | 355 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
| 356 | 356 | */ |
| 357 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
| 358 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 359 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 357 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
| 358 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 359 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
| 370 | 370 | $parameters["immediatly"]=false; |
| 371 | - return $this->_get($url, $responseElement,$parameters); |
|
| 371 | + return $this->_get($url, $responseElement, $parameters); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * @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) |
| 382 | 382 | */ |
| 383 | 383 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
| 384 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 385 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 384 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 385 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -395,8 +395,8 @@ discard block |
||
| 395 | 395 | * @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) |
| 396 | 396 | */ |
| 397 | 397 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
| 398 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
| 399 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 398 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
| 399 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -430,15 +430,15 @@ discard block |
||
| 430 | 430 | * @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) |
| 431 | 431 | * @return $this |
| 432 | 432 | */ |
| 433 | - public function getHref($element,$responseElement="",$parameters=array()){ |
|
| 433 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 434 | 434 | $parameters["attr"]="href"; |
| 435 | - if(JString::isNull($responseElement)){ |
|
| 435 | + if (JString::isNull($responseElement)) { |
|
| 436 | 436 | $responseElement='%$(self).attr("data-target")%'; |
| 437 | 437 | } |
| 438 | - if(!isset($parameters["historize"])){ |
|
| 438 | + if (!isset($parameters["historize"])) { |
|
| 439 | 439 | $parameters["historize"]=true; |
| 440 | 440 | } |
| 441 | - return $this->getOnClick($element, "",$responseElement,$parameters); |
|
| 441 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | /** |
@@ -448,20 +448,20 @@ discard block |
||
| 448 | 448 | * @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) |
| 449 | 449 | * @return $this |
| 450 | 450 | */ |
| 451 | - public function postHref($element,$responseElement="",$parameters=array()){ |
|
| 451 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 452 | 452 | $parameters["attr"]="href"; |
| 453 | - if(JString::isNull($responseElement)){ |
|
| 453 | + if (JString::isNull($responseElement)) { |
|
| 454 | 454 | $responseElement='%$(this).attr("data-target")%'; |
| 455 | 455 | } |
| 456 | - if(!isset($parameters["historize"])){ |
|
| 456 | + if (!isset($parameters["historize"])) { |
|
| 457 | 457 | $parameters["historize"]=true; |
| 458 | 458 | } |
| 459 | - return $this->postOnClick($element, "","{}",$responseElement,$parameters); |
|
| 459 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 462 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 463 | 463 | $parameters["params"]=$params; |
| 464 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
| 464 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * @param string $params JSON parameters |
| 472 | 472 | * @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) |
| 473 | 473 | */ |
| 474 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 475 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
| 474 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 475 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | * @param string $responseElement selector of the HTML element displaying the answer |
| 484 | 484 | * @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) |
| 485 | 485 | */ |
| 486 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 486 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 487 | 487 | $parameters["immediatly"]=false; |
| 488 | 488 | return $this->_post($url, $params, $responseElement, $parameters); |
| 489 | 489 | } |
@@ -499,8 +499,8 @@ discard block |
||
| 499 | 499 | * @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) |
| 500 | 500 | */ |
| 501 | 501 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
| 502 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 503 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 502 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 503 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -517,33 +517,33 @@ discard block |
||
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
| 520 | - if(isset($this->params["ajax"])){ |
|
| 520 | + if (isset($this->params["ajax"])) { |
|
| 521 | 521 | extract($this->params["ajax"]); |
| 522 | 522 | } |
| 523 | - $params="{}";$validation=false; |
|
| 523 | + $params="{}"; $validation=false; |
|
| 524 | 524 | \extract($parameters); |
| 525 | - $async=($async)?"true":"false"; |
|
| 525 | + $async=($async) ? "true" : "false"; |
|
| 526 | 526 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 527 | 527 | $retour=$this->_getAjaxUrl($url, $attr); |
| 528 | 528 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
| 529 | 529 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
| 530 | - if(isset($params)){ |
|
| 530 | + if (isset($params)) { |
|
| 531 | 531 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
| 532 | 532 | } |
| 533 | 533 | $responseElement=$this->_getResponseElement($responseElement); |
| 534 | 534 | $retour.="var self=this;\n"; |
| 535 | - if($hasLoader===true){ |
|
| 536 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
| 537 | - }elseif($hasLoader==="internal"){ |
|
| 535 | + if ($hasLoader===true) { |
|
| 536 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
| 537 | + }elseif ($hasLoader==="internal") { |
|
| 538 | 538 | $retour.="\n$(this).addClass('loading');"; |
| 539 | 539 | } |
| 540 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
| 541 | - if(isset($headers)){ |
|
| 540 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
| 541 | + if (isset($headers)) { |
|
| 542 | 542 | $ajaxParameters["headers"]=$headers; |
| 543 | 543 | } |
| 544 | 544 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 545 | 545 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
| 546 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
| 546 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 547 | 547 | |
| 548 | 548 | if ($validation) { |
| 549 | 549 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -593,8 +593,8 @@ discard block |
||
| 593 | 593 | * @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) |
| 594 | 594 | */ |
| 595 | 595 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
| 596 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 597 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 596 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 597 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -21,24 +21,24 @@ discard block |
||
| 21 | 21 | $this->_rowClass="_json"; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - protected function _generateContent($table){ |
|
| 24 | + protected function _generateContent($table) { |
|
| 25 | 25 | $this->_addRowModel($table); |
| 26 | 26 | parent::_generateContent($table); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - protected function _addRowModel($table){ |
|
| 29 | + protected function _addRowModel($table) { |
|
| 30 | 30 | $row=$this->_createRow($table, $this->_modelClass); |
| 31 | - $row->setProperty("style","display:none;"); |
|
| 31 | + $row->setProperty("style", "display:none;"); |
|
| 32 | 32 | $table->getBody()->_addRow($row); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - protected function _createRow($table,$rowClass){ |
|
| 35 | + protected function _createRow($table, $rowClass) { |
|
| 36 | 36 | $object=JReflection::jsonObject($this->_model); |
| 37 | - if(isset($this->_rowModelCallback)){ |
|
| 37 | + if (isset($this->_rowModelCallback)) { |
|
| 38 | 38 | $callback=$this->_rowModelCallback; |
| 39 | 39 | $callback($object); |
| 40 | 40 | } |
| 41 | - $row=$this->_generateRow($object, $table,"_jsonArrayChecked"); |
|
| 41 | + $row=$this->_generateRow($object, $table, "_jsonArrayChecked"); |
|
| 42 | 42 | $row->setClass($rowClass); |
| 43 | 43 | return $row; |
| 44 | 44 | } |
@@ -47,22 +47,22 @@ discard block |
||
| 47 | 47 | * {@inheritDoc} |
| 48 | 48 | * @see DataTable::_associatePaginationBehavior() |
| 49 | 49 | */ |
| 50 | - protected function _associatePaginationBehavior(JsUtils $js=NULL,$offset=null){ |
|
| 50 | + protected function _associatePaginationBehavior(JsUtils $js=NULL, $offset=null) { |
|
| 51 | 51 | $callback=null; |
| 52 | 52 | $menu=$this->_pagination->getMenu(); |
| 53 | 53 | |
| 54 | - if(isset($js)){ |
|
| 54 | + if (isset($js)) { |
|
| 55 | 55 | $id=$this->identifier; |
| 56 | 56 | $callback=$js->getScript($offset).$this->getHtmlComponent()->getInnerScript(); |
| 57 | - $callback.=$js->trigger("#".$id." [name='selection[]']","change",false)."$('#".$id." tbody .ui.checkbox').checkbox();".$js->execOn("change", "#".$id." [name='selection[]']", $this->_getCheckedChange($js)); |
|
| 57 | + $callback.=$js->trigger("#".$id." [name='selection[]']", "change", false)."$('#".$id." tbody .ui.checkbox').checkbox();".$js->execOn("change", "#".$id." [name='selection[]']", $this->_getCheckedChange($js)); |
|
| 58 | 58 | $callback.=$this->_generatePaginationScript($id); |
| 59 | 59 | } |
| 60 | - if(isset($this->_urls["refresh"])){ |
|
| 61 | - $js->jsonArrayOn("click", "#".$menu->getIdentifier()." a","#".$this->_identifier." tr.".$this->_modelClass, $this->_urls["refresh"],"post",["params"=>"{'p':$(this).attr('data-page')}","jsCallback"=>$callback]); |
|
| 60 | + if (isset($this->_urls["refresh"])) { |
|
| 61 | + $js->jsonArrayOn("click", "#".$menu->getIdentifier()." a", "#".$this->_identifier." tr.".$this->_modelClass, $this->_urls["refresh"], "post", ["params"=>"{'p':$(this).attr('data-page')}", "jsCallback"=>$callback]); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - protected function _generatePaginationScript($id){ |
|
| 65 | + protected function _generatePaginationScript($id) { |
|
| 66 | 66 | return ";var page=parseInt($(self).attr('data-page')) || 1;var pages_visibles=$('#pagination-{$id} .item').length-2; |
| 67 | 67 | var lastPage=$('#pagination-{$id} ._lastPage'); |
| 68 | 68 | var middle= Math.ceil((pages_visibles-1)/ 2); |
@@ -82,17 +82,17 @@ discard block |
||
| 82 | 82 | lastPage.attr('data-page',Math.min(lastPage.attr('data-max'),page+1)); |
| 83 | 83 | $('#{$id}').trigger('pageChange');$('#pagination-{$id}').show();"; |
| 84 | 84 | } |
| 85 | - protected function _compileSearchFieldBehavior(JsUtils $js=NULL){ |
|
| 85 | + protected function _compileSearchFieldBehavior(JsUtils $js=NULL) { |
|
| 86 | 86 | |
| 87 | 87 | } |
| 88 | - protected function _associateSearchFieldBehavior(JsUtils $js=NULL,$offset=null){ |
|
| 89 | - if(isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])){ |
|
| 88 | + protected function _associateSearchFieldBehavior(JsUtils $js=NULL, $offset=null) { |
|
| 89 | + if (isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])) { |
|
| 90 | 90 | $callback=null; |
| 91 | 91 | $id=$this->identifier; |
| 92 | 92 | $callback=$js->getScript($offset).$this->getHtmlComponent()->getInnerScript(); |
| 93 | - $callback.=$js->trigger("#".$id." [name='selection[]']","change",false)."$('#".$id." tbody .ui.checkbox').checkbox();".$js->execOn("change", "#".$id." [name='selection[]']", $this->_getCheckedChange($js)); |
|
| 93 | + $callback.=$js->trigger("#".$id." [name='selection[]']", "change", false)."$('#".$id." tbody .ui.checkbox').checkbox();".$js->execOn("change", "#".$id." [name='selection[]']", $this->_getCheckedChange($js)); |
|
| 94 | 94 | $callback.="$('#pagination-{$id}').hide();$('#".$this->identifier."').trigger('searchTerminate',[$(self).val()]);"; |
| 95 | - $js->jsonArrayOn("change", "#".$this->_searchField->getDataField()->getIdentifier(),"#".$this->_identifier." tr.".$this->_modelClass, $this->_urls["refresh"],"post",["params"=>"{'s':$(self).val()}","jsCallback"=>$callback]); |
|
| 95 | + $js->jsonArrayOn("change", "#".$this->_searchField->getDataField()->getIdentifier(), "#".$this->_identifier." tr.".$this->_modelClass, $this->_urls["refresh"], "post", ["params"=>"{'s':$(self).val()}", "jsCallback"=>$callback]); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
@@ -106,29 +106,29 @@ discard block |
||
| 106 | 106 | * @param string $jsCallback |
| 107 | 107 | * @return AjaxCall |
| 108 | 108 | */ |
| 109 | - public function jsJsonArray($url, $method="get", $params="{}", $jsCallback=NULL,$parameters=[]){ |
|
| 110 | - $parameters=\array_merge($parameters,["modelSelector"=>"#".$this->_identifier." tr.".$this->_modelClass,"url"=>$url,"method"=>$method,"params"=>$params,"jsCallback"=>$jsCallback]); |
|
| 109 | + public function jsJsonArray($url, $method="get", $params="{}", $jsCallback=NULL, $parameters=[]) { |
|
| 110 | + $parameters=\array_merge($parameters, ["modelSelector"=>"#".$this->_identifier." tr.".$this->_modelClass, "url"=>$url, "method"=>$method, "params"=>$params, "jsCallback"=>$jsCallback]); |
|
| 111 | 111 | return new AjaxCall("jsonArray", $parameters); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public function jsClear(){ |
|
| 114 | + public function jsClear() { |
|
| 115 | 115 | return "$('#{$this->identifier} tbody').find('._json').remove();"; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function clearOn(BaseHtml $element,$event, $stopPropagation=false, $preventDefault=false){ |
|
| 119 | - return $element->addEvent($event, $this->jsClear(),$stopPropagation,$preventDefault); |
|
| 118 | + public function clearOn(BaseHtml $element, $event, $stopPropagation=false, $preventDefault=false) { |
|
| 119 | + return $element->addEvent($event, $this->jsClear(), $stopPropagation, $preventDefault); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public function clearOnClick(BaseHtml $element,$stopPropagation=false, $preventDefault=false){ |
|
| 123 | - return $this->clearOn($element, "click",$stopPropagation,$preventDefault); |
|
| 122 | + public function clearOnClick(BaseHtml $element, $stopPropagation=false, $preventDefault=false) { |
|
| 123 | + return $this->clearOn($element, "click", $stopPropagation, $preventDefault); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function jsonArrayOn(BaseHtml $element,$event,$url, $method="get", $params="{}", $jsCallback=NULL,$parameters=[]){ |
|
| 127 | - return $element->_addEvent($event, $this->jsJsonArray($url,$method,$params,$jsCallback,$parameters)); |
|
| 126 | + public function jsonArrayOn(BaseHtml $element, $event, $url, $method="get", $params="{}", $jsCallback=NULL, $parameters=[]) { |
|
| 127 | + return $element->_addEvent($event, $this->jsJsonArray($url, $method, $params, $jsCallback, $parameters)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function jsonArrayOnClick(BaseHtml $element,$url, $method="get", $params="{}", $jsCallback=NULL,$parameters=[]){ |
|
| 131 | - return $this->jsonArrayOn($element, "click", $url,$method,$params,$jsCallback,$parameters); |
|
| 130 | + public function jsonArrayOnClick(BaseHtml $element, $url, $method="get", $params="{}", $jsCallback=NULL, $parameters=[]) { |
|
| 131 | + return $this->jsonArrayOn($element, "click", $url, $method, $params, $jsCallback, $parameters); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 140 | 140 | * @return DataTable |
| 141 | 141 | */ |
| 142 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
| 143 | - return parent::paginate($page, $total_rowcount,$items_per_page,$pages_visibles); |
|
| 142 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
| 143 | + return parent::paginate($page, $total_rowcount, $items_per_page, $pages_visibles); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | public function setRowModelCallback($_rowModelCallback) { |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | 24 | class DataTable extends Widget { |
| 25 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait,BaseTrait; |
|
| 25 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait, BaseTrait; |
|
| 26 | 26 | protected $_searchField; |
| 27 | 27 | protected $_urls; |
| 28 | 28 | protected $_pagination; |
@@ -41,41 +41,41 @@ discard block |
||
| 41 | 41 | protected $_colWidths; |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 45 | - parent::__construct($identifier, $model,$modelInstance); |
|
| 46 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
| 44 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 45 | + parent::__construct($identifier, $model, $modelInstance); |
|
| 46 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
| 47 | 47 | $this->_urls=[]; |
| 48 | - $this->_emptyMessage=new HtmlMessage("","nothing to display"); |
|
| 48 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
| 49 | 49 | $this->_emptyMessage->setIcon("info circle"); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function run(JsUtils $js){ |
|
| 52 | + public function run(JsUtils $js) { |
|
| 53 | 53 | $offset=$js->scriptCount(); |
| 54 | - if($this->_hasCheckboxes && isset($js)){ |
|
| 54 | + if ($this->_hasCheckboxes && isset($js)) { |
|
| 55 | 55 | $this->_runCheckboxes($js); |
| 56 | 56 | } |
| 57 | - if($this->_visibleHover){ |
|
| 58 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 59 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 57 | + if ($this->_visibleHover) { |
|
| 58 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 59 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 60 | 60 | } |
| 61 | - if(\is_array($this->_deleteBehavior)) |
|
| 62 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
| 63 | - if(\is_array($this->_editBehavior)) |
|
| 64 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
| 65 | - if(\is_array($this->_displayBehavior)){ |
|
| 61 | + if (\is_array($this->_deleteBehavior)) |
|
| 62 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
| 63 | + if (\is_array($this->_editBehavior)) |
|
| 64 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
| 65 | + if (\is_array($this->_displayBehavior)) { |
|
| 66 | 66 | $this->_displayBehavior["jsCallback"]='$("#dataTable").hide();'; |
| 67 | - $this->_generateBehavior("display",$this->_displayBehavior,$js); |
|
| 67 | + $this->_generateBehavior("display", $this->_displayBehavior, $js); |
|
| 68 | 68 | } |
| 69 | 69 | parent::run($js); |
| 70 | - $this->_associateSearchFieldBehavior($js,$offset); |
|
| 71 | - if(isset($this->_pagination)) |
|
| 72 | - $this->_associatePaginationBehavior($js,$offset); |
|
| 70 | + $this->_associateSearchFieldBehavior($js, $offset); |
|
| 71 | + if (isset($this->_pagination)) |
|
| 72 | + $this->_associatePaginationBehavior($js, $offset); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
| 76 | - if(isset($this->_urls[$op])){ |
|
| 77 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
| 78 | - $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector($op),$params); |
|
| 75 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
| 76 | + if (isset($this->_urls[$op])) { |
|
| 77 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
| 78 | + $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector($op), $params); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,126 +88,126 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
| 91 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 92 | - if(!$this->_generated){ |
|
| 93 | - if(isset($this->_buttonsColumn)){ |
|
| 91 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 92 | + if (!$this->_generated) { |
|
| 93 | + if (isset($this->_buttonsColumn)) { |
|
| 94 | 94 | $this->_instanceViewer->sortColumnContent($this->_buttonsColumn, $this->_buttons); |
| 95 | 95 | } |
| 96 | 96 | $this->_instanceViewer->setInstance($this->_model); |
| 97 | 97 | $captions=$this->_instanceViewer->getCaptions(); |
| 98 | 98 | $table=$this->content["table"]; |
| 99 | - if($this->_hasCheckboxes){ |
|
| 99 | + if ($this->_hasCheckboxes) { |
|
| 100 | 100 | $this->_generateMainCheckbox($captions); |
| 101 | 101 | } |
| 102 | 102 | $table->setRowCount(0, \sizeof($captions)); |
| 103 | - $this->_generateHeader($table,$captions); |
|
| 103 | + $this->_generateHeader($table, $captions); |
|
| 104 | 104 | |
| 105 | - if(isset($this->_compileParts)) |
|
| 105 | + if (isset($this->_compileParts)) |
|
| 106 | 106 | $table->setCompileParts($this->_compileParts); |
| 107 | 107 | |
| 108 | 108 | $this->_generateContent($table); |
| 109 | 109 | |
| 110 | - $this->compileExtraElements($table, $captions,$js); |
|
| 110 | + $this->compileExtraElements($table, $captions, $js); |
|
| 111 | 111 | $this->_compileSearchFieldBehavior($js); |
| 112 | 112 | |
| 113 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
| 113 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
| 114 | 114 | $this->_compileForm(); |
| 115 | 115 | $this->_applyStyleAttributes($table); |
| 116 | 116 | $this->_generated=true; |
| 117 | 117 | } |
| 118 | - return parent::compile($js,$view); |
|
| 118 | + return parent::compile($js, $view); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - protected function compileExtraElements($table,$captions,JsUtils $js=NULL){ |
|
| 121 | + protected function compileExtraElements($table, $captions, JsUtils $js=NULL) { |
|
| 122 | 122 | |
| 123 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
| 123 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
| 124 | 124 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if(isset($this->_toolbar)){ |
|
| 127 | + if (isset($this->_toolbar)) { |
|
| 128 | 128 | $this->_setToolbarPosition($table, $captions); |
| 129 | 129 | } |
| 130 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
| 131 | - $this->_generatePagination($table,$js); |
|
| 130 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
| 131 | + $this->_generatePagination($table, $js); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - protected function _applyStyleAttributes($table){ |
|
| 136 | - if(isset($this->_hiddenColumns)) |
|
| 135 | + protected function _applyStyleAttributes($table) { |
|
| 136 | + if (isset($this->_hiddenColumns)) |
|
| 137 | 137 | $this->_hideColumns(); |
| 138 | - if(isset($this->_colWidths)){ |
|
| 139 | - foreach ($this->_colWidths as $colIndex=>$width){ |
|
| 140 | - $table->setColWidth($colIndex,$width); |
|
| 138 | + if (isset($this->_colWidths)) { |
|
| 139 | + foreach ($this->_colWidths as $colIndex=>$width) { |
|
| 140 | + $table->setColWidth($colIndex, $width); |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - protected function _hideColumns(){ |
|
| 146 | - foreach ($this->_hiddenColumns as $colIndex){ |
|
| 145 | + protected function _hideColumns() { |
|
| 146 | + foreach ($this->_hiddenColumns as $colIndex) { |
|
| 147 | 147 | $this->_self->hideColumn($colIndex); |
| 148 | 148 | } |
| 149 | 149 | return $this; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - protected function _generateHeader(HtmlTable $table,$captions){ |
|
| 152 | + protected function _generateHeader(HtmlTable $table, $captions) { |
|
| 153 | 153 | $table->setHeaderValues($captions); |
| 154 | - if(isset($this->_sortable)){ |
|
| 154 | + if (isset($this->_sortable)) { |
|
| 155 | 155 | $table->setSortable($this->_sortable); |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | |
| 161 | - protected function _generateContent($table){ |
|
| 161 | + protected function _generateContent($table) { |
|
| 162 | 162 | $objects=$this->_modelInstance; |
| 163 | - if(isset($this->_pagination)){ |
|
| 163 | + if (isset($this->_pagination)) { |
|
| 164 | 164 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
| 165 | 165 | } |
| 166 | 166 | InstanceViewer::setIndex(0); |
| 167 | 167 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
| 168 | 168 | return $this->_generateRow($instance, $table); |
| 169 | 169 | }); |
| 170 | - if($table->getRowCount()==0){ |
|
| 170 | + if ($table->getRowCount()==0) { |
|
| 171 | 171 | $result=$table->addRow(); |
| 172 | 172 | $result->mergeRow(); |
| 173 | 173 | $result->setValues([$this->_emptyMessage]); |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - protected function _generateRow($instance,&$table,$checkedClass=null){ |
|
| 177 | + protected function _generateRow($instance, &$table, $checkedClass=null) { |
|
| 178 | 178 | $this->_instanceViewer->setInstance($instance); |
| 179 | 179 | InstanceViewer::$index++; |
| 180 | - $values= $this->_instanceViewer->getValues(); |
|
| 180 | + $values=$this->_instanceViewer->getValues(); |
|
| 181 | 181 | $id=$this->_instanceViewer->getIdentifier(); |
| 182 | 182 | $dataAjax=$id; |
| 183 | 183 | $id=$this->cleanIdentifier($id); |
| 184 | - if($this->_hasCheckboxes){ |
|
| 185 | - $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id,""); |
|
| 184 | + if ($this->_hasCheckboxes) { |
|
| 185 | + $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, ""); |
|
| 186 | 186 | $checked=false; |
| 187 | - if(isset($this->_checkedCallback)){ |
|
| 187 | + if (isset($this->_checkedCallback)) { |
|
| 188 | 188 | $func=$this->_checkedCallback; |
| 189 | 189 | $checked=$func($instance); |
| 190 | 190 | } |
| 191 | 191 | $ck->setChecked($checked); |
| 192 | 192 | $ck->setOnChange("event.stopPropagation();"); |
| 193 | 193 | $field=$ck->getField(); |
| 194 | - $field->setProperty("value",$dataAjax); |
|
| 194 | + $field->setProperty("value", $dataAjax); |
|
| 195 | 195 | $field->setProperty("name", "selection[]"); |
| 196 | - if(isset($checkedClass)) |
|
| 196 | + if (isset($checkedClass)) |
|
| 197 | 197 | $field->setClass($checkedClass); |
| 198 | 198 | \array_unshift($values, $ck); |
| 199 | 199 | } |
| 200 | 200 | $result=$table->newRow(); |
| 201 | 201 | $result->setIdentifier($this->identifier."-tr-".$id); |
| 202 | - $result->setProperty("data-ajax",$dataAjax); |
|
| 202 | + $result->setProperty("data-ajax", $dataAjax); |
|
| 203 | 203 | $result->setValues($values); |
| 204 | - $result->addToProperty("class",$this->_rowClass); |
|
| 204 | + $result->addToProperty("class", $this->_rowClass); |
|
| 205 | 205 | return $result; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - protected function _generatePagination($table,$js=NULL){ |
|
| 209 | - if(isset($this->_toolbar)){ |
|
| 210 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 208 | + protected function _generatePagination($table, $js=NULL) { |
|
| 209 | + if (isset($this->_toolbar)) { |
|
| 210 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 211 | 211 | $this->_toolbar->setFloated("left"); |
| 212 | 212 | } |
| 213 | 213 | $footer=$table->getFooter(); |
@@ -215,44 +215,44 @@ discard block |
||
| 215 | 215 | $footer->addValues($this->_pagination->generateMenu($this->identifier)); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - protected function _associatePaginationBehavior(JsUtils $js=NULL,$offset=null){ |
|
| 219 | - if(isset($this->_urls["refresh"])){ |
|
| 220 | - $this->_pagination->getMenu()->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith","hasLoader"=>false,"jsCallback"=>'$("#'.$this->identifier.'").trigger("pageChange");']); |
|
| 218 | + protected function _associatePaginationBehavior(JsUtils $js=NULL, $offset=null) { |
|
| 219 | + if (isset($this->_urls["refresh"])) { |
|
| 220 | + $this->_pagination->getMenu()->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith", "hasLoader"=>false, "jsCallback"=>'$("#'.$this->identifier.'").trigger("pageChange");']); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - protected function _compileSearchFieldBehavior(JsUtils $js=NULL){ |
|
| 225 | - if(isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])){ |
|
| 226 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(self).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith","hasLoader"=>"internal","jsCallback"=>'$("#'.$this->identifier.'").trigger("searchTerminate",[$(self).val()]);']); |
|
| 224 | + protected function _compileSearchFieldBehavior(JsUtils $js=NULL) { |
|
| 225 | + if (isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])) { |
|
| 226 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(self).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith", "hasLoader"=>"internal", "jsCallback"=>'$("#'.$this->identifier.'").trigger("searchTerminate",[$(self).val()]);']); |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | - protected function _associateSearchFieldBehavior(JsUtils $js=NULL,$offset=null){ |
|
| 229 | + protected function _associateSearchFieldBehavior(JsUtils $js=NULL, $offset=null) { |
|
| 230 | 230 | |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - protected function _getFieldName($index){ |
|
| 233 | + protected function _getFieldName($index) { |
|
| 234 | 234 | $fieldName=parent::_getFieldName($index); |
| 235 | - if(\is_object($fieldName)) |
|
| 235 | + if (\is_object($fieldName)) |
|
| 236 | 236 | $fieldName="field-".$index; |
| 237 | 237 | return $fieldName."[]"; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - protected function _getFieldCaption($index){ |
|
| 240 | + protected function _getFieldCaption($index) { |
|
| 241 | 241 | return null; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
| 245 | - switch ($this->_toolbarPosition){ |
|
| 244 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 245 | + switch ($this->_toolbarPosition) { |
|
| 246 | 246 | case PositionInTable::BEFORETABLE: |
| 247 | 247 | case PositionInTable::AFTERTABLE: |
| 248 | - if(isset($this->_compileParts)===false){ |
|
| 248 | + if (isset($this->_compileParts)===false) { |
|
| 249 | 249 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 250 | 250 | } |
| 251 | 251 | break; |
| 252 | 252 | case PositionInTable::HEADER: |
| 253 | 253 | case PositionInTable::FOOTER: |
| 254 | 254 | case PositionInTable::BODY: |
| 255 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
| 255 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
| 256 | 256 | break; |
| 257 | 257 | } |
| 258 | 258 | } |
@@ -264,16 +264,16 @@ discard block |
||
| 264 | 264 | * @param callable $callback function called after the field compilation |
| 265 | 265 | * @return DataTable |
| 266 | 266 | */ |
| 267 | - public function afterCompile($index,$callback){ |
|
| 268 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
| 267 | + public function afterCompile($index, $callback) { |
|
| 268 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
| 269 | 269 | return $this; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - private function addToolbarRow($part,$table,$captions){ |
|
| 272 | + private function addToolbarRow($part, $table, $captions) { |
|
| 273 | 273 | $hasPart=$table->hasPart($part); |
| 274 | - if($hasPart){ |
|
| 274 | + if ($hasPart) { |
|
| 275 | 275 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 276 | - }else{ |
|
| 276 | + } else { |
|
| 277 | 277 | $row=$table->getPart($part)->getRow(0); |
| 278 | 278 | } |
| 279 | 279 | $row->mergeCol(); |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * @see Widget::getHtmlComponent() |
| 286 | 286 | * @return HtmlTable |
| 287 | 287 | */ |
| 288 | - public function getHtmlComponent(){ |
|
| 288 | + public function getHtmlComponent() { |
|
| 289 | 289 | return $this->content["table"]; |
| 290 | 290 | } |
| 291 | 291 | |
@@ -300,13 +300,13 @@ discard block |
||
| 300 | 300 | * @return DataTable |
| 301 | 301 | */ |
| 302 | 302 | public function setUrls($urls) { |
| 303 | - if(\is_array($urls)){ |
|
| 304 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
| 305 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
| 306 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
| 307 | - $this->_urls["display"]=JArray::getValue($urls, "display",3); |
|
| 308 | - }else{ |
|
| 309 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls,"display"=>$urls]; |
|
| 303 | + if (\is_array($urls)) { |
|
| 304 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
| 305 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
| 306 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
| 307 | + $this->_urls["display"]=JArray::getValue($urls, "display", 3); |
|
| 308 | + } else { |
|
| 309 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls, "display"=>$urls]; |
|
| 310 | 310 | } |
| 311 | 311 | return $this; |
| 312 | 312 | } |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 320 | 320 | * @return DataTable |
| 321 | 321 | */ |
| 322 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
| 323 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
| 322 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
| 323 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 324 | 324 | return $this; |
| 325 | 325 | } |
| 326 | 326 | |
@@ -331,8 +331,8 @@ discard block |
||
| 331 | 331 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 332 | 332 | * @return DataTable |
| 333 | 333 | */ |
| 334 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
| 335 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
| 334 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
| 335 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
| 336 | 336 | return $this; |
| 337 | 337 | } |
| 338 | 338 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | * @param array $compileParts |
| 343 | 343 | * @return DataTable |
| 344 | 344 | */ |
| 345 | - public function refresh($compileParts=["tbody"]){ |
|
| 345 | + public function refresh($compileParts=["tbody"]) { |
|
| 346 | 346 | $this->_compileParts=$compileParts; |
| 347 | 347 | return $this; |
| 348 | 348 | } |
@@ -353,14 +353,14 @@ discard block |
||
| 353 | 353 | * @param string $position |
| 354 | 354 | * @return \Ajax\common\html\HtmlDoubleElement |
| 355 | 355 | */ |
| 356 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
| 356 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 357 | 357 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - public function getSearchField(){ |
|
| 361 | - if(isset($this->_searchField)===false){ |
|
| 362 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
| 363 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
| 360 | + public function getSearchField() { |
|
| 361 | + if (isset($this->_searchField)===false) { |
|
| 362 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 363 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
| 364 | 364 | } |
| 365 | 365 | return $this->_searchField; |
| 366 | 366 | } |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * Returns a form corresponding to the Datatable |
| 381 | 381 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 382 | 382 | */ |
| 383 | - public function asForm(){ |
|
| 383 | + public function asForm() { |
|
| 384 | 384 | return $this->getForm(); |
| 385 | 385 | } |
| 386 | 386 | |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | protected function getTargetSelector($op) { |
| 390 | 390 | $result=$this->_targetSelector; |
| 391 | - if(!isset($result[$op])) |
|
| 391 | + if (!isset($result[$op])) |
|
| 392 | 392 | $result="#".$this->identifier; |
| 393 | 393 | return $result[$op]; |
| 394 | 394 | } |
@@ -399,15 +399,15 @@ discard block |
||
| 399 | 399 | * @return DataTable |
| 400 | 400 | */ |
| 401 | 401 | public function setTargetSelector($_targetSelector) { |
| 402 | - if(!\is_array($_targetSelector)){ |
|
| 403 | - $_targetSelector=["edit"=>$_targetSelector,"delete"=>$_targetSelector]; |
|
| 402 | + if (!\is_array($_targetSelector)) { |
|
| 403 | + $_targetSelector=["edit"=>$_targetSelector, "delete"=>$_targetSelector]; |
|
| 404 | 404 | } |
| 405 | 405 | $this->_targetSelector=$_targetSelector; |
| 406 | 406 | return $this; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | public function getRefreshSelector() { |
| 410 | - if(isset($this->_refreshSelector)) |
|
| 410 | + if (isset($this->_refreshSelector)) |
|
| 411 | 411 | return $this->_refreshSelector; |
| 412 | 412 | return "#".$this->identifier." tbody"; |
| 413 | 413 | } |
@@ -425,9 +425,9 @@ discard block |
||
| 425 | 425 | * {@inheritDoc} |
| 426 | 426 | * @see \Ajax\common\Widget::show() |
| 427 | 427 | */ |
| 428 | - public function show($modelInstance){ |
|
| 429 | - if(\is_array($modelInstance)){ |
|
| 430 | - if(isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
|
| 428 | + public function show($modelInstance) { |
|
| 429 | + if (\is_array($modelInstance)) { |
|
| 430 | + if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
|
| 431 | 431 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
| 432 | 432 | } |
| 433 | 433 | $this->_modelInstance=$modelInstance; |
@@ -462,29 +462,29 @@ discard block |
||
| 462 | 462 | return $this; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
| 466 | - $this->_self->setActiveRowSelector($class,$event,$multiple); |
|
| 465 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
| 466 | + $this->_self->setActiveRowSelector($class, $event, $multiple); |
|
| 467 | 467 | return $this; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - public function hideColumn($colIndex){ |
|
| 471 | - if(!\is_array($this->_hiddenColumns)) |
|
| 470 | + public function hideColumn($colIndex) { |
|
| 471 | + if (!\is_array($this->_hiddenColumns)) |
|
| 472 | 472 | $this->_hiddenColumns=[]; |
| 473 | 473 | $this->_hiddenColumns[]=$colIndex; |
| 474 | 474 | return $this; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - public function setColWidth($colIndex,$width){ |
|
| 477 | + public function setColWidth($colIndex, $width) { |
|
| 478 | 478 | $this->_colWidths[$colIndex]=$width; |
| 479 | 479 | return $this; |
| 480 | 480 | } |
| 481 | 481 | public function setColWidths($_colWidths) { |
| 482 | - $this->_colWidths = $_colWidths; |
|
| 482 | + $this->_colWidths=$_colWidths; |
|
| 483 | 483 | return $this; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - public function setColAlignment($colIndex,$alignment){ |
|
| 487 | - $this->content["table"]->setColAlignment($colIndex,$alignment); |
|
| 486 | + public function setColAlignment($colIndex, $alignment) { |
|
| 487 | + $this->content["table"]->setColAlignment($colIndex, $alignment); |
|
| 488 | 488 | return $this; |
| 489 | 489 | } |
| 490 | 490 | } |
@@ -58,18 +58,21 @@ discard block |
||
| 58 | 58 | $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
| 59 | 59 | $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
| 60 | 60 | } |
| 61 | - if(\is_array($this->_deleteBehavior)) |
|
| 62 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
| 63 | - if(\is_array($this->_editBehavior)) |
|
| 64 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
| 61 | + if(\is_array($this->_deleteBehavior)) { |
|
| 62 | + $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
| 63 | + } |
|
| 64 | + if(\is_array($this->_editBehavior)) { |
|
| 65 | + $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
| 66 | + } |
|
| 65 | 67 | if(\is_array($this->_displayBehavior)){ |
| 66 | 68 | $this->_displayBehavior["jsCallback"]='$("#dataTable").hide();'; |
| 67 | 69 | $this->_generateBehavior("display",$this->_displayBehavior,$js); |
| 68 | 70 | } |
| 69 | 71 | parent::run($js); |
| 70 | 72 | $this->_associateSearchFieldBehavior($js,$offset); |
| 71 | - if(isset($this->_pagination)) |
|
| 72 | - $this->_associatePaginationBehavior($js,$offset); |
|
| 73 | + if(isset($this->_pagination)) { |
|
| 74 | + $this->_associatePaginationBehavior($js,$offset); |
|
| 75 | + } |
|
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | protected function _generateBehavior($op,$params,JsUtils $js){ |
@@ -102,8 +105,9 @@ discard block |
||
| 102 | 105 | $table->setRowCount(0, \sizeof($captions)); |
| 103 | 106 | $this->_generateHeader($table,$captions); |
| 104 | 107 | |
| 105 | - if(isset($this->_compileParts)) |
|
| 106 | - $table->setCompileParts($this->_compileParts); |
|
| 108 | + if(isset($this->_compileParts)) { |
|
| 109 | + $table->setCompileParts($this->_compileParts); |
|
| 110 | + } |
|
| 107 | 111 | |
| 108 | 112 | $this->_generateContent($table); |
| 109 | 113 | |
@@ -133,8 +137,9 @@ discard block |
||
| 133 | 137 | } |
| 134 | 138 | |
| 135 | 139 | protected function _applyStyleAttributes($table){ |
| 136 | - if(isset($this->_hiddenColumns)) |
|
| 137 | - $this->_hideColumns(); |
|
| 140 | + if(isset($this->_hiddenColumns)) { |
|
| 141 | + $this->_hideColumns(); |
|
| 142 | + } |
|
| 138 | 143 | if(isset($this->_colWidths)){ |
| 139 | 144 | foreach ($this->_colWidths as $colIndex=>$width){ |
| 140 | 145 | $table->setColWidth($colIndex,$width); |
@@ -193,8 +198,9 @@ discard block |
||
| 193 | 198 | $field=$ck->getField(); |
| 194 | 199 | $field->setProperty("value",$dataAjax); |
| 195 | 200 | $field->setProperty("name", "selection[]"); |
| 196 | - if(isset($checkedClass)) |
|
| 197 | - $field->setClass($checkedClass); |
|
| 201 | + if(isset($checkedClass)) { |
|
| 202 | + $field->setClass($checkedClass); |
|
| 203 | + } |
|
| 198 | 204 | \array_unshift($values, $ck); |
| 199 | 205 | } |
| 200 | 206 | $result=$table->newRow(); |
@@ -207,8 +213,9 @@ discard block |
||
| 207 | 213 | |
| 208 | 214 | protected function _generatePagination($table,$js=NULL){ |
| 209 | 215 | if(isset($this->_toolbar)){ |
| 210 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 211 | - $this->_toolbar->setFloated("left"); |
|
| 216 | + if($this->_toolbarPosition==PositionInTable::FOOTER) { |
|
| 217 | + $this->_toolbar->setFloated("left"); |
|
| 218 | + } |
|
| 212 | 219 | } |
| 213 | 220 | $footer=$table->getFooter(); |
| 214 | 221 | $footer->mergeCol(); |
@@ -232,8 +239,9 @@ discard block |
||
| 232 | 239 | |
| 233 | 240 | protected function _getFieldName($index){ |
| 234 | 241 | $fieldName=parent::_getFieldName($index); |
| 235 | - if(\is_object($fieldName)) |
|
| 236 | - $fieldName="field-".$index; |
|
| 242 | + if(\is_object($fieldName)) { |
|
| 243 | + $fieldName="field-".$index; |
|
| 244 | + } |
|
| 237 | 245 | return $fieldName."[]"; |
| 238 | 246 | } |
| 239 | 247 | |
@@ -273,7 +281,7 @@ discard block |
||
| 273 | 281 | $hasPart=$table->hasPart($part); |
| 274 | 282 | if($hasPart){ |
| 275 | 283 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 276 | - }else{ |
|
| 284 | + } else{ |
|
| 277 | 285 | $row=$table->getPart($part)->getRow(0); |
| 278 | 286 | } |
| 279 | 287 | $row->mergeCol(); |
@@ -305,7 +313,7 @@ discard block |
||
| 305 | 313 | $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
| 306 | 314 | $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
| 307 | 315 | $this->_urls["display"]=JArray::getValue($urls, "display",3); |
| 308 | - }else{ |
|
| 316 | + } else{ |
|
| 309 | 317 | $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls,"display"=>$urls]; |
| 310 | 318 | } |
| 311 | 319 | return $this; |
@@ -388,8 +396,9 @@ discard block |
||
| 388 | 396 | |
| 389 | 397 | protected function getTargetSelector($op) { |
| 390 | 398 | $result=$this->_targetSelector; |
| 391 | - if(!isset($result[$op])) |
|
| 392 | - $result="#".$this->identifier; |
|
| 399 | + if(!isset($result[$op])) { |
|
| 400 | + $result="#".$this->identifier; |
|
| 401 | + } |
|
| 393 | 402 | return $result[$op]; |
| 394 | 403 | } |
| 395 | 404 | |
@@ -407,8 +416,9 @@ discard block |
||
| 407 | 416 | } |
| 408 | 417 | |
| 409 | 418 | public function getRefreshSelector() { |
| 410 | - if(isset($this->_refreshSelector)) |
|
| 411 | - return $this->_refreshSelector; |
|
| 419 | + if(isset($this->_refreshSelector)) { |
|
| 420 | + return $this->_refreshSelector; |
|
| 421 | + } |
|
| 412 | 422 | return "#".$this->identifier." tbody"; |
| 413 | 423 | } |
| 414 | 424 | |
@@ -427,8 +437,9 @@ discard block |
||
| 427 | 437 | */ |
| 428 | 438 | public function show($modelInstance){ |
| 429 | 439 | if(\is_array($modelInstance)){ |
| 430 | - if(isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
|
| 431 | - $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
| 440 | + if(isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) { |
|
| 441 | + $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
|
| 442 | + } |
|
| 432 | 443 | } |
| 433 | 444 | $this->_modelInstance=$modelInstance; |
| 434 | 445 | } |
@@ -468,8 +479,9 @@ discard block |
||
| 468 | 479 | } |
| 469 | 480 | |
| 470 | 481 | public function hideColumn($colIndex){ |
| 471 | - if(!\is_array($this->_hiddenColumns)) |
|
| 472 | - $this->_hiddenColumns=[]; |
|
| 482 | + if(!\is_array($this->_hiddenColumns)) { |
|
| 483 | + $this->_hiddenColumns=[]; |
|
| 484 | + } |
|
| 473 | 485 | $this->_hiddenColumns[]=$colIndex; |
| 474 | 486 | return $this; |
| 475 | 487 | } |
@@ -19,245 +19,245 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public static $index=0; |
| 21 | 21 | |
| 22 | - public function __construct($identifier,$instance=NULL,$captions=NULL){ |
|
| 22 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
| 23 | 23 | $this->widgetIdentifier=$identifier; |
| 24 | 24 | $this->values=[]; |
| 25 | 25 | $this->afterCompile=[]; |
| 26 | - if(isset($instance)) |
|
| 26 | + if (isset($instance)) |
|
| 27 | 27 | $this->setInstance($instance); |
| 28 | 28 | $this->setCaptions($captions); |
| 29 | 29 | $this->captionCallback=NULL; |
| 30 | - $this->defaultValueFunction=function($name,$value){return $value;}; |
|
| 30 | + $this->defaultValueFunction=function($name, $value) {return $value; }; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function moveFieldTo($from,$to){ |
|
| 34 | - if(JArray::moveElementTo($this->visibleProperties, $from, $to)){ |
|
| 33 | + public function moveFieldTo($from, $to) { |
|
| 34 | + if (JArray::moveElementTo($this->visibleProperties, $from, $to)) { |
|
| 35 | 35 | return JArray::moveElementTo($this->values, $from, $to); |
| 36 | 36 | } |
| 37 | 37 | return false; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function swapFields($index1,$index2){ |
|
| 41 | - if(JArray::swapElements($this->visibleProperties, $index1, $index2)){ |
|
| 40 | + public function swapFields($index1, $index2) { |
|
| 41 | + if (JArray::swapElements($this->visibleProperties, $index1, $index2)) { |
|
| 42 | 42 | return JArray::swapElements($this->values, $index1, $index2); |
| 43 | 43 | } |
| 44 | 44 | return false; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function removeField($index){ |
|
| 48 | - \array_splice($this->visibleProperties,$index,1); |
|
| 49 | - \array_splice($this->values,$index,1); |
|
| 50 | - \array_splice($this->captions,$index,1); |
|
| 47 | + public function removeField($index) { |
|
| 48 | + \array_splice($this->visibleProperties, $index, 1); |
|
| 49 | + \array_splice($this->values, $index, 1); |
|
| 50 | + \array_splice($this->captions, $index, 1); |
|
| 51 | 51 | return $this; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function getValues(){ |
|
| 54 | + public function getValues() { |
|
| 55 | 55 | $values=[]; |
| 56 | 56 | $index=0; |
| 57 | 57 | $count=$this->count(); |
| 58 | - while($index<$count){ |
|
| 58 | + while ($index<$count) { |
|
| 59 | 59 | $values[]=$this->getValue($index++); |
| 60 | 60 | } |
| 61 | 61 | return $values; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function getIdentifier($index=NULL){ |
|
| 65 | - if(!isset($index)) |
|
| 64 | + public function getIdentifier($index=NULL) { |
|
| 65 | + if (!isset($index)) |
|
| 66 | 66 | $index=self::$index; |
| 67 | 67 | $value=$index; |
| 68 | - if(isset($this->values["identifier"])){ |
|
| 69 | - if(\is_string($this->values["identifier"])) |
|
| 68 | + if (isset($this->values["identifier"])) { |
|
| 69 | + if (\is_string($this->values["identifier"])) |
|
| 70 | 70 | $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
| 71 | 71 | else |
| 72 | - $value=$this->values["identifier"]($index,$this->instance); |
|
| 72 | + $value=$this->values["identifier"]($index, $this->instance); |
|
| 73 | 73 | } |
| 74 | 74 | return $value; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function getValue($index){ |
|
| 77 | + public function getValue($index) { |
|
| 78 | 78 | $property=$this->properties[$index]; |
| 79 | 79 | return $this->_getValue($property, $index); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - protected function _beforeAddProperty($index,&$field){ |
|
| 82 | + protected function _beforeAddProperty($index, &$field) { |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - protected function _getDefaultValue($name,$value,$index){ |
|
| 86 | + protected function _getDefaultValue($name, $value, $index) { |
|
| 87 | 87 | $func=$this->defaultValueFunction; |
| 88 | - return $func($name,$value,$index,$this->instance); |
|
| 88 | + return $func($name, $value, $index, $this->instance); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - protected function _getPropertyValue(\ReflectionProperty $property){ |
|
| 91 | + protected function _getPropertyValue(\ReflectionProperty $property) { |
|
| 92 | 92 | $property->setAccessible(true); |
| 93 | 93 | return $property->getValue($this->instance); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - protected function _getValue($property,$index){ |
|
| 96 | + protected function _getValue($property, $index) { |
|
| 97 | 97 | $value=null; |
| 98 | 98 | $propertyName=$property; |
| 99 | - if($property instanceof \ReflectionProperty){ |
|
| 99 | + if ($property instanceof \ReflectionProperty) { |
|
| 100 | 100 | $value=$this->_getPropertyValue($property); |
| 101 | 101 | $propertyName=$property->getName(); |
| 102 | - }elseif(\is_callable($property) && array_search($property, ["system"])===false) |
|
| 102 | + }elseif (\is_callable($property) && array_search($property, ["system"])===false) |
|
| 103 | 103 | $value=$property($this->instance); |
| 104 | - elseif(\is_array($property)){ |
|
| 105 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
| 104 | + elseif (\is_array($property)) { |
|
| 105 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
| 106 | 106 | $value=\implode("", $values); |
| 107 | - }elseif(\is_string($property)){ |
|
| 107 | + }elseif (\is_string($property)) { |
|
| 108 | 108 | $value=$property; |
| 109 | - if(isset($this->instance->{$property})){ |
|
| 109 | + if (isset($this->instance->{$property})) { |
|
| 110 | 110 | $value=$this->instance->{$property}; |
| 111 | - }elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
| 111 | + }elseif (\method_exists($this->instance, $getter=JReflection::getterName($property))) { |
|
| 112 | 112 | $value=JReflection::callMethod($this->instance, $getter, []); |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | return $this->_postGetValue($index, $propertyName, $value); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - protected function _postGetValue($index,$propertyName,$value){ |
|
| 119 | - if(isset($this->values[$index])){ |
|
| 120 | - $value= $this->values[$index]($value,$this->instance,$index,self::$index); |
|
| 121 | - }else{ |
|
| 122 | - $value=$this->_getDefaultValue($propertyName,$value, $index); |
|
| 118 | + protected function _postGetValue($index, $propertyName, $value) { |
|
| 119 | + if (isset($this->values[$index])) { |
|
| 120 | + $value=$this->values[$index]($value, $this->instance, $index, self::$index); |
|
| 121 | + } else { |
|
| 122 | + $value=$this->_getDefaultValue($propertyName, $value, $index); |
|
| 123 | 123 | } |
| 124 | - if(isset($this->afterCompile[$index])){ |
|
| 125 | - if(\is_callable($this->afterCompile[$index])){ |
|
| 126 | - $this->afterCompile[$index]($value,$this->instance,self::$index); |
|
| 124 | + if (isset($this->afterCompile[$index])) { |
|
| 125 | + if (\is_callable($this->afterCompile[$index])) { |
|
| 126 | + $this->afterCompile[$index]($value, $this->instance, self::$index); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | return $value; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - public function insertField($index,$field,$key=null){ |
|
| 133 | - if(isset($key)){ |
|
| 134 | - array_splice( $this->visibleProperties, $index, 0, [$key=>$field] ); |
|
| 135 | - }else{ |
|
| 136 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
| 132 | + public function insertField($index, $field, $key=null) { |
|
| 133 | + if (isset($key)) { |
|
| 134 | + array_splice($this->visibleProperties, $index, 0, [$key=>$field]); |
|
| 135 | + } else { |
|
| 136 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
| 137 | 137 | } |
| 138 | 138 | return $this; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - public function sortColumnContent($index,$array){ |
|
| 142 | - if(isset($this->visibleProperties[$index])){ |
|
| 143 | - if(is_array($this->visibleProperties[$index])){ |
|
| 144 | - $this->visibleProperties[$index]=JArray::sortAssociative($this->visibleProperties[$index],$array); |
|
| 141 | + public function sortColumnContent($index, $array) { |
|
| 142 | + if (isset($this->visibleProperties[$index])) { |
|
| 143 | + if (is_array($this->visibleProperties[$index])) { |
|
| 144 | + $this->visibleProperties[$index]=JArray::sortAssociative($this->visibleProperties[$index], $array); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | return $this; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - public function insertInField($index,$field,$key=null){ |
|
| 150 | + public function insertInField($index, $field, $key=null) { |
|
| 151 | 151 | $vb=$this->visibleProperties; |
| 152 | - if(isset($vb[$index])){ |
|
| 153 | - if(isset($key)){ |
|
| 154 | - if(\is_array($vb[$index])){ |
|
| 152 | + if (isset($vb[$index])) { |
|
| 153 | + if (isset($key)) { |
|
| 154 | + if (\is_array($vb[$index])) { |
|
| 155 | 155 | $this->visibleProperties[$index][$key]=$field; |
| 156 | - }else{ |
|
| 157 | - $this->visibleProperties[$index]=[$vb[$index],$key=>$field]; |
|
| 156 | + } else { |
|
| 157 | + $this->visibleProperties[$index]=[$vb[$index], $key=>$field]; |
|
| 158 | 158 | } |
| 159 | - }else{ |
|
| 160 | - if(\is_array($vb[$index])){ |
|
| 159 | + } else { |
|
| 160 | + if (\is_array($vb[$index])) { |
|
| 161 | 161 | $this->visibleProperties[$index][]=$field; |
| 162 | - }else{ |
|
| 163 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
| 162 | + } else { |
|
| 163 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | - }else{ |
|
| 166 | + } else { |
|
| 167 | 167 | return $this->insertField($index, $field); |
| 168 | 168 | } |
| 169 | 169 | return $this; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - public function addField($field,$key=null){ |
|
| 173 | - if(isset($key)){ |
|
| 172 | + public function addField($field, $key=null) { |
|
| 173 | + if (isset($key)) { |
|
| 174 | 174 | $this->visibleProperties[]=[$key=>$field]; |
| 175 | - }else{ |
|
| 175 | + } else { |
|
| 176 | 176 | $this->visibleProperties[]=$field; |
| 177 | 177 | } |
| 178 | 178 | return $this; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - public function addFields($fields){ |
|
| 182 | - $this->visibleProperties=\array_merge($this->visibleProperties,$fields); |
|
| 181 | + public function addFields($fields) { |
|
| 182 | + $this->visibleProperties=\array_merge($this->visibleProperties, $fields); |
|
| 183 | 183 | return $this; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - public function count(){ |
|
| 186 | + public function count() { |
|
| 187 | 187 | return \sizeof($this->properties); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - public function visiblePropertiesCount(){ |
|
| 190 | + public function visiblePropertiesCount() { |
|
| 191 | 191 | return \sizeof($this->visibleProperties); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - public function getProperty($index){ |
|
| 194 | + public function getProperty($index) { |
|
| 195 | 195 | return $this->properties[$index]; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - public function getFieldName($index){ |
|
| 198 | + public function getFieldName($index) { |
|
| 199 | 199 | $property=$this->getProperty($index); |
| 200 | - if($property instanceof \ReflectionProperty){ |
|
| 200 | + if ($property instanceof \ReflectionProperty) { |
|
| 201 | 201 | $result=$property->getName(); |
| 202 | - }elseif(\is_callable($property)){ |
|
| 202 | + }elseif (\is_callable($property)) { |
|
| 203 | 203 | $result=$this->visibleProperties[$index]; |
| 204 | - }else{ |
|
| 204 | + } else { |
|
| 205 | 205 | $result=$property; |
| 206 | 206 | } |
| 207 | 207 | return $result; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
| 211 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
| 212 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
| 211 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
| 212 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | public function setInstance($instance) { |
| 216 | - if(\is_string($instance)){ |
|
| 216 | + if (\is_string($instance)) { |
|
| 217 | 217 | $instance=new $instance(); |
| 218 | 218 | } |
| 219 | 219 | $this->instance=$instance; |
| 220 | 220 | $this->properties=[]; |
| 221 | 221 | $this->reflect=new \ReflectionClass($instance); |
| 222 | - if(JArray::count($this->visibleProperties)===0){ |
|
| 222 | + if (JArray::count($this->visibleProperties)===0) { |
|
| 223 | 223 | $this->properties=$this->getDefaultProperties(); |
| 224 | - }else{ |
|
| 225 | - foreach ($this->visibleProperties as $property){ |
|
| 224 | + } else { |
|
| 225 | + foreach ($this->visibleProperties as $property) { |
|
| 226 | 226 | $this->setInstanceProperty($property); |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | return $this; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - private function setInstanceProperty($property){ |
|
| 233 | - if(\is_callable($property)){ |
|
| 232 | + private function setInstanceProperty($property) { |
|
| 233 | + if (\is_callable($property)) { |
|
| 234 | 234 | $this->properties[]=$property; |
| 235 | - }elseif(\is_string($property)){ |
|
| 236 | - try{ |
|
| 235 | + }elseif (\is_string($property)) { |
|
| 236 | + try { |
|
| 237 | 237 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 238 | 238 | $rProperty=$this->reflect->getProperty($property); |
| 239 | 239 | $this->properties[]=$rProperty; |
| 240 | - }catch(\Exception $e){ |
|
| 240 | + }catch (\Exception $e) { |
|
| 241 | 241 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 242 | 242 | $this->properties[]=$property; |
| 243 | 243 | } |
| 244 | - }elseif(\is_int($property)){ |
|
| 244 | + }elseif (\is_int($property)) { |
|
| 245 | 245 | $props=$this->getDefaultProperties(); |
| 246 | - if(isset($props[$property])) |
|
| 246 | + if (isset($props[$property])) |
|
| 247 | 247 | $this->properties[]=$props[$property]; |
| 248 | 248 | else |
| 249 | 249 | $this->properties[]=$property; |
| 250 | - }else{ |
|
| 250 | + } else { |
|
| 251 | 251 | $this->properties[]=$property; |
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - protected function getDefaultProperties(){ |
|
| 255 | + protected function getDefaultProperties() { |
|
| 256 | 256 | $result=[]; |
| 257 | 257 | $properties=$this->reflect->getProperties(); |
| 258 | - foreach ($properties as $property){ |
|
| 258 | + foreach ($properties as $property) { |
|
| 259 | 259 | $showable=$this->showableProperty($property); |
| 260 | - if($showable!==false){ |
|
| 260 | + if ($showable!==false) { |
|
| 261 | 261 | $result[]=$property; |
| 262 | 262 | } |
| 263 | 263 | } |
@@ -269,12 +269,12 @@ discard block |
||
| 269 | 269 | return $this; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - public function setValueFunction($index,$callback){ |
|
| 272 | + public function setValueFunction($index, $callback) { |
|
| 273 | 273 | $this->values[$index]=$callback; |
| 274 | 274 | return $this; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - public function setIdentifierFunction($callback){ |
|
| 277 | + public function setIdentifierFunction($callback) { |
|
| 278 | 278 | $this->values["identifier"]=$callback; |
| 279 | 279 | return $this; |
| 280 | 280 | } |
@@ -287,42 +287,42 @@ discard block |
||
| 287 | 287 | return $this->properties; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - public function getCaption($index){ |
|
| 291 | - if(isset($this->captions[$index])){ |
|
| 290 | + public function getCaption($index) { |
|
| 291 | + if (isset($this->captions[$index])) { |
|
| 292 | 292 | return $this->captions[$index]; |
| 293 | 293 | } |
| 294 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
| 294 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
| 295 | 295 | return $this->properties[$index]->getName(); |
| 296 | - elseif(\is_callable($this->properties[$index])) |
|
| 296 | + elseif (\is_callable($this->properties[$index])) |
|
| 297 | 297 | return ""; |
| 298 | 298 | else |
| 299 | 299 | return $this->properties[$index]; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - public function getCaptions(){ |
|
| 302 | + public function getCaptions() { |
|
| 303 | 303 | $count=$this->count(); |
| 304 | - if(isset($this->captions)){ |
|
| 305 | - $captions= \array_values($this->captions); |
|
| 304 | + if (isset($this->captions)) { |
|
| 305 | + $captions=\array_values($this->captions); |
|
| 306 | 306 | $captionsSize=\sizeof($captions); |
| 307 | - for($i=$captionsSize;$i<$count;$i++){ |
|
| 307 | + for ($i=$captionsSize; $i<$count; $i++) { |
|
| 308 | 308 | $captions[]=""; |
| 309 | 309 | } |
| 310 | - }else{ |
|
| 310 | + } else { |
|
| 311 | 311 | $captions=[]; |
| 312 | 312 | $index=0; |
| 313 | - while($index<$count){ |
|
| 313 | + while ($index<$count) { |
|
| 314 | 314 | $captions[]=$this->getCaption($index++); |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
| 317 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
| 318 | 318 | $callback=$this->captionCallback; |
| 319 | - $callback($captions,$this->instance); |
|
| 319 | + $callback($captions, $this->instance); |
|
| 320 | 320 | } |
| 321 | 321 | return $captions; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - public function setCaption($index,$caption){ |
|
| 325 | - if(isset($this->captions)===false) |
|
| 324 | + public function setCaption($index, $caption) { |
|
| 325 | + if (isset($this->captions)===false) |
|
| 326 | 326 | $this->captions=[]; |
| 327 | 327 | $this->captions[$index]=$caption; |
| 328 | 328 | return $this; |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * @param callable $callback function called after the field compilation |
| 341 | 341 | * @return InstanceViewer |
| 342 | 342 | */ |
| 343 | - public function afterCompile($index,$callback){ |
|
| 343 | + public function afterCompile($index, $callback) { |
|
| 344 | 344 | $this->afterCompile[$index]=$callback; |
| 345 | 345 | return $this; |
| 346 | 346 | } |
@@ -23,8 +23,9 @@ discard block |
||
| 23 | 23 | $this->widgetIdentifier=$identifier; |
| 24 | 24 | $this->values=[]; |
| 25 | 25 | $this->afterCompile=[]; |
| 26 | - if(isset($instance)) |
|
| 27 | - $this->setInstance($instance); |
|
| 26 | + if(isset($instance)) { |
|
| 27 | + $this->setInstance($instance); |
|
| 28 | + } |
|
| 28 | 29 | $this->setCaptions($captions); |
| 29 | 30 | $this->captionCallback=NULL; |
| 30 | 31 | $this->defaultValueFunction=function($name,$value){return $value;}; |
@@ -62,14 +63,16 @@ discard block |
||
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | public function getIdentifier($index=NULL){ |
| 65 | - if(!isset($index)) |
|
| 66 | - $index=self::$index; |
|
| 66 | + if(!isset($index)) { |
|
| 67 | + $index=self::$index; |
|
| 68 | + } |
|
| 67 | 69 | $value=$index; |
| 68 | 70 | if(isset($this->values["identifier"])){ |
| 69 | - if(\is_string($this->values["identifier"])) |
|
| 70 | - $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
| 71 | - else |
|
| 72 | - $value=$this->values["identifier"]($index,$this->instance); |
|
| 71 | + if(\is_string($this->values["identifier"])) { |
|
| 72 | + $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
| 73 | + } else { |
|
| 74 | + $value=$this->values["identifier"]($index,$this->instance); |
|
| 75 | + } |
|
| 73 | 76 | } |
| 74 | 77 | return $value; |
| 75 | 78 | } |
@@ -99,16 +102,16 @@ discard block |
||
| 99 | 102 | if($property instanceof \ReflectionProperty){ |
| 100 | 103 | $value=$this->_getPropertyValue($property); |
| 101 | 104 | $propertyName=$property->getName(); |
| 102 | - }elseif(\is_callable($property) && array_search($property, ["system"])===false) |
|
| 103 | - $value=$property($this->instance); |
|
| 104 | - elseif(\is_array($property)){ |
|
| 105 | + } elseif(\is_callable($property) && array_search($property, ["system"])===false) { |
|
| 106 | + $value=$property($this->instance); |
|
| 107 | + } elseif(\is_array($property)){ |
|
| 105 | 108 | $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
| 106 | 109 | $value=\implode("", $values); |
| 107 | - }elseif(\is_string($property)){ |
|
| 110 | + } elseif(\is_string($property)){ |
|
| 108 | 111 | $value=$property; |
| 109 | 112 | if(isset($this->instance->{$property})){ |
| 110 | 113 | $value=$this->instance->{$property}; |
| 111 | - }elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
| 114 | + } elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
| 112 | 115 | $value=JReflection::callMethod($this->instance, $getter, []); |
| 113 | 116 | } |
| 114 | 117 | } |
@@ -118,7 +121,7 @@ discard block |
||
| 118 | 121 | protected function _postGetValue($index,$propertyName,$value){ |
| 119 | 122 | if(isset($this->values[$index])){ |
| 120 | 123 | $value= $this->values[$index]($value,$this->instance,$index,self::$index); |
| 121 | - }else{ |
|
| 124 | + } else{ |
|
| 122 | 125 | $value=$this->_getDefaultValue($propertyName,$value, $index); |
| 123 | 126 | } |
| 124 | 127 | if(isset($this->afterCompile[$index])){ |
@@ -132,7 +135,7 @@ discard block |
||
| 132 | 135 | public function insertField($index,$field,$key=null){ |
| 133 | 136 | if(isset($key)){ |
| 134 | 137 | array_splice( $this->visibleProperties, $index, 0, [$key=>$field] ); |
| 135 | - }else{ |
|
| 138 | + } else{ |
|
| 136 | 139 | array_splice( $this->visibleProperties, $index, 0, $field ); |
| 137 | 140 | } |
| 138 | 141 | return $this; |
@@ -153,17 +156,17 @@ discard block |
||
| 153 | 156 | if(isset($key)){ |
| 154 | 157 | if(\is_array($vb[$index])){ |
| 155 | 158 | $this->visibleProperties[$index][$key]=$field; |
| 156 | - }else{ |
|
| 159 | + } else{ |
|
| 157 | 160 | $this->visibleProperties[$index]=[$vb[$index],$key=>$field]; |
| 158 | 161 | } |
| 159 | - }else{ |
|
| 162 | + } else{ |
|
| 160 | 163 | if(\is_array($vb[$index])){ |
| 161 | 164 | $this->visibleProperties[$index][]=$field; |
| 162 | - }else{ |
|
| 165 | + } else{ |
|
| 163 | 166 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
| 164 | 167 | } |
| 165 | 168 | } |
| 166 | - }else{ |
|
| 169 | + } else{ |
|
| 167 | 170 | return $this->insertField($index, $field); |
| 168 | 171 | } |
| 169 | 172 | return $this; |
@@ -172,7 +175,7 @@ discard block |
||
| 172 | 175 | public function addField($field,$key=null){ |
| 173 | 176 | if(isset($key)){ |
| 174 | 177 | $this->visibleProperties[]=[$key=>$field]; |
| 175 | - }else{ |
|
| 178 | + } else{ |
|
| 176 | 179 | $this->visibleProperties[]=$field; |
| 177 | 180 | } |
| 178 | 181 | return $this; |
@@ -199,9 +202,9 @@ discard block |
||
| 199 | 202 | $property=$this->getProperty($index); |
| 200 | 203 | if($property instanceof \ReflectionProperty){ |
| 201 | 204 | $result=$property->getName(); |
| 202 | - }elseif(\is_callable($property)){ |
|
| 205 | + } elseif(\is_callable($property)){ |
|
| 203 | 206 | $result=$this->visibleProperties[$index]; |
| 204 | - }else{ |
|
| 207 | + } else{ |
|
| 205 | 208 | $result=$property; |
| 206 | 209 | } |
| 207 | 210 | return $result; |
@@ -221,7 +224,7 @@ discard block |
||
| 221 | 224 | $this->reflect=new \ReflectionClass($instance); |
| 222 | 225 | if(JArray::count($this->visibleProperties)===0){ |
| 223 | 226 | $this->properties=$this->getDefaultProperties(); |
| 224 | - }else{ |
|
| 227 | + } else{ |
|
| 225 | 228 | foreach ($this->visibleProperties as $property){ |
| 226 | 229 | $this->setInstanceProperty($property); |
| 227 | 230 | } |
@@ -232,22 +235,23 @@ discard block |
||
| 232 | 235 | private function setInstanceProperty($property){ |
| 233 | 236 | if(\is_callable($property)){ |
| 234 | 237 | $this->properties[]=$property; |
| 235 | - }elseif(\is_string($property)){ |
|
| 238 | + } elseif(\is_string($property)){ |
|
| 236 | 239 | try{ |
| 237 | 240 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 238 | 241 | $rProperty=$this->reflect->getProperty($property); |
| 239 | 242 | $this->properties[]=$rProperty; |
| 240 | - }catch(\Exception $e){ |
|
| 243 | + } catch(\Exception $e){ |
|
| 241 | 244 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 242 | 245 | $this->properties[]=$property; |
| 243 | 246 | } |
| 244 | - }elseif(\is_int($property)){ |
|
| 247 | + } elseif(\is_int($property)){ |
|
| 245 | 248 | $props=$this->getDefaultProperties(); |
| 246 | - if(isset($props[$property])) |
|
| 247 | - $this->properties[]=$props[$property]; |
|
| 248 | - else |
|
| 249 | - $this->properties[]=$property; |
|
| 250 | - }else{ |
|
| 249 | + if(isset($props[$property])) { |
|
| 250 | + $this->properties[]=$props[$property]; |
|
| 251 | + } else { |
|
| 252 | + $this->properties[]=$property; |
|
| 253 | + } |
|
| 254 | + } else{ |
|
| 251 | 255 | $this->properties[]=$property; |
| 252 | 256 | } |
| 253 | 257 | } |
@@ -291,12 +295,13 @@ discard block |
||
| 291 | 295 | if(isset($this->captions[$index])){ |
| 292 | 296 | return $this->captions[$index]; |
| 293 | 297 | } |
| 294 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
| 295 | - return $this->properties[$index]->getName(); |
|
| 296 | - elseif(\is_callable($this->properties[$index])) |
|
| 297 | - return ""; |
|
| 298 | - else |
|
| 299 | - return $this->properties[$index]; |
|
| 298 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
| 299 | + return $this->properties[$index]->getName(); |
|
| 300 | + } elseif(\is_callable($this->properties[$index])) { |
|
| 301 | + return ""; |
|
| 302 | + } else { |
|
| 303 | + return $this->properties[$index]; |
|
| 304 | + } |
|
| 300 | 305 | } |
| 301 | 306 | |
| 302 | 307 | public function getCaptions(){ |
@@ -307,7 +312,7 @@ discard block |
||
| 307 | 312 | for($i=$captionsSize;$i<$count;$i++){ |
| 308 | 313 | $captions[]=""; |
| 309 | 314 | } |
| 310 | - }else{ |
|
| 315 | + } else{ |
|
| 311 | 316 | $captions=[]; |
| 312 | 317 | $index=0; |
| 313 | 318 | while($index<$count){ |
@@ -322,8 +327,9 @@ discard block |
||
| 322 | 327 | } |
| 323 | 328 | |
| 324 | 329 | public function setCaption($index,$caption){ |
| 325 | - if(isset($this->captions)===false) |
|
| 326 | - $this->captions=[]; |
|
| 330 | + if(isset($this->captions)===false) { |
|
| 331 | + $this->captions=[]; |
|
| 332 | + } |
|
| 327 | 333 | $this->captions[$index]=$caption; |
| 328 | 334 | return $this; |
| 329 | 335 | } |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | * @author jc |
| 11 | 11 | * |
| 12 | 12 | */ |
| 13 | -class Visibility extends SimpleSemExtComponent{ |
|
| 13 | +class Visibility extends SimpleSemExtComponent { |
|
| 14 | 14 | |
| 15 | 15 | public function __construct(JsUtils $js) { |
| 16 | 16 | parent::__construct($js); |
| 17 | 17 | $this->uiName="visibility"; |
| 18 | - $this->params=["once"=>false,"observeChanges"=>true]; |
|
| 18 | + $this->params=["once"=>false, "observeChanges"=>true]; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function setOnce($value=false) { |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function __construct($identifier, $rowCount, $colCount) { |
| 33 | 33 | parent::__construct($identifier, "table", "ui table"); |
| 34 | - $this->content=array (); |
|
| 34 | + $this->content=array(); |
|
| 35 | 35 | $this->setRowCount($rowCount, $colCount); |
| 36 | - $this->_variations=[ Variation::CELLED,Variation::PADDED,Variation::COMPACT ]; |
|
| 37 | - $this->_compileParts=["thead","tbody","tfoot"]; |
|
| 36 | + $this->_variations=[Variation::CELLED, Variation::PADDED, Variation::COMPACT]; |
|
| 37 | + $this->_compileParts=["thead", "tbody", "tfoot"]; |
|
| 38 | 38 | $this->_afterCompileEvents=[]; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | * @return HtmlTableContent |
| 45 | 45 | */ |
| 46 | 46 | public function getPart($key) { |
| 47 | - if (\array_key_exists($key, $this->content) === false) { |
|
| 47 | + if (\array_key_exists($key, $this->content)===false) { |
|
| 48 | 48 | $this->content[$key]=new HtmlTableContent("", $key); |
| 49 | - if ($key !== "tbody") { |
|
| 49 | + if ($key!=="tbody") { |
|
| 50 | 50 | $this->content[$key]->setRowCount(1, $this->_colCount); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | return $this->content[$key]; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - protected function _getFirstPart(){ |
|
| 57 | - if(isset($this->content["thead"])){ |
|
| 56 | + protected function _getFirstPart() { |
|
| 57 | + if (isset($this->content["thead"])) { |
|
| 58 | 58 | return $this->content["thead"]; |
| 59 | 59 | } |
| 60 | 60 | return $this->content["tbody"]; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @return boolean |
| 100 | 100 | */ |
| 101 | 101 | public function hasPart($key) { |
| 102 | - return \array_key_exists($key, $this->content) === true; |
|
| 102 | + return \array_key_exists($key, $this->content)===true; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | return $this->colAlign($colIndex, "colLeft"); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - public function setColAlignment($colIndex,$alignment){ |
|
| 236 | - switch ($alignment){ |
|
| 235 | + public function setColAlignment($colIndex, $alignment) { |
|
| 236 | + switch ($alignment) { |
|
| 237 | 237 | case TextAlignment::LEFT: |
| 238 | 238 | $function="colLeft"; |
| 239 | 239 | break; |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | private function colAlign($colIndex, $function) { |
| 257 | 257 | if (\is_array($colIndex)) { |
| 258 | - foreach ( $colIndex as $cIndex ) { |
|
| 258 | + foreach ($colIndex as $cIndex) { |
|
| 259 | 259 | $this->colAlign($cIndex, $function); |
| 260 | 260 | } |
| 261 | 261 | } else { |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | * @see HtmlSemDoubleElement::compile() |
| 317 | 317 | */ |
| 318 | 318 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 319 | - if(\sizeof($this->_compileParts)<3){ |
|
| 319 | + if (\sizeof($this->_compileParts)<3) { |
|
| 320 | 320 | $this->_template="%content%"; |
| 321 | 321 | $this->refresh($js); |
| 322 | 322 | } |
@@ -325,9 +325,9 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
| 328 | - parent::compile_once($js,$view); |
|
| 328 | + parent::compile_once($js, $view); |
|
| 329 | 329 | if ($this->propertyContains("class", "sortable")) { |
| 330 | - $this->addEvent("execute", "$('#" . $this->identifier . "').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
| 330 | + $this->addEvent("execute", "$('#".$this->identifier."').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | |
@@ -340,13 +340,13 @@ discard block |
||
| 340 | 340 | public function fromDatabaseObject($object, $function) { |
| 341 | 341 | $result=$function($object); |
| 342 | 342 | if (\is_array($result)) { |
| 343 | - $result= $this->addRow($function($object)); |
|
| 343 | + $result=$this->addRow($function($object)); |
|
| 344 | 344 | } else { |
| 345 | - $result= $this->getBody()->_addRow($result); |
|
| 345 | + $result=$this->getBody()->_addRow($result); |
|
| 346 | 346 | } |
| 347 | - if(isset($this->_afterCompileEvents["onNewRow"])){ |
|
| 348 | - if(\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
| 349 | - $this->_afterCompileEvents["onNewRow"]($result,$object); |
|
| 347 | + if (isset($this->_afterCompileEvents["onNewRow"])) { |
|
| 348 | + if (\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
| 349 | + $this->_afterCompileEvents["onNewRow"]($result, $object); |
|
| 350 | 350 | } |
| 351 | 351 | return $result; |
| 352 | 352 | } |
@@ -361,20 +361,20 @@ discard block |
||
| 361 | 361 | return $this; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - public function refresh($js){ |
|
| 364 | + public function refresh($js) { |
|
| 365 | 365 | $this->_footer=$this->getFooter(); |
| 366 | - if(isset($js)){ |
|
| 367 | - $js->exec('$("#'.$this->identifier.' tfoot").replaceWith("'.\addslashes($this->_footer).'");',true); |
|
| 366 | + if (isset($js)) { |
|
| 367 | + $js->exec('$("#'.$this->identifier.' tfoot").replaceWith("'.\addslashes($this->_footer).'");', true); |
|
| 368 | 368 | } |
| 369 | 369 | //$this->addEvent("execute", '$("#'.$this->identifier.' tfoot").replaceWith("'.\addslashes($this->_footer).'");'); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - public function run(JsUtils $js){ |
|
| 373 | - if(isset($this->_activeRowSelector)){ |
|
| 372 | + public function run(JsUtils $js) { |
|
| 373 | + if (isset($this->_activeRowSelector)) { |
|
| 374 | 374 | $this->_activeRowSelector->run(); |
| 375 | 375 | } |
| 376 | - $result= parent::run($js); |
|
| 377 | - if(isset($this->_footer)) |
|
| 376 | + $result=parent::run($js); |
|
| 377 | + if (isset($this->_footer)) |
|
| 378 | 378 | $this->_footer->run($js); |
| 379 | 379 | return $result; |
| 380 | 380 | } |
@@ -397,47 +397,47 @@ discard block |
||
| 397 | 397 | * @param boolean $multiple |
| 398 | 398 | * @return HtmlTable |
| 399 | 399 | */ |
| 400 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
| 401 | - $this->_activeRowSelector=new ActiveRow($this,$class,$event,$multiple); |
|
| 400 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
| 401 | + $this->_activeRowSelector=new ActiveRow($this, $class, $event, $multiple); |
|
| 402 | 402 | return $this; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - public function hideColumn($colIndex){ |
|
| 406 | - if(isset($this->content["thead"])){ |
|
| 405 | + public function hideColumn($colIndex) { |
|
| 406 | + if (isset($this->content["thead"])) { |
|
| 407 | 407 | $this->content["thead"]->hideColumn($colIndex); |
| 408 | 408 | } |
| 409 | 409 | $this->content["tbody"]->hideColumn($colIndex); |
| 410 | - if(isset($this->content["tfoot"])){ |
|
| 410 | + if (isset($this->content["tfoot"])) { |
|
| 411 | 411 | $this->content["tfoot"]->hideColumn($colIndex); |
| 412 | 412 | } |
| 413 | 413 | return $this; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - public function setColWidth($colIndex,$width){ |
|
| 416 | + public function setColWidth($colIndex, $width) { |
|
| 417 | 417 | $part=$this->_getFirstPart(); |
| 418 | - if($part!==null && $part->count()>0) |
|
| 418 | + if ($part!==null && $part->count()>0) |
|
| 419 | 419 | $part->getCell(0, $colIndex)->setWidth($width); |
| 420 | 420 | return $this; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - public function setColWidths($widths){ |
|
| 423 | + public function setColWidths($widths) { |
|
| 424 | 424 | $part=$this->_getFirstPart(); |
| 425 | - if($part!==null && $part->count()>0){ |
|
| 425 | + if ($part!==null && $part->count()>0) { |
|
| 426 | 426 | $count=$part->getColCount(); |
| 427 | - if(!\is_array($widths)){ |
|
| 427 | + if (!\is_array($widths)) { |
|
| 428 | 428 | $widths=\array_fill(0, $count, $widths); |
| 429 | 429 | } |
| 430 | - $max=\min(\sizeof($widths),$count); |
|
| 431 | - for($i=0;$i<$max;$i++){ |
|
| 430 | + $max=\min(\sizeof($widths), $count); |
|
| 431 | + for ($i=0; $i<$max; $i++) { |
|
| 432 | 432 | $part->getCell(0, $i)->setWidth($widths[$i]); |
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | return $this; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - public function mergeIdentiqualValues($colIndex,$function="strip_tags"){ |
|
| 438 | + public function mergeIdentiqualValues($colIndex, $function="strip_tags") { |
|
| 439 | 439 | $body=$this->getBody(); |
| 440 | - $body->mergeIdentiqualValues($colIndex,$function); |
|
| 440 | + $body->mergeIdentiqualValues($colIndex, $function); |
|
| 441 | 441 | return $this; |
| 442 | 442 | } |
| 443 | 443 | /** |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | * @param mixed $_innerScript |
| 452 | 452 | */ |
| 453 | 453 | public function setInnerScript($_innerScript) { |
| 454 | - $this->_innerScript = $_innerScript; |
|
| 454 | + $this->_innerScript=$_innerScript; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | } |
@@ -345,8 +345,9 @@ discard block |
||
| 345 | 345 | $result= $this->getBody()->_addRow($result); |
| 346 | 346 | } |
| 347 | 347 | if(isset($this->_afterCompileEvents["onNewRow"])){ |
| 348 | - if(\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
| 349 | - $this->_afterCompileEvents["onNewRow"]($result,$object); |
|
| 348 | + if(\is_callable($this->_afterCompileEvents["onNewRow"])) { |
|
| 349 | + $this->_afterCompileEvents["onNewRow"]($result,$object); |
|
| 350 | + } |
|
| 350 | 351 | } |
| 351 | 352 | return $result; |
| 352 | 353 | } |
@@ -374,8 +375,9 @@ discard block |
||
| 374 | 375 | $this->_activeRowSelector->run(); |
| 375 | 376 | } |
| 376 | 377 | $result= parent::run($js); |
| 377 | - if(isset($this->_footer)) |
|
| 378 | - $this->_footer->run($js); |
|
| 378 | + if(isset($this->_footer)) { |
|
| 379 | + $this->_footer->run($js); |
|
| 380 | + } |
|
| 379 | 381 | return $result; |
| 380 | 382 | } |
| 381 | 383 | |
@@ -415,8 +417,9 @@ discard block |
||
| 415 | 417 | |
| 416 | 418 | public function setColWidth($colIndex,$width){ |
| 417 | 419 | $part=$this->_getFirstPart(); |
| 418 | - if($part!==null && $part->count()>0) |
|
| 419 | - $part->getCell(0, $colIndex)->setWidth($width); |
|
| 420 | + if($part!==null && $part->count()>0) { |
|
| 421 | + $part->getCell(0, $colIndex)->setWidth($width); |
|
| 422 | + } |
|
| 420 | 423 | return $this; |
| 421 | 424 | } |
| 422 | 425 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param string $event |
| 22 | 22 | * @param boolean $multiple |
| 23 | 23 | */ |
| 24 | - public function __construct($table,$class="active",$event="click",$multiple=false){ |
|
| 24 | + public function __construct($table, $class="active", $event="click", $multiple=false) { |
|
| 25 | 25 | $this->table=$table; |
| 26 | 26 | $this->class=$class; |
| 27 | 27 | $this->event=$event; |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | return $this; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public function run(){ |
|
| 58 | + public function run() { |
|
| 59 | 59 | $multiple=""; |
| 60 | - if(!$this->multiple){ |
|
| 60 | + if (!$this->multiple) { |
|
| 61 | 61 | $multiple="$(this).closest('tbody').children('tr').removeClass('".$this->class."');"; |
| 62 | 62 | } |
| 63 | - $this->table->onRow($this->event, $multiple."$(this).toggleClass('".$this->class."');",false,false); |
|
| 63 | + $this->table->onRow($this->event, $multiple."$(this).toggleClass('".$this->class."');", false, false); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | } |