@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
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; |
@@ -34,78 +34,78 @@ discard block |
||
34 | 34 | $retour=$this->_getAjaxUrl($url, $attr); |
35 | 35 | $responseElement=$this->_getResponseElement($responseElement); |
36 | 36 | $retour.="var self=this;\n"; |
37 | - if($hasLoader===true){ |
|
37 | + if ($hasLoader===true) { |
|
38 | 38 | $this->addLoading($retour, $responseElement); |
39 | 39 | } |
40 | 40 | |
41 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
42 | - if(isset($params)){ |
|
41 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
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)."});\n"; |
|
51 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\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 _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
100 | - $retour="";$call=null; |
|
99 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
100 | + $retour=""; $call=null; |
|
101 | 101 | if ($responseElement!=="") { |
102 | - if(isset($ajaxTransition)){ |
|
102 | + if (isset($ajaxTransition)) { |
|
103 | 103 | $call=$this->setAjaxDataCall($ajaxTransition); |
104 | - }elseif(isset($this->ajaxTransition)){ |
|
104 | + }elseif (isset($this->ajaxTransition)) { |
|
105 | 105 | $call=$this->ajaxTransition; |
106 | 106 | } |
107 | - if(\is_callable($call)) |
|
108 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
107 | + if (\is_callable($call)) |
|
108 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
109 | 109 | else |
110 | 110 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
111 | 111 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | return $retour; |
114 | 114 | } |
115 | 115 | |
116 | - protected function _getResponseElement($responseElement){ |
|
116 | + protected function _getResponseElement($responseElement) { |
|
117 | 117 | if ($responseElement!=="") { |
118 | 118 | $responseElement=Javascript::prep_value($responseElement); |
119 | 119 | } |
@@ -123,26 +123,26 @@ discard block |
||
123 | 123 | protected function _correctAjaxUrl($url) { |
124 | 124 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
125 | 125 | $url=substr($url, 0, strlen($url)-1); |
126 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
126 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
127 | 127 | $url=$this->getUrl($url); |
128 | 128 | } |
129 | 129 | return $url; |
130 | 130 | } |
131 | 131 | |
132 | - public static function _correctParams($params){ |
|
133 | - if(JString::isNull($params)){ |
|
132 | + public static function _correctParams($params) { |
|
133 | + if (JString::isNull($params)) { |
|
134 | 134 | return ""; |
135 | 135 | } |
136 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
136 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
137 | 137 | return '$.param('.$params.')'; |
138 | 138 | } |
139 | 139 | return $params; |
140 | 140 | } |
141 | 141 | |
142 | - public static function _implodeParams($parameters){ |
|
142 | + public static function _implodeParams($parameters) { |
|
143 | 143 | $allParameters=[]; |
144 | - foreach ($parameters as $params){ |
|
145 | - if(isset($params)) |
|
144 | + foreach ($parameters as $params) { |
|
145 | + if (isset($params)) |
|
146 | 146 | $allParameters[]=self::_correctParams($params); |
147 | 147 | } |
148 | 148 | return \implode("+'&'+", $allParameters); |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
161 | 161 | } |
162 | 162 | |
163 | - protected function setAjaxDataCall($params){ |
|
163 | + protected function setAjaxDataCall($params) { |
|
164 | 164 | $result=null; |
165 | - if(!\is_callable($params)){ |
|
166 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
167 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
165 | + if (!\is_callable($params)) { |
|
166 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
167 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
168 | 168 | }; |
169 | 169 | } |
170 | 170 | return $result; |
171 | 171 | } |
172 | 172 | |
173 | - protected function setDefaultParameters(&$parameters,$default){ |
|
174 | - foreach ($default as $k=>$v){ |
|
175 | - if(!isset($parameters[$k])) |
|
173 | + protected function setDefaultParameters(&$parameters, $default) { |
|
174 | + foreach ($default as $k=>$v) { |
|
175 | + if (!isset($parameters[$k])) |
|
176 | 176 | $parameters[$k]=$v; |
177 | 177 | } |
178 | 178 | } |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @param string $url The url of the request |
187 | 187 | * @param string $responseElement selector of the HTML element displaying the answer |
188 | 188 | */ |
189 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
190 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
189 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
190 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | * @param string $responseElement selector of the HTML element displaying the answer |
197 | 197 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
198 | 198 | */ |
199 | - public function get($url, $responseElement="",$parameters=[]) { |
|
199 | + public function get($url, $responseElement="", $parameters=[]) { |
|
200 | 200 | $parameters["immediatly"]=true; |
201 | - return $this->_get($url,$responseElement,$parameters); |
|
201 | + return $this->_get($url, $responseElement, $parameters); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | * @param string $responseElement selector of the HTML element displaying the answer |
209 | 209 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
210 | 210 | */ |
211 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
211 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
212 | 212 | $parameters["immediatly"]=true; |
213 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
213 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | * @param string $responseElement selector of the HTML element displaying the answer |
221 | 221 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
222 | 222 | */ |
223 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
223 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
224 | 224 | $parameters["immediatly"]=false; |
225 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
225 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @param string $context |
236 | 236 | * @param boolean $immediatly |
237 | 237 | */ |
238 | - private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
238 | + private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
239 | 239 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
240 | 240 | $retour=$this->_getAjaxUrl($url, $attr); |
241 | 241 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | * @param string $context |
259 | 259 | * @param boolean $immediatly |
260 | 260 | */ |
261 | - public function json($url, $method="get", $params="{}", $jsCallback=NULL,$context="document",$immediatly=false) { |
|
262 | - return $this->_json($url,$method,$params,$jsCallback,NULL,$context,$immediatly); |
|
261 | + public function json($url, $method="get", $params="{}", $jsCallback=NULL, $context="document", $immediatly=false) { |
|
262 | + return $this->_json($url, $method, $params, $jsCallback, NULL, $context, $immediatly); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @param string $url the request address |
270 | 270 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
271 | 271 | */ |
272 | - public function jsonOn($event,$element, $url,$parameters=array()) { |
|
272 | + public function jsonOn($event, $element, $url, $parameters=array()) { |
|
273 | 273 | $preventDefault=true; |
274 | 274 | $stopPropagation=true; |
275 | 275 | $jsCallback=null; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $params="{}"; |
280 | 280 | $immediatly=true; |
281 | 281 | extract($parameters); |
282 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
282 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * @param string $jsCallback javascript code to execute after the request |
291 | 291 | * @param string $context jquery DOM element, array container. |
292 | 292 | */ |
293 | - public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL,$context=NULL) { |
|
294 | - return $this->json($url, $method, $params, $jsCallback, $context,false); |
|
293 | + public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL, $context=NULL) { |
|
294 | + return $this->json($url, $method, $params, $jsCallback, $context, false); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -304,22 +304,22 @@ discard block |
||
304 | 304 | * @param string $rowClass the css class for the new element |
305 | 305 | * @param boolean $immediatly |
306 | 306 | */ |
307 | - private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$attr="id",$immediatly=false) { |
|
307 | + private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $attr="id", $immediatly=false) { |
|
308 | 308 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
309 | 309 | $retour=$this->_getAjaxUrl($url, $attr); |
310 | - if($context===null){ |
|
310 | + if ($context===null) { |
|
311 | 311 | $parent="$('".$maskSelector."').parent()"; |
312 | - $newElm = "$('#'+newId)"; |
|
313 | - }else{ |
|
312 | + $newElm="$('#'+newId)"; |
|
313 | + } else { |
|
314 | 314 | $parent=$context; |
315 | - $newElm = $context.".find('#'+newId)"; |
|
315 | + $newElm=$context.".find('#'+newId)"; |
|
316 | 316 | } |
317 | 317 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
318 | 318 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
319 | 319 | $retour.=$parent.".find('._json').remove();"; |
320 | 320 | $retour.="\tdata=$.parseJSON(data);$.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(); |
321 | 321 | 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"; |
322 | - $retour.= $appendTo; |
|
322 | + $retour.=$appendTo; |
|
323 | 323 | $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"; |
324 | 324 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
325 | 325 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | * @param string $context jquery DOM element, array container. |
339 | 339 | * @param boolean $immediatly |
340 | 340 | */ |
341 | - public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$immediatly=false) { |
|
342 | - return $this->_jsonArray($maskSelector, $url,$method,$params,$jsCallback,$rowClass,$context,NULL,$immediatly); |
|
341 | + public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $immediatly=false) { |
|
342 | + return $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, NULL, $immediatly); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -352,8 +352,8 @@ discard block |
||
352 | 352 | * @param string $rowClass the css class for the new element |
353 | 353 | * @param string $context jquery DOM element, array container. |
354 | 354 | */ |
355 | - public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL) { |
|
356 | - return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback,$rowClass,$context,false); |
|
355 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL) { |
|
356 | + return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, false); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -363,18 +363,18 @@ discard block |
||
363 | 363 | * @param string $url the request url |
364 | 364 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
365 | 365 | */ |
366 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$parameters=array()) { |
|
366 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
367 | 367 | $preventDefault=true; |
368 | 368 | $stopPropagation=true; |
369 | 369 | $jsCallback=null; |
370 | 370 | $attr="id"; |
371 | 371 | $method="get"; |
372 | - $context = null; |
|
372 | + $context=null; |
|
373 | 373 | $params="{}"; |
374 | 374 | $immediatly=true; |
375 | 375 | $rowClass="_json"; |
376 | 376 | extract($parameters); |
377 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $rowClass, $context,$attr), $event, $preventDefault, $stopPropagation,$immediatly); |
|
377 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, $attr), $event, $preventDefault, $stopPropagation, $immediatly); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | /** |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | */ |
387 | 387 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
388 | 388 | $parameters["immediatly"]=false; |
389 | - return $this->_get($url, $responseElement,$parameters); |
|
389 | + return $this->_get($url, $responseElement, $parameters); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null) |
400 | 400 | */ |
401 | 401 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
402 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
403 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
402 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
403 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -413,8 +413,8 @@ discard block |
||
413 | 413 | * @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null) |
414 | 414 | */ |
415 | 415 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
416 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
417 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
416 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
417 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
442 | 442 | } |
443 | 443 | |
444 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
444 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
445 | 445 | $parameters["params"]=$params; |
446 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
446 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,8 +453,8 @@ discard block |
||
453 | 453 | * @param string $params JSON parameters |
454 | 454 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
455 | 455 | */ |
456 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
457 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
456 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
457 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | * @param string $responseElement selector of the HTML element displaying the answer |
466 | 466 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
467 | 467 | */ |
468 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
468 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
469 | 469 | $parameters["immediatly"]=false; |
470 | 470 | return $this->_post($url, $params, $responseElement, $parameters); |
471 | 471 | } |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
482 | 482 | */ |
483 | 483 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
484 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
485 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
484 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
485 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
@@ -499,26 +499,26 @@ discard block |
||
499 | 499 | } |
500 | 500 | |
501 | 501 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
502 | - $params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL; |
|
502 | + $params="{}"; $validation=false; $jsCallback=NULL; $attr="id"; $hasLoader=true; $jqueryDone="html"; $ajaxTransition=null; $immediatly=false; $jsCondition=NULL; $headers=NULL; |
|
503 | 503 | \extract($parameters); |
504 | 504 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
505 | 505 | $retour=$this->_getAjaxUrl($url, $attr); |
506 | 506 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
507 | - if(isset($params)){ |
|
507 | + if (isset($params)) { |
|
508 | 508 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
509 | 509 | } |
510 | 510 | $responseElement=$this->_getResponseElement($responseElement); |
511 | 511 | $retour.="var self=this;\n"; |
512 | - if($hasLoader===true){ |
|
512 | + if ($hasLoader===true) { |
|
513 | 513 | $this->addLoading($retour, $responseElement); |
514 | 514 | } |
515 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params"]; |
|
516 | - if(isset($headers)){ |
|
515 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params"]; |
|
516 | + if (isset($headers)) { |
|
517 | 517 | $ajaxParameters["headers"]=$headers; |
518 | 518 | } |
519 | 519 | $this->createAjaxParameters($ajaxParameters, $parameters); |
520 | 520 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
521 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
521 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
522 | 522 | |
523 | 523 | if ($validation) { |
524 | 524 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null) |
569 | 569 | */ |
570 | 570 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
571 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
572 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
571 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
572 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |