@@ -15,63 +15,63 @@ discard block |
||
15 | 15 | |
16 | 16 | protected $ajaxTransition; |
17 | 17 | |
18 | - protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
18 | + protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
19 | 19 | |
20 | 20 | abstract public function getUrl($url); |
21 | 21 | |
22 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true); |
|
22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
23 | 23 | |
24 | - abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
24 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
25 | 25 | |
26 | - protected function _ajax($method, $url, $responseElement = "", $parameters = []) { |
|
26 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
27 | 27 | if (isset($this->params["ajax"])) { |
28 | 28 | extract($this->params["ajax"]); |
29 | 29 | } |
30 | 30 | extract($parameters); |
31 | 31 | |
32 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
33 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
34 | - $originalSelector = $responseElement; |
|
35 | - $responseElement = $this->_getResponseElement($responseElement); |
|
36 | - $retour .= "var self=this;\n"; |
|
37 | - $before = isset($before) ? $before : ""; |
|
38 | - $retour .= $before; |
|
39 | - if ($hasLoader === true && JString::isNotNull($responseElement)) { |
|
32 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
33 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
34 | + $originalSelector=$responseElement; |
|
35 | + $responseElement=$this->_getResponseElement($responseElement); |
|
36 | + $retour.="var self=this;\n"; |
|
37 | + $before=isset($before) ? $before : ""; |
|
38 | + $retour.=$before; |
|
39 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
40 | 40 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
41 | - } elseif ($hasLoader === 'response') { |
|
41 | + } elseif ($hasLoader==='response') { |
|
42 | 42 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
43 | - } elseif ($hasLoader === 'internal') { |
|
44 | - $retour .= "\n$(this).addClass('loading');"; |
|
43 | + } elseif ($hasLoader==='internal') { |
|
44 | + $retour.="\n$(this).addClass('loading');"; |
|
45 | 45 | } |
46 | - $ajaxParameters = [ |
|
46 | + $ajaxParameters=[ |
|
47 | 47 | "url" => "url", |
48 | - "method" => "'" . \strtoupper($method) . "'" |
|
48 | + "method" => "'".\strtoupper($method)."'" |
|
49 | 49 | ]; |
50 | 50 | |
51 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
51 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
52 | 52 | |
53 | 53 | if (isset($params)) { |
54 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
54 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
55 | 55 | } |
56 | 56 | if (isset($headers)) { |
57 | - $ajaxParameters["headers"] = $headers; |
|
57 | + $ajaxParameters["headers"]=$headers; |
|
58 | 58 | } |
59 | 59 | if (isset($partial)) { |
60 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
61 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
60 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
61 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
62 | 62 | } |
63 | 63 | $this->createAjaxParameters($ajaxParameters, $parameters); |
64 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
65 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
|
64 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
65 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
66 | 66 | |
67 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
67 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
68 | 68 | if ($immediatly) |
69 | - $this->jquery_code_for_compile[] = $retour; |
|
69 | + $this->jquery_code_for_compile[]=$retour; |
|
70 | 70 | return $retour; |
71 | 71 | } |
72 | 72 | |
73 | 73 | protected function createAjaxParameters(&$original, $parameters) { |
74 | - $validParameters = [ |
|
74 | + $validParameters=[ |
|
75 | 75 | "contentType" => "%value%", |
76 | 76 | "dataType" => "'%value%'", |
77 | 77 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -80,21 +80,21 @@ discard block |
||
80 | 80 | ]; |
81 | 81 | foreach ($validParameters as $param => $mask) { |
82 | 82 | if (isset($parameters[$param])) { |
83 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
83 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | 88 | protected function implodeAjaxParameters($ajaxParameters) { |
89 | - $s = ''; |
|
89 | + $s=''; |
|
90 | 90 | foreach ($ajaxParameters as $k => $v) { |
91 | - if ($s !== '') { |
|
92 | - $s .= ','; |
|
91 | + if ($s!=='') { |
|
92 | + $s.=','; |
|
93 | 93 | } |
94 | 94 | if (is_array($v)) { |
95 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
95 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
96 | 96 | } else { |
97 | - $s .= "'{$k}':{$v}"; |
|
97 | + $s.="'{$k}':{$v}"; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | return $s; |
@@ -102,27 +102,27 @@ discard block |
||
102 | 102 | |
103 | 103 | protected function _addJsCondition($jsCondition, $jsSource) { |
104 | 104 | if (isset($jsCondition)) { |
105 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
105 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
106 | 106 | } |
107 | 107 | return $jsSource; |
108 | 108 | } |
109 | 109 | |
110 | 110 | protected function _getAjaxUrl($url, $attr) { |
111 | - $url = $this->_correctAjaxUrl($url); |
|
112 | - $retour = "url='" . $url . "';"; |
|
113 | - $slash = "/"; |
|
114 | - if (JString::endswith($url, "/") === true) { |
|
115 | - $slash = ""; |
|
111 | + $url=$this->_correctAjaxUrl($url); |
|
112 | + $retour="url='".$url."';"; |
|
113 | + $slash="/"; |
|
114 | + if (JString::endswith($url, "/")===true) { |
|
115 | + $slash=""; |
|
116 | 116 | } |
117 | 117 | if (JString::isNotNull($attr)) { |
118 | - if ($attr === "value") { |
|
119 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
120 | - } elseif ($attr === "html") { |
|
121 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
122 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
123 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
124 | - } elseif ($attr !== null && $attr !== "") |
|
125 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
118 | + if ($attr==="value") { |
|
119 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
120 | + } elseif ($attr==="html") { |
|
121 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
122 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
123 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
124 | + } elseif ($attr!==null && $attr!=="") |
|
125 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
126 | 126 | } |
127 | 127 | return $retour; |
128 | 128 | } |
@@ -131,99 +131,99 @@ discard block |
||
131 | 131 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
132 | 132 | } |
133 | 133 | |
134 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
135 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
136 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
134 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
135 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
136 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
137 | 137 | return $result; |
138 | 138 | } |
139 | 139 | |
140 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
141 | - $retour = ""; |
|
142 | - $call = null; |
|
140 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
141 | + $retour=""; |
|
142 | + $call=null; |
|
143 | 143 | if (JString::isNotNull($responseElement)) { |
144 | 144 | if (isset($ajaxTransition)) { |
145 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
145 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
146 | 146 | } elseif (isset($this->ajaxTransition)) { |
147 | - $call = $this->ajaxTransition; |
|
147 | + $call=$this->ajaxTransition; |
|
148 | 148 | } |
149 | 149 | if (\is_callable($call)) |
150 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
150 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
151 | 151 | else |
152 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
152 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
153 | 153 | } |
154 | 154 | if (isset($history)) { |
155 | 155 | if ($this->params["autoActiveLinks"]) { |
156 | - $retour .= $this->autoActiveLinks("url"); |
|
156 | + $retour.=$this->autoActiveLinks("url"); |
|
157 | 157 | } |
158 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
158 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
159 | 159 | } |
160 | - if ($hasLoader === "internal") { |
|
161 | - $retour .= "\n$(self).removeClass('loading');"; |
|
160 | + if ($hasLoader==="internal") { |
|
161 | + $retour.="\n$(self).removeClass('loading');"; |
|
162 | 162 | } |
163 | - $retour .= "\t" . $jsCallback . "\n"; |
|
163 | + $retour.="\t".$jsCallback."\n"; |
|
164 | 164 | return $retour; |
165 | 165 | } |
166 | 166 | |
167 | 167 | protected function _getResponseElement($responseElement) { |
168 | 168 | if (JString::isNotNull($responseElement)) { |
169 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
169 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
170 | 170 | } |
171 | 171 | return $responseElement; |
172 | 172 | } |
173 | 173 | |
174 | 174 | protected function _correctAjaxUrl($url) { |
175 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
176 | - $url = substr($url, 0, strlen($url) - 1); |
|
177 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
178 | - $url = $this->getUrl($url); |
|
175 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
176 | + $url=substr($url, 0, strlen($url)-1); |
|
177 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
178 | + $url=$this->getUrl($url); |
|
179 | 179 | } |
180 | 180 | return $url; |
181 | 181 | } |
182 | 182 | |
183 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
183 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
184 | 184 | if (JString::isNull($params)) { |
185 | 185 | return ""; |
186 | 186 | } |
187 | 187 | if (\preg_match("@^\{.*?\}$@", $params)) { |
188 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
189 | - return '$.param(' . $params . ')'; |
|
188 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
189 | + return '$.param('.$params.')'; |
|
190 | 190 | } else { |
191 | - return 'JSON.stringify(' . $params . ')'; |
|
191 | + return 'JSON.stringify('.$params.')'; |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | return $params; |
195 | 195 | } |
196 | 196 | |
197 | 197 | public static function _implodeParams($parameters) { |
198 | - $allParameters = []; |
|
198 | + $allParameters=[]; |
|
199 | 199 | foreach ($parameters as $params) { |
200 | 200 | if (isset($params)) |
201 | - $allParameters[] = self::_correctParams($params); |
|
201 | + $allParameters[]=self::_correctParams($params); |
|
202 | 202 | } |
203 | 203 | return \implode("+'&'+", $allParameters); |
204 | 204 | } |
205 | 205 | |
206 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
207 | - if (! isset($ajaxLoader)) { |
|
208 | - $ajaxLoader = $this->ajaxLoader; |
|
206 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
207 | + if (!isset($ajaxLoader)) { |
|
208 | + $ajaxLoader=$this->ajaxLoader; |
|
209 | 209 | } |
210 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
211 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
210 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
211 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
212 | 212 | } |
213 | 213 | |
214 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
215 | - if (! isset($ajaxLoader)) { |
|
216 | - $ajaxLoader = $this->ajaxLoader; |
|
214 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
215 | + if (!isset($ajaxLoader)) { |
|
216 | + $ajaxLoader=$this->ajaxLoader; |
|
217 | 217 | } |
218 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
219 | - $retour .= "{$responseElement}.empty();\n"; |
|
220 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
218 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
219 | + $retour.="{$responseElement}.empty();\n"; |
|
220 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | protected function setAjaxDataCall($params) { |
224 | - $result = null; |
|
225 | - if (! \is_callable($params)) { |
|
226 | - $result = function ($responseElement, $jqueryDone = "html") use ($params) { |
|
224 | + $result=null; |
|
225 | + if (!\is_callable($params)) { |
|
226 | + $result=function($responseElement, $jqueryDone="html") use ($params) { |
|
227 | 227 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
228 | 228 | }; |
229 | 229 | } |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | |
233 | 233 | protected function setDefaultParameters(&$parameters, $default) { |
234 | 234 | foreach ($default as $k => $v) { |
235 | - if (! isset($parameters[$k])) |
|
236 | - $parameters[$k] = $v; |
|
235 | + if (!isset($parameters[$k])) |
|
236 | + $parameters[$k]=$v; |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | 240 | public function setAjaxLoader($loader) { |
241 | - $this->ajaxLoader = $loader; |
|
241 | + $this->ajaxLoader=$loader; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @param string $responseElement |
250 | 250 | * selector of the HTML element displaying the answer |
251 | 251 | */ |
252 | - private function _get($url, $responseElement = "", $parameters = []) { |
|
252 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
253 | 253 | return $this->_ajax("get", $url, $responseElement, $parameters); |
254 | 254 | } |
255 | 255 | |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | * @param array $parameters |
264 | 264 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
265 | 265 | */ |
266 | - public function get($url, $responseElement = "", $parameters = []) { |
|
267 | - $parameters["immediatly"] = true; |
|
266 | + public function get($url, $responseElement="", $parameters=[]) { |
|
267 | + $parameters["immediatly"]=true; |
|
268 | 268 | return $this->_get($url, $responseElement, $parameters); |
269 | 269 | } |
270 | 270 | |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * @param array $parameters |
281 | 281 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
282 | 282 | */ |
283 | - public function ajax($method, $url, $responseElement = "", $parameters = []) { |
|
284 | - $parameters["immediatly"] = true; |
|
283 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
284 | + $parameters["immediatly"]=true; |
|
285 | 285 | return $this->_ajax($method, $url, $responseElement, $parameters); |
286 | 286 | } |
287 | 287 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * $immediatly |
304 | 304 | * @return string |
305 | 305 | */ |
306 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = "", $parameters = [], $immediatly = true) { |
|
306 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[], $immediatly=true) { |
|
307 | 307 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
308 | 308 | } |
309 | 309 | |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | * @param array $parameters |
320 | 320 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
321 | 321 | */ |
322 | - public function ajaxDeferred($method, $url, $responseElement = "", $parameters = []) { |
|
323 | - $parameters["immediatly"] = false; |
|
322 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
323 | + $parameters["immediatly"]=false; |
|
324 | 324 | return $this->_ajax($method, $url, $responseElement, $parameters); |
325 | 325 | } |
326 | 326 | |
@@ -334,15 +334,15 @@ discard block |
||
334 | 334 | * @param array $parameters |
335 | 335 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
336 | 336 | */ |
337 | - private function _json($url, $method = "get", $parameters = []) { |
|
338 | - $parameters = \array_merge($parameters, [ |
|
337 | + private function _json($url, $method="get", $parameters=[]) { |
|
338 | + $parameters=\array_merge($parameters, [ |
|
339 | 339 | "hasLoader" => false |
340 | 340 | ]); |
341 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
342 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
343 | - $retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(var key in data){" . "if($('#'+key," . $context . ").length){ if($('#'+key," . $context . ").is('[value]')) { $('#'+key," . $context . ").val(data[key]);} else { $('#'+key," . $context . ").html(data[key]); }}};\n"; |
|
344 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
345 | - $parameters["jsCallback"] = $retour; |
|
341 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
342 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
343 | + $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(var key in data){"."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
|
344 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
345 | + $parameters["jsCallback"]=$retour; |
|
346 | 346 | return $this->_ajax($method, $url, null, $parameters); |
347 | 347 | } |
348 | 348 | |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * @param array $parameters |
357 | 357 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
358 | 358 | */ |
359 | - public function json($url, $method = "get", $parameters = []) { |
|
359 | + public function json($url, $method="get", $parameters=[]) { |
|
360 | 360 | return $this->_json($url, $method, $parameters); |
361 | 361 | } |
362 | 362 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | * @param array $parameters |
373 | 373 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null) |
374 | 374 | */ |
375 | - public function jsonOn($event, $element, $url, $method = "get", $parameters = array()) { |
|
375 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
376 | 376 | $this->setDefaultParameters($parameters, [ |
377 | 377 | "preventDefault" => true, |
378 | 378 | "stopPropagation" => true, |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | * @param array $parameters |
392 | 392 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
393 | 393 | */ |
394 | - public function jsonDeferred($url, $method = "get", $parameters = []) { |
|
395 | - $parameters["immediatly"] = false; |
|
394 | + public function jsonDeferred($url, $method="get", $parameters=[]) { |
|
395 | + $parameters["immediatly"]=false; |
|
396 | 396 | return $this->_json($url, $method, $parameters); |
397 | 397 | } |
398 | 398 | |
@@ -407,29 +407,29 @@ discard block |
||
407 | 407 | * @param array $parameters |
408 | 408 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
409 | 409 | */ |
410 | - private function _jsonArray($maskSelector, $url, $method = "get", $parameters = []) { |
|
411 | - $parameters = \array_merge($parameters, [ |
|
410 | + private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
411 | + $parameters=\array_merge($parameters, [ |
|
412 | 412 | "hasLoader" => false |
413 | 413 | ]); |
414 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
415 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
416 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
417 | - if ($context === null) { |
|
418 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
419 | - $newElm = "$('#'+newId)"; |
|
414 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
415 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
416 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
417 | + if ($context===null) { |
|
418 | + $parent="$('".$maskSelector."').parent()"; |
|
419 | + $newElm="$('#'+newId)"; |
|
420 | 420 | } else { |
421 | - $parent = $context; |
|
422 | - $newElm = $context . ".find('#'+newId)"; |
|
421 | + $parent=$context; |
|
422 | + $newElm=$context.".find('#'+newId)"; |
|
423 | 423 | } |
424 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
425 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
426 | - $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(); |
|
424 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
425 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
426 | + $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(); |
|
427 | 427 | 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"; |
428 | - $retour .= $appendTo; |
|
429 | - $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"; |
|
430 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
431 | - $retour .= "\t" . $jsCallback; |
|
432 | - $parameters["jsCallback"] = $retour; |
|
428 | + $retour.=$appendTo; |
|
429 | + $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"; |
|
430 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
431 | + $retour.="\t".$jsCallback; |
|
432 | + $parameters["jsCallback"]=$retour; |
|
433 | 433 | return $this->_ajax($method, $url, null, $parameters); |
434 | 434 | } |
435 | 435 | |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * @param array $parameters |
445 | 445 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
446 | 446 | */ |
447 | - public function jsonArray($maskSelector, $url, $method = "get", $parameters = []) { |
|
447 | + public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
448 | 448 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
449 | 449 | } |
450 | 450 | |
@@ -459,8 +459,8 @@ discard block |
||
459 | 459 | * @param array $parameters |
460 | 460 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
461 | 461 | */ |
462 | - public function jsonArrayDeferred($maskSelector, $url, $method = "get", $parameters) { |
|
463 | - $parameters["immediatly"] = false; |
|
462 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $parameters) { |
|
463 | + $parameters["immediatly"]=false; |
|
464 | 464 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
465 | 465 | } |
466 | 466 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * @param array $parameters |
477 | 477 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null) |
478 | 478 | */ |
479 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = "get", $parameters = array()) { |
|
479 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
480 | 480 | $this->setDefaultParameters($parameters, [ |
481 | 481 | "preventDefault" => true, |
482 | 482 | "stopPropagation" => true, |
@@ -496,8 +496,8 @@ discard block |
||
496 | 496 | * @param array $parameters |
497 | 497 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
498 | 498 | */ |
499 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
500 | - $parameters["immediatly"] = false; |
|
499 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
500 | + $parameters["immediatly"]=false; |
|
501 | 501 | return $this->_get($url, $responseElement, $parameters); |
502 | 502 | } |
503 | 503 | |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * @param array $parameters |
517 | 517 | * 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,"before"=>null) |
518 | 518 | */ |
519 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
519 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
520 | 520 | $this->setDefaultParameters($parameters, [ |
521 | 521 | "preventDefault" => true, |
522 | 522 | "stopPropagation" => true, |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | * @param array $parameters |
541 | 541 | * 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,"before"=>null) |
542 | 542 | */ |
543 | - public function ajaxOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
543 | + public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
544 | 544 | $this->setDefaultParameters($parameters, [ |
545 | 545 | "preventDefault" => true, |
546 | 546 | "stopPropagation" => true, |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * @param array $parameters |
564 | 564 | * 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,"before"=>null) |
565 | 565 | */ |
566 | - public function ajaxOnClick($element, $url, $responseElement = "", $parameters = array()) { |
|
566 | + public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
567 | 567 | return $this->ajaxOn("click", $element, $url, $responseElement, $parameters); |
568 | 568 | } |
569 | 569 | |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @param array $parameters |
581 | 581 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
582 | 582 | */ |
583 | - public function getOnClick($element, $url, $responseElement = "", $parameters = array()) { |
|
583 | + public function getOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
584 | 584 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
585 | 585 | } |
586 | 586 | |
@@ -595,15 +595,15 @@ discard block |
||
595 | 595 | * 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,"before"=>null) |
596 | 596 | * @return $this |
597 | 597 | */ |
598 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
599 | - $parameters["attr"] = "href"; |
|
598 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
599 | + $parameters["attr"]="href"; |
|
600 | 600 | if (JString::isNull($responseElement)) { |
601 | - $responseElement = '%$(self).attr("data-target")%'; |
|
601 | + $responseElement='%$(self).attr("data-target")%'; |
|
602 | 602 | } else { |
603 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
603 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
604 | 604 | } |
605 | - if (! isset($parameters["historize"])) { |
|
606 | - $parameters["historize"] = true; |
|
605 | + if (!isset($parameters["historize"])) { |
|
606 | + $parameters["historize"]=true; |
|
607 | 607 | } |
608 | 608 | return $this->getOnClick($element, "", $responseElement, $parameters); |
609 | 609 | } |
@@ -619,21 +619,21 @@ discard block |
||
619 | 619 | * 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,"before"=>null) |
620 | 620 | * @return $this |
621 | 621 | */ |
622 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
623 | - $parameters["attr"] = "href"; |
|
622 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
623 | + $parameters["attr"]="href"; |
|
624 | 624 | if (JString::isNull($responseElement)) { |
625 | - $responseElement = '%$(this).attr("data-target")%'; |
|
625 | + $responseElement='%$(this).attr("data-target")%'; |
|
626 | 626 | } else { |
627 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
627 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
628 | 628 | } |
629 | - if (! isset($parameters["historize"])) { |
|
630 | - $parameters["historize"] = true; |
|
629 | + if (!isset($parameters["historize"])) { |
|
630 | + $parameters["historize"]=true; |
|
631 | 631 | } |
632 | 632 | return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
633 | 633 | } |
634 | 634 | |
635 | - private function _post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
636 | - $parameters["params"] = $params; |
|
635 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
636 | + $parameters["params"]=$params; |
|
637 | 637 | return $this->_ajax("POST", $url, $responseElement, $parameters); |
638 | 638 | } |
639 | 639 | |
@@ -649,8 +649,8 @@ discard block |
||
649 | 649 | * @param array $parameters |
650 | 650 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
651 | 651 | */ |
652 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
653 | - $parameters['immediatly'] = true; |
|
652 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
653 | + $parameters['immediatly']=true; |
|
654 | 654 | return $this->_post($url, $params, $responseElement, $parameters); |
655 | 655 | } |
656 | 656 | |
@@ -667,8 +667,8 @@ discard block |
||
667 | 667 | * @param array $parameters |
668 | 668 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
669 | 669 | */ |
670 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
671 | - $parameters["immediatly"] = false; |
|
670 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
671 | + $parameters["immediatly"]=false; |
|
672 | 672 | return $this->_post($url, $params, $responseElement, $parameters); |
673 | 673 | } |
674 | 674 | |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | * @param array $parameters |
688 | 688 | * 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,"before"=>null) |
689 | 689 | */ |
690 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
690 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
691 | 691 | $this->setDefaultParameters($parameters, [ |
692 | 692 | "preventDefault" => true, |
693 | 693 | "stopPropagation" => true, |
@@ -710,66 +710,66 @@ discard block |
||
710 | 710 | * @param array $parameters |
711 | 711 | * 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,"before"=>null,"before"=>null) |
712 | 712 | */ |
713 | - public function postOnClick($element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
713 | + public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
714 | 714 | return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
715 | 715 | } |
716 | 716 | |
717 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
717 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
718 | 718 | if (isset($this->params["ajax"])) { |
719 | 719 | extract($this->params["ajax"]); |
720 | 720 | } |
721 | - $params = "{}"; |
|
722 | - $validation = false; |
|
721 | + $params="{}"; |
|
722 | + $validation=false; |
|
723 | 723 | \extract($parameters); |
724 | - $async = ($async) ? "true" : "false"; |
|
725 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
726 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
727 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
728 | - if (! isset($contentType) || $contentType != 'false') { |
|
729 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
724 | + $async=($async) ? "true" : "false"; |
|
725 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
726 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
727 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
728 | + if (!isset($contentType) || $contentType!='false') { |
|
729 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
730 | 730 | if (isset($params)) { |
731 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
731 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
732 | 732 | } |
733 | 733 | } else { |
734 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
734 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
735 | 735 | } |
736 | - $responseElement = $this->_getResponseElement($responseElement); |
|
737 | - $retour .= "var self=this;\n"; |
|
738 | - $before = isset($before) ? $before : ""; |
|
739 | - $retour .= $before; |
|
740 | - if ($hasLoader === true) { |
|
736 | + $responseElement=$this->_getResponseElement($responseElement); |
|
737 | + $retour.="var self=this;\n"; |
|
738 | + $before=isset($before) ? $before : ""; |
|
739 | + $retour.=$before; |
|
740 | + if ($hasLoader===true) { |
|
741 | 741 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
742 | - } elseif ($hasLoader === 'response') { |
|
742 | + } elseif ($hasLoader==='response') { |
|
743 | 743 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
744 | - } elseif ($hasLoader === 'internal') { |
|
745 | - $retour .= "\n$(this).addClass('loading');"; |
|
744 | + } elseif ($hasLoader==='internal') { |
|
745 | + $retour.="\n$(this).addClass('loading');"; |
|
746 | 746 | } |
747 | - $ajaxParameters = [ |
|
747 | + $ajaxParameters=[ |
|
748 | 748 | "url" => "url", |
749 | 749 | "method" => "'POST'", |
750 | 750 | "data" => "params", |
751 | 751 | "async" => $async |
752 | 752 | ]; |
753 | 753 | if (isset($headers)) { |
754 | - $ajaxParameters["headers"] = $headers; |
|
754 | + $ajaxParameters["headers"]=$headers; |
|
755 | 755 | } |
756 | 756 | if (isset($partial)) { |
757 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
758 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
757 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
758 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
759 | 759 | } |
760 | 760 | $this->createAjaxParameters($ajaxParameters, $parameters); |
761 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
762 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n"; |
|
761 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
762 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
763 | 763 | |
764 | 764 | if ($validation) { |
765 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
766 | - " . $retour . " |
|
765 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
766 | + " . $retour." |
|
767 | 767 | }});\n"; |
768 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
768 | + $retour.="$('#".$form."').submit();\n"; |
|
769 | 769 | } |
770 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
770 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
771 | 771 | if ($immediatly) |
772 | - $this->jquery_code_for_compile[] = $retour; |
|
772 | + $this->jquery_code_for_compile[]=$retour; |
|
773 | 773 | return $retour; |
774 | 774 | } |
775 | 775 | |
@@ -785,8 +785,8 @@ discard block |
||
785 | 785 | * @param array $parameters |
786 | 786 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
787 | 787 | */ |
788 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
789 | - $parameters["immediatly"] = true; |
|
788 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
789 | + $parameters["immediatly"]=true; |
|
790 | 790 | return $this->_postForm($url, $form, $responseElement, $parameters); |
791 | 791 | } |
792 | 792 | |
@@ -803,8 +803,8 @@ discard block |
||
803 | 803 | * @param array $parameters |
804 | 804 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
805 | 805 | */ |
806 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
807 | - $parameters["immediatly"] = false; |
|
806 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
807 | + $parameters["immediatly"]=false; |
|
808 | 808 | return $this->_postForm($url, $form, $responseElement, $parameters); |
809 | 809 | } |
810 | 810 | |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | * @param array $parameters |
822 | 822 | * 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,"before"=>null) |
823 | 823 | */ |
824 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
824 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
825 | 825 | $this->setDefaultParameters($parameters, [ |
826 | 826 | "preventDefault" => true, |
827 | 827 | "stopPropagation" => true, |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | * @param array $parameters |
843 | 843 | * 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,"before"=>null) |
844 | 844 | */ |
845 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
845 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
846 | 846 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
847 | 847 | } |
848 | 848 | } |