@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
19 | 19 | |
20 | 20 | abstract public function getUrl($url); |
21 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
22 | - abstract public function interval($jsCode,$time,$globalName=null,$immediatly=true); |
|
21 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
22 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
23 | 23 | |
24 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
25 | - if(isset($this->params["ajax"])){ |
|
24 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
25 | + if (isset($this->params["ajax"])) { |
|
26 | 26 | extract($this->params["ajax"]); |
27 | 27 | } |
28 | 28 | extract($parameters); |
@@ -32,121 +32,121 @@ discard block |
||
32 | 32 | $originalSelector=$responseElement; |
33 | 33 | $responseElement=$this->_getResponseElement($responseElement); |
34 | 34 | $retour.="var self=this;\n"; |
35 | - $before=isset($before)?$before:""; |
|
35 | + $before=isset($before) ? $before : ""; |
|
36 | 36 | $retour.=$before; |
37 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
38 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
39 | - }elseif($hasLoader==="internal"){ |
|
37 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
38 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
39 | + }elseif ($hasLoader==="internal") { |
|
40 | 40 | $retour.="\n$(this).addClass('loading');"; |
41 | 41 | } |
42 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
42 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
43 | 43 | |
44 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
44 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
45 | 45 | |
46 | - if(isset($params)){ |
|
47 | - $ajaxParameters["data"]=self::_correctParams($params,$parameters); |
|
46 | + if (isset($params)) { |
|
47 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
48 | 48 | } |
49 | - if(isset($headers)){ |
|
49 | + if (isset($headers)) { |
|
50 | 50 | $ajaxParameters["headers"]=$headers; |
51 | 51 | } |
52 | 52 | $this->createAjaxParameters($ajaxParameters, $parameters); |
53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
54 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
55 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
54 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
55 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
56 | 56 | if ($immediatly) |
57 | 57 | $this->jquery_code_for_compile[]=$retour; |
58 | 58 | return $retour; |
59 | 59 | } |
60 | 60 | |
61 | - protected function createAjaxParameters(&$original,$parameters){ |
|
62 | - $validParameters=["contentType"=>"%value%","dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
63 | - foreach ($validParameters as $param=>$mask){ |
|
64 | - if(isset($parameters[$param])){ |
|
61 | + protected function createAjaxParameters(&$original, $parameters) { |
|
62 | + $validParameters=["contentType"=>"%value%", "dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
63 | + foreach ($validParameters as $param=>$mask) { |
|
64 | + if (isset($parameters[$param])) { |
|
65 | 65 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
71 | - $s = ''; |
|
70 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
71 | + $s=''; |
|
72 | 72 | foreach ($ajaxParameters as $k=>$v) { |
73 | - if ($s !== '') { |
|
74 | - $s .= ','; |
|
73 | + if ($s!=='') { |
|
74 | + $s.=','; |
|
75 | 75 | } |
76 | - if(is_array($v)){ |
|
77 | - $s .= "'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
78 | - }else{ |
|
79 | - $s .= "'{$k}':{$v}"; |
|
76 | + if (is_array($v)) { |
|
77 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
78 | + } else { |
|
79 | + $s.="'{$k}':{$v}"; |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | return $s; |
83 | 83 | } |
84 | 84 | |
85 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
86 | - if(isset($jsCondition)){ |
|
85 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
86 | + if (isset($jsCondition)) { |
|
87 | 87 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
88 | 88 | } |
89 | 89 | return $jsSource; |
90 | 90 | } |
91 | 91 | |
92 | 92 | |
93 | - protected function _getAjaxUrl($url,$attr){ |
|
93 | + protected function _getAjaxUrl($url, $attr) { |
|
94 | 94 | $url=$this->_correctAjaxUrl($url); |
95 | 95 | $retour="url='".$url."';"; |
96 | 96 | $slash="/"; |
97 | - if(JString::endswith($url, "/")===true){ |
|
97 | + if (JString::endswith($url, "/")===true) { |
|
98 | 98 | $slash=""; |
99 | 99 | } |
100 | - if(JString::isNotNull($attr)){ |
|
101 | - if ($attr==="value"){ |
|
100 | + if (JString::isNotNull($attr)) { |
|
101 | + if ($attr==="value") { |
|
102 | 102 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
103 | - }elseif ($attr==="html"){ |
|
103 | + }elseif ($attr==="html") { |
|
104 | 104 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
105 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
105 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
106 | 106 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
107 | - }elseif($attr!==null && $attr!=="") |
|
107 | + }elseif ($attr!==null && $attr!=="") |
|
108 | 108 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
109 | 109 | } |
110 | 110 | return $retour; |
111 | 111 | } |
112 | 112 | |
113 | - protected function onPopstate(){ |
|
113 | + protected function onPopstate() { |
|
114 | 114 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
115 | 115 | } |
116 | 116 | |
117 | - protected function autoActiveLinks($previousURL="window.location.href"){ |
|
118 | - $result= "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
117 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
118 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
119 | 119 | $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
120 | 120 | return $result; |
121 | 121 | } |
122 | 122 | |
123 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
124 | - $retour="";$call=null; |
|
123 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
124 | + $retour=""; $call=null; |
|
125 | 125 | if (JString::isNotNull($responseElement)) { |
126 | - if(isset($ajaxTransition)){ |
|
126 | + if (isset($ajaxTransition)) { |
|
127 | 127 | $call=$this->setAjaxDataCall($ajaxTransition); |
128 | - }elseif(isset($this->ajaxTransition)){ |
|
128 | + }elseif (isset($this->ajaxTransition)) { |
|
129 | 129 | $call=$this->ajaxTransition; |
130 | 130 | } |
131 | - if(\is_callable($call)) |
|
132 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
131 | + if (\is_callable($call)) |
|
132 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
133 | 133 | else |
134 | 134 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
135 | 135 | } |
136 | - if(isset($history)){ |
|
137 | - if($this->params["autoActiveLinks"]){ |
|
136 | + if (isset($history)) { |
|
137 | + if ($this->params["autoActiveLinks"]) { |
|
138 | 138 | $retour.=$this->autoActiveLinks("url"); |
139 | 139 | } |
140 | 140 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
141 | 141 | } |
142 | - if($hasLoader==="internal"){ |
|
142 | + if ($hasLoader==="internal") { |
|
143 | 143 | $retour.="\n$(self).removeClass('loading');"; |
144 | 144 | } |
145 | 145 | $retour.="\t".$jsCallback."\n"; |
146 | 146 | return $retour; |
147 | 147 | } |
148 | 148 | |
149 | - protected function _getResponseElement($responseElement){ |
|
149 | + protected function _getResponseElement($responseElement) { |
|
150 | 150 | if (JString::isNotNull($responseElement)) { |
151 | 151 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
152 | 152 | } |
@@ -156,37 +156,37 @@ discard block |
||
156 | 156 | protected function _correctAjaxUrl($url) { |
157 | 157 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
158 | 158 | $url=substr($url, 0, strlen($url)-1); |
159 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
159 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
160 | 160 | $url=$this->getUrl($url); |
161 | 161 | } |
162 | 162 | return $url; |
163 | 163 | } |
164 | 164 | |
165 | - public static function _correctParams($params,$ajaxParameters=[]){ |
|
166 | - if(JString::isNull($params)){ |
|
165 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
166 | + if (JString::isNull($params)) { |
|
167 | 167 | return ""; |
168 | 168 | } |
169 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
170 | - if( !isset($ajaxParameters['contentType'])|| !UString::contains('json', $ajaxParameters['contentType'])){ |
|
169 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
170 | + if (!isset($ajaxParameters['contentType']) || !UString::contains('json', $ajaxParameters['contentType'])) { |
|
171 | 171 | return '$.param('.$params.')'; |
172 | - }else{ |
|
172 | + } else { |
|
173 | 173 | return 'JSON.stringify('.$params.')'; |
174 | 174 | } |
175 | 175 | } |
176 | 176 | return $params; |
177 | 177 | } |
178 | 178 | |
179 | - public static function _implodeParams($parameters){ |
|
179 | + public static function _implodeParams($parameters) { |
|
180 | 180 | $allParameters=[]; |
181 | - foreach ($parameters as $params){ |
|
182 | - if(isset($params)) |
|
181 | + foreach ($parameters as $params) { |
|
182 | + if (isset($params)) |
|
183 | 183 | $allParameters[]=self::_correctParams($params); |
184 | 184 | } |
185 | 185 | return \implode("+'&'+", $allParameters); |
186 | 186 | } |
187 | 187 | |
188 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
189 | - if(!isset($ajaxLoader)){ |
|
188 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
189 | + if (!isset($ajaxLoader)) { |
|
190 | 190 | $ajaxLoader=$this->ajaxLoader; |
191 | 191 | } |
192 | 192 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -194,19 +194,19 @@ discard block |
||
194 | 194 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
195 | 195 | } |
196 | 196 | |
197 | - protected function setAjaxDataCall($params){ |
|
197 | + protected function setAjaxDataCall($params) { |
|
198 | 198 | $result=null; |
199 | - if(!\is_callable($params)){ |
|
200 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
201 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
199 | + if (!\is_callable($params)) { |
|
200 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
201 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
202 | 202 | }; |
203 | 203 | } |
204 | 204 | return $result; |
205 | 205 | } |
206 | 206 | |
207 | - protected function setDefaultParameters(&$parameters,$default){ |
|
208 | - foreach ($default as $k=>$v){ |
|
209 | - if(!isset($parameters[$k])) |
|
207 | + protected function setDefaultParameters(&$parameters, $default) { |
|
208 | + foreach ($default as $k=>$v) { |
|
209 | + if (!isset($parameters[$k])) |
|
210 | 210 | $parameters[$k]=$v; |
211 | 211 | } |
212 | 212 | } |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | * @param string $url The url of the request |
221 | 221 | * @param string $responseElement selector of the HTML element displaying the answer |
222 | 222 | */ |
223 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
224 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
223 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
224 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param string $responseElement selector of the HTML element displaying the answer |
231 | 231 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
232 | 232 | */ |
233 | - public function get($url, $responseElement="",$parameters=[]) { |
|
233 | + public function get($url, $responseElement="", $parameters=[]) { |
|
234 | 234 | $parameters["immediatly"]=true; |
235 | - return $this->_get($url,$responseElement,$parameters); |
|
235 | + return $this->_get($url, $responseElement, $parameters); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | * @param string $responseElement selector of the HTML element displaying the answer |
243 | 243 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
244 | 244 | */ |
245 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
245 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
246 | 246 | $parameters["immediatly"]=true; |
247 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
247 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | * @param array $parameters The ajax parameters, default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
258 | 258 | * @return string |
259 | 259 | */ |
260 | - public function ajaxInterval($method,$url, $interval,$globalName=null,$responseElement="", $parameters=[]){ |
|
261 | - return $this->interval($this->ajaxDeferred($method, $url,$responseElement,$parameters), $interval,$globalName); |
|
260 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[]) { |
|
261 | + return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | * @param string $responseElement selector of the HTML element displaying the answer |
269 | 269 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
270 | 270 | */ |
271 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
271 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
272 | 272 | $parameters["immediatly"]=false; |
273 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
273 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | * @param string $method Method used |
280 | 280 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
281 | 281 | */ |
282 | - private function _json($url, $method="get",$parameters=[]) { |
|
283 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
282 | + private function _json($url, $method="get", $parameters=[]) { |
|
283 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
284 | 284 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
285 | 285 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
286 | 286 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";" |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
289 | 289 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
290 | 290 | $parameters["jsCallback"]=$retour; |
291 | - return $this->_ajax($method, $url,null,$parameters); |
|
291 | + return $this->_ajax($method, $url, null, $parameters); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
299 | 299 | */ |
300 | 300 | public function json($url, $method="get", $parameters=[]) { |
301 | - return $this->_json($url,$method,$parameters); |
|
301 | + return $this->_json($url, $method, $parameters); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | * @param string $method default get |
310 | 310 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
311 | 311 | */ |
312 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
313 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
314 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
312 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
313 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
314 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
324 | 324 | $parameters["immediatly"]=false; |
325 | - return $this->_json($url,$method,$parameters); |
|
325 | + return $this->_json($url, $method, $parameters); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -333,27 +333,27 @@ discard block |
||
333 | 333 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
334 | 334 | */ |
335 | 335 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
336 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
336 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
337 | 337 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
338 | 338 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
339 | 339 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
340 | - if($context===null){ |
|
340 | + if ($context===null) { |
|
341 | 341 | $parent="$('".$maskSelector."').parent()"; |
342 | - $newElm = "$('#'+newId)"; |
|
343 | - }else{ |
|
342 | + $newElm="$('#'+newId)"; |
|
343 | + } else { |
|
344 | 344 | $parent=$context; |
345 | - $newElm = $context.".find('#'+newId)"; |
|
345 | + $newElm=$context.".find('#'+newId)"; |
|
346 | 346 | } |
347 | 347 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
348 | 348 | $retour=$parent.".find('.{$rowClass}').remove();"; |
349 | 349 | $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
350 | 350 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
351 | - $retour.= $appendTo; |
|
351 | + $retour.=$appendTo; |
|
352 | 352 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
353 | 353 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
354 | 354 | $retour.="\t".$jsCallback; |
355 | 355 | $parameters["jsCallback"]=$retour; |
356 | - return $this->_ajax($method, $url,null,$parameters); |
|
356 | + return $this->_ajax($method, $url, null, $parameters); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
365 | 365 | */ |
366 | 366 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
367 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
367 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -387,9 +387,9 @@ discard block |
||
387 | 387 | * @param string $method Method used, default : get |
388 | 388 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
389 | 389 | */ |
390 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
391 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
392 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
390 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
391 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
392 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | */ |
402 | 402 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
403 | 403 | $parameters["immediatly"]=false; |
404 | - return $this->_get($url, $responseElement,$parameters); |
|
404 | + return $this->_get($url, $responseElement, $parameters); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
415 | 415 | */ |
416 | 416 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
417 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
418 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
417 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
418 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
429 | 429 | */ |
430 | 430 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
431 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
432 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
431 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
432 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -463,15 +463,15 @@ discard block |
||
463 | 463 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true) |
464 | 464 | * @return $this |
465 | 465 | */ |
466 | - public function getHref($element,$responseElement="",$parameters=array()){ |
|
466 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
467 | 467 | $parameters["attr"]="href"; |
468 | - if(JString::isNull($responseElement)){ |
|
468 | + if (JString::isNull($responseElement)) { |
|
469 | 469 | $responseElement='%$(self).attr("data-target")%'; |
470 | 470 | } |
471 | - if(!isset($parameters["historize"])){ |
|
471 | + if (!isset($parameters["historize"])) { |
|
472 | 472 | $parameters["historize"]=true; |
473 | 473 | } |
474 | - return $this->getOnClick($element, "",$responseElement,$parameters); |
|
474 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -481,20 +481,20 @@ discard block |
||
481 | 481 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
482 | 482 | * @return $this |
483 | 483 | */ |
484 | - public function postHref($element,$responseElement="",$parameters=array()){ |
|
484 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
485 | 485 | $parameters["attr"]="href"; |
486 | - if(JString::isNull($responseElement)){ |
|
486 | + if (JString::isNull($responseElement)) { |
|
487 | 487 | $responseElement='%$(this).attr("data-target")%'; |
488 | 488 | } |
489 | - if(!isset($parameters["historize"])){ |
|
489 | + if (!isset($parameters["historize"])) { |
|
490 | 490 | $parameters["historize"]=true; |
491 | 491 | } |
492 | - return $this->postOnClick($element, "","{}",$responseElement,$parameters); |
|
492 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
493 | 493 | } |
494 | 494 | |
495 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
495 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
496 | 496 | $parameters["params"]=$params; |
497 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
497 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | * @param string $params JSON parameters |
505 | 505 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
506 | 506 | */ |
507 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
508 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
507 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
508 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * @param string $responseElement selector of the HTML element displaying the answer |
517 | 517 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
518 | 518 | */ |
519 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
519 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
520 | 520 | $parameters["immediatly"]=false; |
521 | 521 | return $this->_post($url, $params, $responseElement, $parameters); |
522 | 522 | } |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
533 | 533 | */ |
534 | 534 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
535 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
536 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
535 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
536 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -550,33 +550,33 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
553 | - if(isset($this->params["ajax"])){ |
|
553 | + if (isset($this->params["ajax"])) { |
|
554 | 554 | extract($this->params["ajax"]); |
555 | 555 | } |
556 | - $params="{}";$validation=false; |
|
556 | + $params="{}"; $validation=false; |
|
557 | 557 | \extract($parameters); |
558 | - $async=($async)?"true":"false"; |
|
558 | + $async=($async) ? "true" : "false"; |
|
559 | 559 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
560 | 560 | $retour=$this->_getAjaxUrl($url, $attr); |
561 | 561 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
562 | 562 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
563 | - if(isset($params)){ |
|
563 | + if (isset($params)) { |
|
564 | 564 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
565 | 565 | } |
566 | 566 | $responseElement=$this->_getResponseElement($responseElement); |
567 | 567 | $retour.="var self=this;\n"; |
568 | - if($hasLoader===true){ |
|
569 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
570 | - }elseif($hasLoader==="internal"){ |
|
568 | + if ($hasLoader===true) { |
|
569 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
570 | + }elseif ($hasLoader==="internal") { |
|
571 | 571 | $retour.="\n$(this).addClass('loading');"; |
572 | 572 | } |
573 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
574 | - if(isset($headers)){ |
|
573 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
574 | + if (isset($headers)) { |
|
575 | 575 | $ajaxParameters["headers"]=$headers; |
576 | 576 | } |
577 | 577 | $this->createAjaxParameters($ajaxParameters, $parameters); |
578 | 578 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
579 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
579 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
580 | 580 | |
581 | 581 | if ($validation) { |
582 | 582 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -626,8 +626,8 @@ discard block |
||
626 | 626 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
627 | 627 | */ |
628 | 628 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
629 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
630 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
629 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
630 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |