@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
17 | 17 | |
18 | 18 | abstract public function getUrl($url); |
19 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
19 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
20 | 20 | |
21 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
21 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
22 | 22 | $jsCallback=null; |
23 | 23 | $attr="id"; |
24 | 24 | $hasLoader=true; |
@@ -36,80 +36,80 @@ discard block |
||
36 | 36 | $retour=$this->_getAjaxUrl($url, $attr); |
37 | 37 | $responseElement=$this->_getResponseElement($responseElement); |
38 | 38 | $retour.="var self=this;\n"; |
39 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
40 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
39 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
40 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
41 | 41 | } |
42 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
43 | - if(!$async){ |
|
42 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
43 | + if (!$async) { |
|
44 | 44 | $ajaxParameters["async"]="false"; |
45 | 45 | } |
46 | - if(isset($params)){ |
|
46 | + if (isset($params)) { |
|
47 | 47 | $ajaxParameters["data"]=self::_correctParams($params); |
48 | 48 | } |
49 | - if(isset($headers)){ |
|
49 | + if (isset($headers)) { |
|
50 | 50 | $ajaxParameters["headers"]=$headers; |
51 | 51 | } |
52 | 52 | $this->createAjaxParameters($ajaxParameters, $parameters); |
53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
54 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
55 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
54 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
55 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
56 | 56 | if ($immediatly) |
57 | 57 | $this->jquery_code_for_compile[]=$retour; |
58 | 58 | return $retour; |
59 | 59 | } |
60 | 60 | |
61 | - protected function createAjaxParameters(&$original,$parameters){ |
|
62 | - $validParameters=["dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
63 | - foreach ($validParameters as $param=>$mask){ |
|
64 | - if(isset($parameters[$param])){ |
|
61 | + protected function createAjaxParameters(&$original, $parameters) { |
|
62 | + $validParameters=["dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
63 | + foreach ($validParameters as $param=>$mask) { |
|
64 | + if (isset($parameters[$param])) { |
|
65 | 65 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
71 | - $s = ''; foreach ($ajaxParameters as $k=>$v) { if ($s !== '') { $s .= ','; } $s .= "'{$k}':{$v}"; } |
|
70 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
71 | + $s=''; foreach ($ajaxParameters as $k=>$v) { if ($s!=='') { $s.=','; } $s.="'{$k}':{$v}"; } |
|
72 | 72 | return $s; |
73 | 73 | } |
74 | 74 | |
75 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
76 | - if(isset($jsCondition)){ |
|
75 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
76 | + if (isset($jsCondition)) { |
|
77 | 77 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
78 | 78 | } |
79 | 79 | return $jsSource; |
80 | 80 | } |
81 | 81 | |
82 | 82 | |
83 | - protected function _getAjaxUrl($url,$attr){ |
|
83 | + protected function _getAjaxUrl($url, $attr) { |
|
84 | 84 | $url=$this->_correctAjaxUrl($url); |
85 | 85 | $retour="url='".$url."';"; |
86 | 86 | $slash="/"; |
87 | - if(JString::endswith($url, "/")===true){ |
|
87 | + if (JString::endswith($url, "/")===true) { |
|
88 | 88 | $slash=""; |
89 | 89 | } |
90 | - if(JString::isNotNull($attr)){ |
|
91 | - if ($attr==="value"){ |
|
90 | + if (JString::isNotNull($attr)) { |
|
91 | + if ($attr==="value") { |
|
92 | 92 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
93 | - }elseif ($attr==="html"){ |
|
93 | + }elseif ($attr==="html") { |
|
94 | 94 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
95 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
95 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
96 | 96 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
97 | - }elseif($attr!==null && $attr!=="") |
|
97 | + }elseif ($attr!==null && $attr!=="") |
|
98 | 98 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
99 | 99 | } |
100 | 100 | return $retour; |
101 | 101 | } |
102 | 102 | |
103 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
104 | - $retour="";$call=null; |
|
103 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
104 | + $retour=""; $call=null; |
|
105 | 105 | if (JString::isNotNull($responseElement)) { |
106 | - if(isset($ajaxTransition)){ |
|
106 | + if (isset($ajaxTransition)) { |
|
107 | 107 | $call=$this->setAjaxDataCall($ajaxTransition); |
108 | - }elseif(isset($this->ajaxTransition)){ |
|
108 | + }elseif (isset($this->ajaxTransition)) { |
|
109 | 109 | $call=$this->ajaxTransition; |
110 | 110 | } |
111 | - if(\is_callable($call)) |
|
112 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
111 | + if (\is_callable($call)) |
|
112 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
113 | 113 | else |
114 | 114 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
115 | 115 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | return $retour; |
118 | 118 | } |
119 | 119 | |
120 | - protected function _getResponseElement($responseElement){ |
|
120 | + protected function _getResponseElement($responseElement) { |
|
121 | 121 | if (JString::isNotNull($responseElement)) { |
122 | 122 | $responseElement=Javascript::prep_value($responseElement); |
123 | 123 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
@@ -128,33 +128,33 @@ discard block |
||
128 | 128 | protected function _correctAjaxUrl($url) { |
129 | 129 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
130 | 130 | $url=substr($url, 0, strlen($url)-1); |
131 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
131 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
132 | 132 | $url=$this->getUrl($url); |
133 | 133 | } |
134 | 134 | return $url; |
135 | 135 | } |
136 | 136 | |
137 | - public static function _correctParams($params){ |
|
138 | - if(JString::isNull($params)){ |
|
137 | + public static function _correctParams($params) { |
|
138 | + if (JString::isNull($params)) { |
|
139 | 139 | return ""; |
140 | 140 | } |
141 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
141 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
142 | 142 | return '$.param('.$params.')'; |
143 | 143 | } |
144 | 144 | return $params; |
145 | 145 | } |
146 | 146 | |
147 | - public static function _implodeParams($parameters){ |
|
147 | + public static function _implodeParams($parameters) { |
|
148 | 148 | $allParameters=[]; |
149 | - foreach ($parameters as $params){ |
|
150 | - if(isset($params)) |
|
149 | + foreach ($parameters as $params) { |
|
150 | + if (isset($params)) |
|
151 | 151 | $allParameters[]=self::_correctParams($params); |
152 | 152 | } |
153 | 153 | return \implode("+'&'+", $allParameters); |
154 | 154 | } |
155 | 155 | |
156 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
157 | - if(!isset($ajaxLoader)){ |
|
156 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
157 | + if (!isset($ajaxLoader)) { |
|
158 | 158 | $ajaxLoader=$this->ajaxLoader; |
159 | 159 | } |
160 | 160 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -162,19 +162,19 @@ discard block |
||
162 | 162 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
163 | 163 | } |
164 | 164 | |
165 | - protected function setAjaxDataCall($params){ |
|
165 | + protected function setAjaxDataCall($params) { |
|
166 | 166 | $result=null; |
167 | - if(!\is_callable($params)){ |
|
168 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
169 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
167 | + if (!\is_callable($params)) { |
|
168 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
169 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
170 | 170 | }; |
171 | 171 | } |
172 | 172 | return $result; |
173 | 173 | } |
174 | 174 | |
175 | - protected function setDefaultParameters(&$parameters,$default){ |
|
176 | - foreach ($default as $k=>$v){ |
|
177 | - if(!isset($parameters[$k])) |
|
175 | + protected function setDefaultParameters(&$parameters, $default) { |
|
176 | + foreach ($default as $k=>$v) { |
|
177 | + if (!isset($parameters[$k])) |
|
178 | 178 | $parameters[$k]=$v; |
179 | 179 | } |
180 | 180 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param string $url The url of the request |
189 | 189 | * @param string $responseElement selector of the HTML element displaying the answer |
190 | 190 | */ |
191 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
192 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
191 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
192 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * @param string $responseElement selector of the HTML element displaying the answer |
199 | 199 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
200 | 200 | */ |
201 | - public function get($url, $responseElement="",$parameters=[]) { |
|
201 | + public function get($url, $responseElement="", $parameters=[]) { |
|
202 | 202 | $parameters["immediatly"]=true; |
203 | - return $this->_get($url,$responseElement,$parameters); |
|
203 | + return $this->_get($url, $responseElement, $parameters); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | * @param string $responseElement selector of the HTML element displaying the answer |
211 | 211 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
212 | 212 | */ |
213 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
213 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
214 | 214 | $parameters["immediatly"]=true; |
215 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
215 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | * @param string $responseElement selector of the HTML element displaying the answer |
223 | 223 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
224 | 224 | */ |
225 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
225 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
226 | 226 | $parameters["immediatly"]=false; |
227 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
227 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,15 +233,15 @@ discard block |
||
233 | 233 | * @param string $method Method used |
234 | 234 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
235 | 235 | */ |
236 | - private function _json($url, $method="get",$parameters=[]) { |
|
237 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
236 | + private function _json($url, $method="get", $parameters=[]) { |
|
237 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
238 | 238 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
239 | 239 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
240 | 240 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n\tfor(var key in data){" |
241 | 241 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
242 | 242 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
243 | 243 | $parameters["jsCallback"]=$retour; |
244 | - return $this->_ajax($method, $url,null,$parameters); |
|
244 | + return $this->_ajax($method, $url, null, $parameters); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
252 | 252 | */ |
253 | 253 | public function json($url, $method="get", $parameters=[]) { |
254 | - return $this->_json($url,$method,$parameters); |
|
254 | + return $this->_json($url, $method, $parameters); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * @param string $method default get |
263 | 263 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
264 | 264 | */ |
265 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
266 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
267 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
265 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
266 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
267 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | */ |
276 | 276 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
277 | 277 | $parameters["immediatly"]=false; |
278 | - return $this->_json($url,$method,$parameters); |
|
278 | + return $this->_json($url, $method, $parameters); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -286,26 +286,26 @@ discard block |
||
286 | 286 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
287 | 287 | */ |
288 | 288 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
289 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
289 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
290 | 290 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
291 | 291 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
292 | 292 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
293 | - if($context===null){ |
|
293 | + if ($context===null) { |
|
294 | 294 | $parent="$('".$maskSelector."').parent()"; |
295 | - $newElm = "$('#'+newId)"; |
|
296 | - }else{ |
|
295 | + $newElm="$('#'+newId)"; |
|
296 | + } else { |
|
297 | 297 | $parent=$context; |
298 | - $newElm = $context.".find('#'+newId)"; |
|
298 | + $newElm=$context.".find('#'+newId)"; |
|
299 | 299 | } |
300 | 300 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
301 | 301 | $retour=$parent.".find('.{$rowClass}').remove();"; |
302 | 302 | $retour.="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
303 | 303 | 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"; |
304 | - $retour.= $appendTo; |
|
304 | + $retour.=$appendTo; |
|
305 | 305 | $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"; |
306 | 306 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
307 | 307 | $parameters["jsCallback"]=$retour; |
308 | - return $this->_ajax($method, $url,null,$parameters); |
|
308 | + return $this->_ajax($method, $url, null, $parameters); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
317 | 317 | */ |
318 | 318 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
319 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
319 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | * @param string $method Method used, default : get |
340 | 340 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
341 | 341 | */ |
342 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
343 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
344 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
342 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
343 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
344 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
355 | 355 | $parameters["immediatly"]=false; |
356 | - return $this->_get($url, $responseElement,$parameters); |
|
356 | + return $this->_get($url, $responseElement, $parameters); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | * @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) |
367 | 367 | */ |
368 | 368 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
369 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
370 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
369 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
370 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | * @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) |
381 | 381 | */ |
382 | 382 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
383 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
384 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
383 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
384 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -408,9 +408,9 @@ discard block |
||
408 | 408 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
409 | 409 | } |
410 | 410 | |
411 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
411 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
412 | 412 | $parameters["params"]=$params; |
413 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
413 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $params JSON parameters |
421 | 421 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
422 | 422 | */ |
423 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
424 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
423 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
424 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @param string $responseElement selector of the HTML element displaying the answer |
433 | 433 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
434 | 434 | */ |
435 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
435 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
436 | 436 | $parameters["immediatly"]=false; |
437 | 437 | return $this->_post($url, $params, $responseElement, $parameters); |
438 | 438 | } |
@@ -448,8 +448,8 @@ discard block |
||
448 | 448 | * @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) |
449 | 449 | */ |
450 | 450 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
451 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
452 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
451 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
452 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -466,28 +466,28 @@ discard block |
||
466 | 466 | } |
467 | 467 | |
468 | 468 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
469 | - $params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$ajaxLoader=null;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL;$async=true; |
|
469 | + $params="{}"; $validation=false; $jsCallback=NULL; $attr="id"; $hasLoader=true; $ajaxLoader=null; $jqueryDone="html"; $ajaxTransition=null; $immediatly=false; $jsCondition=NULL; $headers=NULL; $async=true; |
|
470 | 470 | \extract($parameters); |
471 | - $async=($async)?"true":"false"; |
|
471 | + $async=($async) ? "true" : "false"; |
|
472 | 472 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
473 | 473 | $retour=$this->_getAjaxUrl($url, $attr); |
474 | 474 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
475 | 475 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
476 | - if(isset($params)){ |
|
476 | + if (isset($params)) { |
|
477 | 477 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
478 | 478 | } |
479 | 479 | $responseElement=$this->_getResponseElement($responseElement); |
480 | 480 | $retour.="var self=this;\n"; |
481 | - if($hasLoader===true){ |
|
482 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
481 | + if ($hasLoader===true) { |
|
482 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
483 | 483 | } |
484 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
485 | - if(isset($headers)){ |
|
484 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
485 | + if (isset($headers)) { |
|
486 | 486 | $ajaxParameters["headers"]=$headers; |
487 | 487 | } |
488 | 488 | $this->createAjaxParameters($ajaxParameters, $parameters); |
489 | 489 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
490 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
490 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
491 | 491 | |
492 | 492 | if ($validation) { |
493 | 493 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -537,8 +537,8 @@ discard block |
||
537 | 537 | * @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) |
538 | 538 | */ |
539 | 539 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
540 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
541 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
540 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
541 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
@@ -14,27 +14,27 @@ discard block |
||
14 | 14 | * @author jc |
15 | 15 | * |
16 | 16 | */ |
17 | -trait FormTrait{ |
|
17 | +trait FormTrait { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @return HtmlForm |
21 | 21 | */ |
22 | 22 | abstract protected function getForm(); |
23 | 23 | |
24 | - protected function addCompoValidation(Form $compo,HtmlFormField $field){ |
|
24 | + protected function addCompoValidation(Form $compo, HtmlFormField $field) { |
|
25 | 25 | $validation=$field->getValidation(); |
26 | - if(isset($validation)){ |
|
26 | + if (isset($validation)) { |
|
27 | 27 | $validation->setIdentifier($field->getDataField()->getIdentifier()); |
28 | 28 | $compo->addFieldValidation($validation); |
29 | 29 | } |
30 | 30 | return $compo; |
31 | 31 | } |
32 | 32 | |
33 | - protected function _runValidationParams(Form &$compo,JsUtils $js=NULL){ |
|
33 | + protected function _runValidationParams(Form &$compo, JsUtils $js=NULL) { |
|
34 | 34 | $form=$this->getForm(); |
35 | 35 | $params=$form->getValidationParams(); |
36 | - if(isset($params["_ajaxSubmit"])){ |
|
37 | - $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"],$js); |
|
36 | + if (isset($params["_ajaxSubmit"])) { |
|
37 | + $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"], $js); |
|
38 | 38 | $this->onSuccess($compilation); |
39 | 39 | $form->removeValidationParam("_ajaxSubmit"); |
40 | 40 | } |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | $form->addEventsOnRun($js); |
44 | 44 | } |
45 | 45 | |
46 | - protected function _compileAjaxSubmit($ajaxSubmit,JsUtils $js=null){ |
|
46 | + protected function _compileAjaxSubmit($ajaxSubmit, JsUtils $js=null) { |
|
47 | 47 | $compilation=""; |
48 | - if(\is_array($ajaxSubmit)){ |
|
49 | - foreach ($ajaxSubmit as $ajaxSubmitItem){ |
|
48 | + if (\is_array($ajaxSubmit)) { |
|
49 | + foreach ($ajaxSubmit as $ajaxSubmitItem) { |
|
50 | 50 | $compilation.=$ajaxSubmitItem->compile($js); |
51 | 51 | } |
52 | - }elseif($ajaxSubmit instanceof AjaxCall){ |
|
52 | + }elseif ($ajaxSubmit instanceof AjaxCall) { |
|
53 | 53 | $compilation=$ajaxSubmit->compile($js); |
54 | 54 | } |
55 | - $compilation=str_ireplace("\"","%quote%", $compilation); |
|
55 | + $compilation=str_ireplace("\"", "%quote%", $compilation); |
|
56 | 56 | return $compilation; |
57 | 57 | } |
58 | 58 | |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - public function setAttached($value=true){ |
|
68 | + public function setAttached($value=true) { |
|
69 | 69 | $form=$this->getForm(); |
70 | - if($value) |
|
71 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
70 | + if ($value) |
|
71 | + $form->addToPropertyCtrl("class", "attached", array("attached")); |
|
72 | 72 | return $form; |
73 | 73 | } |
74 | 74 | |
75 | - public function addErrorMessage(){ |
|
75 | + public function addErrorMessage() { |
|
76 | 76 | return $this->getForm()->addContent((new HtmlMessage(""))->setError()); |
77 | 77 | } |
78 | 78 | |
@@ -88,48 +88,48 @@ discard block |
||
88 | 88 | * @param array $parameters |
89 | 89 | * @return HtmlForm |
90 | 90 | */ |
91 | - public function submitOn($event,$identifierOrElement,$url,$responseElement,$parameters=NULL){ |
|
91 | + public function submitOn($event, $identifierOrElement, $url, $responseElement, $parameters=NULL) { |
|
92 | 92 | $form=$this->getForm(); |
93 | - if($identifierOrElement instanceof BaseHtml) |
|
93 | + if ($identifierOrElement instanceof BaseHtml) |
|
94 | 94 | $elem=$identifierOrElement; |
95 | 95 | else |
96 | 96 | $elem=$form->getElementById($identifierOrElement, $form->getContent()); |
97 | - if(isset($elem)){ |
|
98 | - $this->_buttonAsSubmit($elem, $event,$url,$responseElement,$parameters); |
|
97 | + if (isset($elem)) { |
|
98 | + $this->_buttonAsSubmit($elem, $event, $url, $responseElement, $parameters); |
|
99 | 99 | } |
100 | 100 | return $form; |
101 | 101 | } |
102 | 102 | |
103 | - public function submitOnClick($identifier,$url,$responseElement,$parameters=NULL){ |
|
104 | - return $this->submitOn("click", $identifier, $url, $responseElement,$parameters); |
|
103 | + public function submitOnClick($identifier, $url, $responseElement, $parameters=NULL) { |
|
104 | + return $this->submitOn("click", $identifier, $url, $responseElement, $parameters); |
|
105 | 105 | } |
106 | 106 | |
107 | - public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
108 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
109 | - return $this->_buttonAsSubmit($bt, "click",$url,$responseElement,$parameters); |
|
107 | + public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
108 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
109 | + return $this->_buttonAsSubmit($bt, "click", $url, $responseElement, $parameters); |
|
110 | 110 | } |
111 | 111 | |
112 | - protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL){ |
|
112 | + protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement=NULL, $parameters=NULL) { |
|
113 | 113 | $form=$this->getForm(); |
114 | - if(isset($url) && isset($responseElement)){ |
|
115 | - $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');",true,true); |
|
116 | - $this->setSubmitParams($url,$responseElement,$parameters); |
|
114 | + if (isset($url) && isset($responseElement)) { |
|
115 | + $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');", true, true); |
|
116 | + $this->setSubmitParams($url, $responseElement, $parameters); |
|
117 | 117 | } |
118 | 118 | return $button; |
119 | 119 | } |
120 | 120 | |
121 | - public function setSubmitParams($url,$responseElement=NULL,$parameters=NULL){ |
|
121 | + public function setSubmitParams($url, $responseElement=NULL, $parameters=NULL) { |
|
122 | 122 | $form=$this->getForm(); |
123 | - $params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true]; |
|
124 | - if(\is_array($parameters)){ |
|
125 | - $params=\array_merge($params,$parameters); |
|
123 | + $params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url, "stopPropagation"=>true]; |
|
124 | + if (\is_array($parameters)) { |
|
125 | + $params=\array_merge($params, $parameters); |
|
126 | 126 | } |
127 | 127 | $form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params)); |
128 | 128 | return $this; |
129 | 129 | } |
130 | 130 | |
131 | - public function addReset($identifier,$value,$cssStyle=NULL){ |
|
132 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
131 | + public function addReset($identifier, $value, $cssStyle=NULL) { |
|
132 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
133 | 133 | $bt->setProperty("type", "reset"); |
134 | 134 | return $bt; |
135 | 135 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param string $jsCode |
140 | 140 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
141 | 141 | */ |
142 | - public function onValid($jsCode){ |
|
142 | + public function onValid($jsCode) { |
|
143 | 143 | $form=$this->getForm(); |
144 | 144 | $form->addValidationParam("onValid", "%function(){".$jsCode."}%"); |
145 | 145 | return $form; |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | * @param string $jsCode can use event and fields parameters |
151 | 151 | * @return HtmlForm |
152 | 152 | */ |
153 | - public function onSuccess($jsCode){ |
|
153 | + public function onSuccess($jsCode) { |
|
154 | 154 | $form=$this->getForm(); |
155 | - $form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%"); |
|
155 | + $form->addValidationParam("onSuccess", $jsCode, "%function(event,fields){", "}%"); |
|
156 | 156 | return $form; |
157 | 157 | } |
158 | 158 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | foreach ($ajaxSubmit as $ajaxSubmitItem){ |
50 | 50 | $compilation.=$ajaxSubmitItem->compile($js); |
51 | 51 | } |
52 | - }elseif($ajaxSubmit instanceof AjaxCall){ |
|
52 | + } elseif($ajaxSubmit instanceof AjaxCall){ |
|
53 | 53 | $compilation=$ajaxSubmit->compile($js); |
54 | 54 | } |
55 | 55 | $compilation=str_ireplace("\"","%quote%", $compilation); |
@@ -67,8 +67,9 @@ discard block |
||
67 | 67 | |
68 | 68 | public function setAttached($value=true){ |
69 | 69 | $form=$this->getForm(); |
70 | - if($value) |
|
71 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
70 | + if($value) { |
|
71 | + $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
72 | + } |
|
72 | 73 | return $form; |
73 | 74 | } |
74 | 75 | |
@@ -90,10 +91,11 @@ discard block |
||
90 | 91 | */ |
91 | 92 | public function submitOn($event,$identifierOrElement,$url,$responseElement,$parameters=NULL){ |
92 | 93 | $form=$this->getForm(); |
93 | - if($identifierOrElement instanceof BaseHtml) |
|
94 | - $elem=$identifierOrElement; |
|
95 | - else |
|
96 | - $elem=$form->getElementById($identifierOrElement, $form->getContent()); |
|
94 | + if($identifierOrElement instanceof BaseHtml) { |
|
95 | + $elem=$identifierOrElement; |
|
96 | + } else { |
|
97 | + $elem=$form->getElementById($identifierOrElement, $form->getContent()); |
|
98 | + } |
|
97 | 99 | if(isset($elem)){ |
98 | 100 | $this->_buttonAsSubmit($elem, $event,$url,$responseElement,$parameters); |
99 | 101 | } |
@@ -19,220 +19,220 @@ 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){ |
|
133 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
132 | + public function insertField($index, $field) { |
|
133 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
134 | 134 | return $this; |
135 | 135 | } |
136 | 136 | |
137 | - public function insertInField($index,$field){ |
|
137 | + public function insertInField($index, $field) { |
|
138 | 138 | $vb=$this->visibleProperties; |
139 | - if(isset($vb[$index])){ |
|
140 | - if(\is_array($vb[$index])){ |
|
139 | + if (isset($vb[$index])) { |
|
140 | + if (\is_array($vb[$index])) { |
|
141 | 141 | $this->visibleProperties[$index][]=$field; |
142 | - }else{ |
|
143 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
142 | + } else { |
|
143 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
144 | 144 | } |
145 | - }else{ |
|
145 | + } else { |
|
146 | 146 | return $this->insertField($index, $field); |
147 | 147 | } |
148 | 148 | return $this; |
149 | 149 | } |
150 | 150 | |
151 | - public function addField($field){ |
|
151 | + public function addField($field) { |
|
152 | 152 | $this->visibleProperties[]=$field; |
153 | 153 | return $this; |
154 | 154 | } |
155 | 155 | |
156 | - public function addFields($fields){ |
|
157 | - $this->visibleProperties=\array_merge($this->visibleProperties,$fields); |
|
156 | + public function addFields($fields) { |
|
157 | + $this->visibleProperties=\array_merge($this->visibleProperties, $fields); |
|
158 | 158 | return $this; |
159 | 159 | } |
160 | 160 | |
161 | - public function count(){ |
|
161 | + public function count() { |
|
162 | 162 | return \sizeof($this->properties); |
163 | 163 | } |
164 | 164 | |
165 | - public function visiblePropertiesCount(){ |
|
165 | + public function visiblePropertiesCount() { |
|
166 | 166 | return \sizeof($this->visibleProperties); |
167 | 167 | } |
168 | 168 | |
169 | - public function getProperty($index){ |
|
169 | + public function getProperty($index) { |
|
170 | 170 | return $this->properties[$index]; |
171 | 171 | } |
172 | 172 | |
173 | - public function getFieldName($index){ |
|
173 | + public function getFieldName($index) { |
|
174 | 174 | $property=$this->getProperty($index); |
175 | - if($property instanceof \ReflectionProperty){ |
|
175 | + if ($property instanceof \ReflectionProperty) { |
|
176 | 176 | $result=$property->getName(); |
177 | - }elseif(\is_callable($property)){ |
|
177 | + }elseif (\is_callable($property)) { |
|
178 | 178 | $result=$this->visibleProperties[$index]; |
179 | - }else{ |
|
179 | + } else { |
|
180 | 180 | $result=$property; |
181 | 181 | } |
182 | 182 | return $result; |
183 | 183 | } |
184 | 184 | |
185 | 185 | |
186 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
187 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
186 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
187 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | public function setInstance($instance) { |
191 | - if(\is_string($instance)){ |
|
191 | + if (\is_string($instance)) { |
|
192 | 192 | $instance=new $instance(); |
193 | 193 | } |
194 | 194 | $this->instance=$instance; |
195 | 195 | $this->properties=[]; |
196 | 196 | $this->reflect=new \ReflectionClass($instance); |
197 | - if(JArray::count($this->visibleProperties)===0){ |
|
197 | + if (JArray::count($this->visibleProperties)===0) { |
|
198 | 198 | $this->properties=$this->getDefaultProperties(); |
199 | - }else{ |
|
200 | - foreach ($this->visibleProperties as $property){ |
|
199 | + } else { |
|
200 | + foreach ($this->visibleProperties as $property) { |
|
201 | 201 | $this->setInstanceProperty($property); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | return $this; |
205 | 205 | } |
206 | 206 | |
207 | - private function setInstanceProperty($property){ |
|
208 | - if(\is_callable($property)){ |
|
207 | + private function setInstanceProperty($property) { |
|
208 | + if (\is_callable($property)) { |
|
209 | 209 | $this->properties[]=$property; |
210 | - }elseif(\is_string($property)){ |
|
211 | - try{ |
|
210 | + }elseif (\is_string($property)) { |
|
211 | + try { |
|
212 | 212 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
213 | 213 | $rProperty=$this->reflect->getProperty($property); |
214 | 214 | $this->properties[]=$rProperty; |
215 | - }catch(\Exception $e){ |
|
215 | + }catch (\Exception $e) { |
|
216 | 216 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
217 | 217 | $this->properties[]=$property; |
218 | 218 | } |
219 | - }elseif(\is_int($property)){ |
|
219 | + }elseif (\is_int($property)) { |
|
220 | 220 | $props=$this->getDefaultProperties(); |
221 | - if(isset($props[$property])) |
|
221 | + if (isset($props[$property])) |
|
222 | 222 | $this->properties[]=$props[$property]; |
223 | 223 | else |
224 | 224 | $this->properties[]=$property; |
225 | - }else{ |
|
225 | + } else { |
|
226 | 226 | $this->properties[]=$property; |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | - protected function getDefaultProperties(){ |
|
230 | + protected function getDefaultProperties() { |
|
231 | 231 | $result=[]; |
232 | 232 | $properties=$this->reflect->getProperties(); |
233 | - foreach ($properties as $property){ |
|
233 | + foreach ($properties as $property) { |
|
234 | 234 | $showable=$this->showableProperty($property); |
235 | - if($showable!==false){ |
|
235 | + if ($showable!==false) { |
|
236 | 236 | $result[]=$property; |
237 | 237 | } |
238 | 238 | } |
@@ -244,12 +244,12 @@ discard block |
||
244 | 244 | return $this; |
245 | 245 | } |
246 | 246 | |
247 | - public function setValueFunction($index,$callback){ |
|
247 | + public function setValueFunction($index, $callback) { |
|
248 | 248 | $this->values[$index]=$callback; |
249 | 249 | return $this; |
250 | 250 | } |
251 | 251 | |
252 | - public function setIdentifierFunction($callback){ |
|
252 | + public function setIdentifierFunction($callback) { |
|
253 | 253 | $this->values["identifier"]=$callback; |
254 | 254 | return $this; |
255 | 255 | } |
@@ -262,42 +262,42 @@ discard block |
||
262 | 262 | return $this->properties; |
263 | 263 | } |
264 | 264 | |
265 | - public function getCaption($index){ |
|
266 | - if(isset($this->captions[$index])){ |
|
265 | + public function getCaption($index) { |
|
266 | + if (isset($this->captions[$index])) { |
|
267 | 267 | return $this->captions[$index]; |
268 | 268 | } |
269 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
269 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
270 | 270 | return $this->properties[$index]->getName(); |
271 | - elseif(\is_callable($this->properties[$index])) |
|
271 | + elseif (\is_callable($this->properties[$index])) |
|
272 | 272 | return ""; |
273 | 273 | else |
274 | 274 | return $this->properties[$index]; |
275 | 275 | } |
276 | 276 | |
277 | - public function getCaptions(){ |
|
277 | + public function getCaptions() { |
|
278 | 278 | $count=$this->count(); |
279 | - if(isset($this->captions)){ |
|
280 | - $captions= \array_values($this->captions); |
|
279 | + if (isset($this->captions)) { |
|
280 | + $captions=\array_values($this->captions); |
|
281 | 281 | $captionsSize=\sizeof($captions); |
282 | - for($i=$captionsSize;$i<$count;$i++){ |
|
282 | + for ($i=$captionsSize; $i<$count; $i++) { |
|
283 | 283 | $captions[]=""; |
284 | 284 | } |
285 | - }else{ |
|
285 | + } else { |
|
286 | 286 | $captions=[]; |
287 | 287 | $index=0; |
288 | - while($index<$count){ |
|
288 | + while ($index<$count) { |
|
289 | 289 | $captions[]=$this->getCaption($index++); |
290 | 290 | } |
291 | 291 | } |
292 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
292 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
293 | 293 | $callback=$this->captionCallback; |
294 | - $callback($captions,$this->instance); |
|
294 | + $callback($captions, $this->instance); |
|
295 | 295 | } |
296 | 296 | return $captions; |
297 | 297 | } |
298 | 298 | |
299 | - public function setCaption($index,$caption){ |
|
300 | - if(isset($this->captions)===false) |
|
299 | + public function setCaption($index, $caption) { |
|
300 | + if (isset($this->captions)===false) |
|
301 | 301 | $this->captions=[]; |
302 | 302 | $this->captions[$index]=$caption; |
303 | 303 | return $this; |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param callable $callback function called after the field compilation |
316 | 316 | * @return InstanceViewer |
317 | 317 | */ |
318 | - public function afterCompile($index,$callback){ |
|
318 | + public function afterCompile($index, $callback) { |
|
319 | 319 | $this->afterCompile[$index]=$callback; |
320 | 320 | return $this; |
321 | 321 | } |
@@ -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])){ |
@@ -139,10 +142,10 @@ discard block |
||
139 | 142 | if(isset($vb[$index])){ |
140 | 143 | if(\is_array($vb[$index])){ |
141 | 144 | $this->visibleProperties[$index][]=$field; |
142 | - }else{ |
|
145 | + } else{ |
|
143 | 146 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
144 | 147 | } |
145 | - }else{ |
|
148 | + } else{ |
|
146 | 149 | return $this->insertField($index, $field); |
147 | 150 | } |
148 | 151 | return $this; |
@@ -174,9 +177,9 @@ discard block |
||
174 | 177 | $property=$this->getProperty($index); |
175 | 178 | if($property instanceof \ReflectionProperty){ |
176 | 179 | $result=$property->getName(); |
177 | - }elseif(\is_callable($property)){ |
|
180 | + } elseif(\is_callable($property)){ |
|
178 | 181 | $result=$this->visibleProperties[$index]; |
179 | - }else{ |
|
182 | + } else{ |
|
180 | 183 | $result=$property; |
181 | 184 | } |
182 | 185 | return $result; |
@@ -196,7 +199,7 @@ discard block |
||
196 | 199 | $this->reflect=new \ReflectionClass($instance); |
197 | 200 | if(JArray::count($this->visibleProperties)===0){ |
198 | 201 | $this->properties=$this->getDefaultProperties(); |
199 | - }else{ |
|
202 | + } else{ |
|
200 | 203 | foreach ($this->visibleProperties as $property){ |
201 | 204 | $this->setInstanceProperty($property); |
202 | 205 | } |
@@ -207,22 +210,23 @@ discard block |
||
207 | 210 | private function setInstanceProperty($property){ |
208 | 211 | if(\is_callable($property)){ |
209 | 212 | $this->properties[]=$property; |
210 | - }elseif(\is_string($property)){ |
|
213 | + } elseif(\is_string($property)){ |
|
211 | 214 | try{ |
212 | 215 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
213 | 216 | $rProperty=$this->reflect->getProperty($property); |
214 | 217 | $this->properties[]=$rProperty; |
215 | - }catch(\Exception $e){ |
|
218 | + } catch(\Exception $e){ |
|
216 | 219 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
217 | 220 | $this->properties[]=$property; |
218 | 221 | } |
219 | - }elseif(\is_int($property)){ |
|
222 | + } elseif(\is_int($property)){ |
|
220 | 223 | $props=$this->getDefaultProperties(); |
221 | - if(isset($props[$property])) |
|
222 | - $this->properties[]=$props[$property]; |
|
223 | - else |
|
224 | - $this->properties[]=$property; |
|
225 | - }else{ |
|
224 | + if(isset($props[$property])) { |
|
225 | + $this->properties[]=$props[$property]; |
|
226 | + } else { |
|
227 | + $this->properties[]=$property; |
|
228 | + } |
|
229 | + } else{ |
|
226 | 230 | $this->properties[]=$property; |
227 | 231 | } |
228 | 232 | } |
@@ -266,12 +270,13 @@ discard block |
||
266 | 270 | if(isset($this->captions[$index])){ |
267 | 271 | return $this->captions[$index]; |
268 | 272 | } |
269 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
270 | - return $this->properties[$index]->getName(); |
|
271 | - elseif(\is_callable($this->properties[$index])) |
|
272 | - return ""; |
|
273 | - else |
|
274 | - return $this->properties[$index]; |
|
273 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
274 | + return $this->properties[$index]->getName(); |
|
275 | + } elseif(\is_callable($this->properties[$index])) { |
|
276 | + return ""; |
|
277 | + } else { |
|
278 | + return $this->properties[$index]; |
|
279 | + } |
|
275 | 280 | } |
276 | 281 | |
277 | 282 | public function getCaptions(){ |
@@ -282,7 +287,7 @@ discard block |
||
282 | 287 | for($i=$captionsSize;$i<$count;$i++){ |
283 | 288 | $captions[]=""; |
284 | 289 | } |
285 | - }else{ |
|
290 | + } else{ |
|
286 | 291 | $captions=[]; |
287 | 292 | $index=0; |
288 | 293 | while($index<$count){ |
@@ -297,8 +302,9 @@ discard block |
||
297 | 302 | } |
298 | 303 | |
299 | 304 | public function setCaption($index,$caption){ |
300 | - if(isset($this->captions)===false) |
|
301 | - $this->captions=[]; |
|
305 | + if(isset($this->captions)===false) { |
|
306 | + $this->captions=[]; |
|
307 | + } |
|
302 | 308 | $this->captions[$index]=$caption; |
303 | 309 | return $this; |
304 | 310 | } |
@@ -21,56 +21,56 @@ discard block |
||
21 | 21 | protected $_colWidths; |
22 | 22 | |
23 | 23 | public function __construct($identifier, $modelInstance=NULL) { |
24 | - parent::__construct($identifier, null,$modelInstance); |
|
25 | - $this->_init(new DeInstanceViewer($identifier), "table", new HtmlTable($identifier, 0,2), false); |
|
24 | + parent::__construct($identifier, null, $modelInstance); |
|
25 | + $this->_init(new DeInstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 2), false); |
|
26 | 26 | $this->content["table"]->setDefinition(); |
27 | 27 | } |
28 | 28 | |
29 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
30 | - if(!$this->_generated){ |
|
29 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
30 | + if (!$this->_generated) { |
|
31 | 31 | $this->_instanceViewer->setInstance($this->_modelInstance); |
32 | 32 | |
33 | 33 | $table=$this->content["table"]; |
34 | 34 | $this->_generateContent($table); |
35 | 35 | |
36 | - if(isset($this->_toolbar)){ |
|
36 | + if (isset($this->_toolbar)) { |
|
37 | 37 | $this->_setToolbarPosition($table); |
38 | 38 | } |
39 | - if(isset($this->_colWidths)){ |
|
39 | + if (isset($this->_colWidths)) { |
|
40 | 40 | $this->_applyStyleAttributes($table); |
41 | 41 | } |
42 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
42 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
43 | 43 | $this->_compileForm(); |
44 | 44 | $this->_generated=true; |
45 | 45 | } |
46 | - return parent::compile($js,$view); |
|
46 | + return parent::compile($js, $view); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @param HtmlTable $table |
51 | 51 | */ |
52 | - protected function _generateContent($table){ |
|
53 | - $values= $this->_instanceViewer->getValues(); |
|
52 | + protected function _generateContent($table) { |
|
53 | + $values=$this->_instanceViewer->getValues(); |
|
54 | 54 | $captions=$this->_instanceViewer->getCaptions(); |
55 | 55 | $count=$this->_instanceViewer->count(); |
56 | 56 | |
57 | - for($i=0;$i<$count;$i++){ |
|
58 | - $table->addRow([$captions[$i],$values[$i]]); |
|
57 | + for ($i=0; $i<$count; $i++) { |
|
58 | + $table->addRow([$captions[$i], $values[$i]]); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - protected function _applyStyleAttributes(HtmlTable $table){ |
|
62 | + protected function _applyStyleAttributes(HtmlTable $table) { |
|
63 | 63 | $table->setColWidths($this->_colWidths); |
64 | 64 | } |
65 | - protected function _getFieldName($index){ |
|
65 | + protected function _getFieldName($index) { |
|
66 | 66 | return $this->_instanceViewer->getFieldName($index); |
67 | 67 | } |
68 | 68 | |
69 | - protected function _getFieldCaption($index){ |
|
69 | + protected function _getFieldCaption($index) { |
|
70 | 70 | return null; |
71 | 71 | } |
72 | 72 | |
73 | - protected function _getFieldIdentifier($prefix,$name=""){ |
|
73 | + protected function _getFieldIdentifier($prefix, $name="") { |
|
74 | 74 | return $this->identifier."-{$prefix}-".$name; |
75 | 75 | } |
76 | 76 | |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | return $this; |
103 | 103 | } |
104 | 104 | |
105 | - public function asForm(){ |
|
105 | + public function asForm() { |
|
106 | 106 | return $this->getForm(); |
107 | 107 | } |
108 | 108 | |
109 | - public function setColCaptionWidth($width){ |
|
109 | + public function setColCaptionWidth($width) { |
|
110 | 110 | $this->_colWidths[0]=$width; |
111 | 111 | return $this; |
112 | 112 | } |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | return $this; |
117 | 117 | } |
118 | 118 | |
119 | - public function setColWidths($widths){ |
|
119 | + public function setColWidths($widths) { |
|
120 | 120 | $this->_colWidths=$widths; |
121 | 121 | return $this; |
122 | 122 | } |
123 | 123 | |
124 | - public function run(JsUtils $js){ |
|
124 | + public function run(JsUtils $js) { |
|
125 | 125 | $js->execOn("click", ".ui.toggle", 'var active=$(this).hasClass("active");$(this).children("i").toggleClass("up",active).toggleClass("down",!active);$(this).closest("td").next("td").children().toggle(active);'); |
126 | 126 | parent::run($js); |
127 | 127 | } |