@@ -15,69 +15,69 @@ 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, $listenerOn = false); |
|
22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
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-x') { |
|
43 | + } elseif ($hasLoader==='internal-x') { |
|
44 | 44 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
45 | - } elseif ($hasLoader === 'internal') { |
|
46 | - $retour .= "\n$(this).addClass('loading');"; |
|
45 | + } elseif ($hasLoader==='internal') { |
|
46 | + $retour.="\n$(this).addClass('loading');"; |
|
47 | 47 | } |
48 | - $ajaxParameters = [ |
|
48 | + $ajaxParameters=[ |
|
49 | 49 | "url" => "url", |
50 | - "method" => "'" . \strtoupper($method) . "'" |
|
50 | + "method" => "'".\strtoupper($method)."'" |
|
51 | 51 | ]; |
52 | 52 | |
53 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
53 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
54 | 54 | |
55 | 55 | if (isset($params)) { |
56 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
56 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
57 | 57 | } |
58 | 58 | if (isset($headers)) { |
59 | - $ajaxParameters["headers"] = $headers; |
|
59 | + $ajaxParameters["headers"]=$headers; |
|
60 | 60 | } |
61 | 61 | if ($csrf) { |
62 | - $csrf = (is_string($csrf)) ? $csrf : 'csrf-token'; |
|
63 | - $parameters["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
62 | + $csrf=(is_string($csrf)) ? $csrf : 'csrf-token'; |
|
63 | + $parameters["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
64 | 64 | } |
65 | 65 | if (isset($partial)) { |
66 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
67 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
66 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
67 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
68 | 68 | } |
69 | 69 | $this->createAjaxParameters($ajaxParameters, $parameters); |
70 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
71 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
|
70 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
71 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
72 | 72 | |
73 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
73 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
74 | 74 | if ($immediatly) |
75 | - $this->jquery_code_for_compile[] = $retour; |
|
75 | + $this->jquery_code_for_compile[]=$retour; |
|
76 | 76 | return $retour; |
77 | 77 | } |
78 | 78 | |
79 | 79 | protected function createAjaxParameters(&$original, $parameters) { |
80 | - $validParameters = [ |
|
80 | + $validParameters=[ |
|
81 | 81 | "contentType" => "%value%", |
82 | 82 | "dataType" => "'%value%'", |
83 | 83 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -86,21 +86,21 @@ discard block |
||
86 | 86 | ]; |
87 | 87 | foreach ($validParameters as $param => $mask) { |
88 | 88 | if (isset($parameters[$param])) { |
89 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
89 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | protected function implodeAjaxParameters($ajaxParameters) { |
95 | - $s = ''; |
|
95 | + $s=''; |
|
96 | 96 | foreach ($ajaxParameters as $k => $v) { |
97 | - if ($s !== '') { |
|
98 | - $s .= ','; |
|
97 | + if ($s!=='') { |
|
98 | + $s.=','; |
|
99 | 99 | } |
100 | 100 | if (is_array($v)) { |
101 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
101 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
102 | 102 | } else { |
103 | - $s .= "'{$k}':{$v}"; |
|
103 | + $s.="'{$k}':{$v}"; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | return $s; |
@@ -108,29 +108,29 @@ discard block |
||
108 | 108 | |
109 | 109 | protected function _addJsCondition($jsCondition, $jsSource) { |
110 | 110 | if (isset($jsCondition)) { |
111 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
111 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
112 | 112 | } |
113 | 113 | return $jsSource; |
114 | 114 | } |
115 | 115 | |
116 | 116 | protected function _getAjaxUrl($url, $attr) { |
117 | - $url = $this->_correctAjaxUrl($url); |
|
118 | - $retour = "url='" . $url . "';"; |
|
119 | - $slash = "/"; |
|
120 | - if (JString::endswith($url, "/") === true) { |
|
121 | - $slash = ""; |
|
117 | + $url=$this->_correctAjaxUrl($url); |
|
118 | + $retour="url='".$url."';"; |
|
119 | + $slash="/"; |
|
120 | + if (JString::endswith($url, "/")===true) { |
|
121 | + $slash=""; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | if (JString::isNotNull($attr)) { |
125 | - if ($attr === "value") { |
|
126 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
127 | - } elseif ($attr === "html") { |
|
128 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
129 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
130 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
131 | - } elseif ($attr !== null && $attr !== "") { |
|
132 | - $retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';"; |
|
133 | - $retour .= "url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'" . $slash . "'+elmUrl:elmUrl;\n"; |
|
125 | + if ($attr==="value") { |
|
126 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
127 | + } elseif ($attr==="html") { |
|
128 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
129 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
130 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
131 | + } elseif ($attr!==null && $attr!=="") { |
|
132 | + $retour.="let elmUrl=$(this).attr('".$attr."')||'';"; |
|
133 | + $retour.="url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'".$slash."'+elmUrl:elmUrl;\n"; |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | return $retour; |
@@ -140,101 +140,101 @@ discard block |
||
140 | 140 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
141 | 141 | } |
142 | 142 | |
143 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
144 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
145 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
143 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
144 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
145 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
146 | 146 | return $result; |
147 | 147 | } |
148 | 148 | |
149 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
150 | - $retour = ""; |
|
151 | - $call = null; |
|
149 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
150 | + $retour=""; |
|
151 | + $call=null; |
|
152 | 152 | if (JString::isNotNull($responseElement)) { |
153 | 153 | if (isset($ajaxTransition)) { |
154 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
154 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
155 | 155 | } elseif (isset($this->ajaxTransition)) { |
156 | - $call = $this->ajaxTransition; |
|
156 | + $call=$this->ajaxTransition; |
|
157 | 157 | } |
158 | 158 | if (\is_callable($call)) |
159 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
159 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
160 | 160 | else |
161 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
161 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
162 | 162 | } |
163 | 163 | if (isset($history)) { |
164 | 164 | if ($this->params["autoActiveLinks"]) { |
165 | - $retour .= $this->autoActiveLinks("url"); |
|
165 | + $retour.=$this->autoActiveLinks("url"); |
|
166 | 166 | } |
167 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
167 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
168 | 168 | } |
169 | - if ($hasLoader === 'internal') { |
|
170 | - $retour .= "\n$(self).removeClass('loading');"; |
|
171 | - } elseif ($hasLoader === 'internal-x') { |
|
172 | - $retour .= "\n$(self).children('.ajax-loader').remove();"; |
|
169 | + if ($hasLoader==='internal') { |
|
170 | + $retour.="\n$(self).removeClass('loading');"; |
|
171 | + } elseif ($hasLoader==='internal-x') { |
|
172 | + $retour.="\n$(self).children('.ajax-loader').remove();"; |
|
173 | 173 | } |
174 | - $retour .= "\t" . $jsCallback . "\n"; |
|
174 | + $retour.="\t".$jsCallback."\n"; |
|
175 | 175 | return $retour; |
176 | 176 | } |
177 | 177 | |
178 | 178 | protected function _getResponseElement($responseElement) { |
179 | 179 | if (JString::isNotNull($responseElement)) { |
180 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
180 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
181 | 181 | } |
182 | 182 | return $responseElement; |
183 | 183 | } |
184 | 184 | |
185 | 185 | protected function _correctAjaxUrl($url) { |
186 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
187 | - $url = substr($url, 0, strlen($url) - 1); |
|
188 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
189 | - $url = $this->getUrl($url); |
|
186 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
187 | + $url=substr($url, 0, strlen($url)-1); |
|
188 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
189 | + $url=$this->getUrl($url); |
|
190 | 190 | } |
191 | 191 | return $url; |
192 | 192 | } |
193 | 193 | |
194 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
194 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
195 | 195 | if (JString::isNull($params)) { |
196 | 196 | return ""; |
197 | 197 | } |
198 | 198 | if (\preg_match("@^\{.*?\}$@", $params)) { |
199 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
200 | - return '$.param(' . $params . ')'; |
|
199 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
200 | + return '$.param('.$params.')'; |
|
201 | 201 | } else { |
202 | - return 'JSON.stringify(' . $params . ')'; |
|
202 | + return 'JSON.stringify('.$params.')'; |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | return $params; |
206 | 206 | } |
207 | 207 | |
208 | 208 | public static function _implodeParams($parameters) { |
209 | - $allParameters = []; |
|
209 | + $allParameters=[]; |
|
210 | 210 | foreach ($parameters as $params) { |
211 | 211 | if (isset($params)) |
212 | - $allParameters[] = self::_correctParams($params); |
|
212 | + $allParameters[]=self::_correctParams($params); |
|
213 | 213 | } |
214 | 214 | return \implode("+'&'+", $allParameters); |
215 | 215 | } |
216 | 216 | |
217 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
218 | - if (! isset($ajaxLoader)) { |
|
219 | - $ajaxLoader = $this->ajaxLoader; |
|
217 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
218 | + if (!isset($ajaxLoader)) { |
|
219 | + $ajaxLoader=$this->ajaxLoader; |
|
220 | 220 | } |
221 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
222 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
221 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
222 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
223 | 223 | } |
224 | 224 | |
225 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
226 | - if (! isset($ajaxLoader)) { |
|
227 | - $ajaxLoader = $this->ajaxLoader; |
|
225 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
226 | + if (!isset($ajaxLoader)) { |
|
227 | + $ajaxLoader=$this->ajaxLoader; |
|
228 | 228 | } |
229 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
230 | - $retour .= "{$responseElement}.empty();\n"; |
|
231 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
229 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
230 | + $retour.="{$responseElement}.empty();\n"; |
|
231 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | protected function setAjaxDataCall($params) { |
235 | - $result = null; |
|
236 | - if (! \is_callable($params)) { |
|
237 | - $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
235 | + $result=null; |
|
236 | + if (!\is_callable($params)) { |
|
237 | + $result=function($responseElement, $jqueryDone='html') use ($params) { |
|
238 | 238 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
239 | 239 | }; |
240 | 240 | } |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | |
244 | 244 | protected function setDefaultParameters(&$parameters, $default) { |
245 | 245 | foreach ($default as $k => $v) { |
246 | - if (! isset($parameters[$k])) |
|
247 | - $parameters[$k] = $v; |
|
246 | + if (!isset($parameters[$k])) |
|
247 | + $parameters[$k]=$v; |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | 251 | public function setAjaxLoader($loader) { |
252 | - $this->ajaxLoader = $loader; |
|
252 | + $this->ajaxLoader=$loader; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param string $responseElement |
261 | 261 | * selector of the HTML element displaying the answer |
262 | 262 | */ |
263 | - private function _get($url, $responseElement = '', $parameters = []) { |
|
263 | + private function _get($url, $responseElement='', $parameters=[]) { |
|
264 | 264 | return $this->_ajax('get', $url, $responseElement, $parameters); |
265 | 265 | } |
266 | 266 | |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | * @param array $parameters |
275 | 275 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
276 | 276 | */ |
277 | - public function get($url, $responseElement = '', $parameters = []) { |
|
278 | - $parameters['immediatly'] = true; |
|
277 | + public function get($url, $responseElement='', $parameters=[]) { |
|
278 | + $parameters['immediatly']=true; |
|
279 | 279 | return $this->_get($url, $responseElement, $parameters); |
280 | 280 | } |
281 | 281 | |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * @param array $parameters |
292 | 292 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
293 | 293 | */ |
294 | - public function ajax($method, $url, $responseElement = '', $parameters = []) { |
|
295 | - $parameters['immediatly'] = true; |
|
294 | + public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
295 | + $parameters['immediatly']=true; |
|
296 | 296 | return $this->_ajax($method, $url, $responseElement, $parameters); |
297 | 297 | } |
298 | 298 | |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * $immediatly |
315 | 315 | * @return string |
316 | 316 | */ |
317 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) { |
|
317 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
|
318 | 318 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
319 | 319 | } |
320 | 320 | |
@@ -330,8 +330,8 @@ discard block |
||
330 | 330 | * @param array $parameters |
331 | 331 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
332 | 332 | */ |
333 | - public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) { |
|
334 | - $parameters['immediatly'] = false; |
|
333 | + public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
334 | + $parameters['immediatly']=false; |
|
335 | 335 | return $this->_ajax($method, $url, $responseElement, $parameters); |
336 | 336 | } |
337 | 337 | |
@@ -345,15 +345,15 @@ discard block |
||
345 | 345 | * @param array $parameters |
346 | 346 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
347 | 347 | */ |
348 | - private function _json($url, $method = "get", $parameters = []) { |
|
349 | - $parameters = \array_merge($parameters, [ |
|
348 | + private function _json($url, $method="get", $parameters=[]) { |
|
349 | + $parameters=\array_merge($parameters, [ |
|
350 | 350 | "hasLoader" => false |
351 | 351 | ]); |
352 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
353 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
354 | - $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"; |
|
355 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
356 | - $parameters["jsCallback"] = $retour; |
|
352 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
353 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
354 | + $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"; |
|
355 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
356 | + $parameters["jsCallback"]=$retour; |
|
357 | 357 | return $this->_ajax($method, $url, null, $parameters); |
358 | 358 | } |
359 | 359 | |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * @param array $parameters |
368 | 368 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
369 | 369 | */ |
370 | - public function json($url, $method = "get", $parameters = []) { |
|
370 | + public function json($url, $method="get", $parameters=[]) { |
|
371 | 371 | return $this->_json($url, $method, $parameters); |
372 | 372 | } |
373 | 373 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param array $parameters |
384 | 384 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
385 | 385 | */ |
386 | - public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) { |
|
386 | + public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
|
387 | 387 | $this->setDefaultParameters($parameters, [ |
388 | 388 | 'preventDefault' => true, |
389 | 389 | 'stopPropagation' => true, |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | * @param array $parameters |
404 | 404 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
405 | 405 | */ |
406 | - public function jsonDeferred($url, $method = 'get', $parameters = []) { |
|
407 | - $parameters['immediatly'] = false; |
|
406 | + public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
407 | + $parameters['immediatly']=false; |
|
408 | 408 | return $this->_json($url, $method, $parameters); |
409 | 409 | } |
410 | 410 | |
@@ -419,29 +419,29 @@ discard block |
||
419 | 419 | * @param array $parameters |
420 | 420 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
421 | 421 | */ |
422 | - private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
423 | - $parameters = \array_merge($parameters, [ |
|
422 | + private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
423 | + $parameters=\array_merge($parameters, [ |
|
424 | 424 | "hasLoader" => false |
425 | 425 | ]); |
426 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
427 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
428 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
429 | - if ($context === null) { |
|
430 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
431 | - $newElm = "$('#'+newId)"; |
|
426 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
427 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
428 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
429 | + if ($context===null) { |
|
430 | + $parent="$('".$maskSelector."').parent()"; |
|
431 | + $newElm="$('#'+newId)"; |
|
432 | 432 | } else { |
433 | - $parent = $context; |
|
434 | - $newElm = $context . ".find('#'+newId)"; |
|
433 | + $parent=$context; |
|
434 | + $newElm=$context.".find('#'+newId)"; |
|
435 | 435 | } |
436 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
437 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
438 | - $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(); |
|
436 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
437 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
438 | + $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(); |
|
439 | 439 | 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"; |
440 | - $retour .= $appendTo; |
|
441 | - $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"; |
|
442 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
443 | - $retour .= "\t" . $jsCallback; |
|
444 | - $parameters["jsCallback"] = $retour; |
|
440 | + $retour.=$appendTo; |
|
441 | + $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"; |
|
442 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
443 | + $retour.="\t".$jsCallback; |
|
444 | + $parameters["jsCallback"]=$retour; |
|
445 | 445 | return $this->_ajax($method, $url, null, $parameters); |
446 | 446 | } |
447 | 447 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * @param array $parameters |
457 | 457 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
458 | 458 | */ |
459 | - public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
459 | + public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
460 | 460 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
461 | 461 | } |
462 | 462 | |
@@ -471,8 +471,8 @@ discard block |
||
471 | 471 | * @param array $parameters |
472 | 472 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
473 | 473 | */ |
474 | - public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) { |
|
475 | - $parameters['immediatly'] = false; |
|
474 | + public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
475 | + $parameters['immediatly']=false; |
|
476 | 476 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
477 | 477 | } |
478 | 478 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | * @param array $parameters |
489 | 489 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
490 | 490 | */ |
491 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) { |
|
491 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
|
492 | 492 | $this->setDefaultParameters($parameters, [ |
493 | 493 | 'preventDefault' => true, |
494 | 494 | 'stopPropagation' => true, |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | * @param array $parameters |
510 | 510 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
511 | 511 | */ |
512 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
513 | - $parameters['immediatly'] = false; |
|
512 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
513 | + $parameters['immediatly']=false; |
|
514 | 514 | return $this->_get($url, $responseElement, $parameters); |
515 | 515 | } |
516 | 516 | |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | * @param array $parameters |
530 | 530 | * 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,"listenerOn"=>false) |
531 | 531 | */ |
532 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
533 | - $parameters['method'] = 'get'; |
|
532 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
533 | + $parameters['method']='get'; |
|
534 | 534 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
535 | 535 | } |
536 | 536 | |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @param array $parameters |
550 | 550 | * 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,"listenerOn"=>false) |
551 | 551 | */ |
552 | - public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) { |
|
552 | + public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
|
553 | 553 | $this->setDefaultParameters($parameters, [ |
554 | 554 | 'preventDefault' => true, |
555 | 555 | 'stopPropagation' => true, |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @param array $parameters |
574 | 574 | * 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,"listenerOn"=>false) |
575 | 575 | */ |
576 | - public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
576 | + public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
577 | 577 | return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
578 | 578 | } |
579 | 579 | |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * @param array $parameters |
591 | 591 | * 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,"listenerOn"=>false) |
592 | 592 | */ |
593 | - public function getOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
593 | + public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
594 | 594 | return $this->getOn('click', $element, $url, $responseElement, $parameters); |
595 | 595 | } |
596 | 596 | |
@@ -605,15 +605,15 @@ discard block |
||
605 | 605 | * 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) |
606 | 606 | * @return $this |
607 | 607 | */ |
608 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
609 | - $parameters['attr'] = 'href'; |
|
608 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
609 | + $parameters['attr']='href'; |
|
610 | 610 | if (JString::isNull($responseElement)) { |
611 | - $responseElement = '%$(self).attr("data-target")%'; |
|
611 | + $responseElement='%$(self).attr("data-target")%'; |
|
612 | 612 | } else { |
613 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
613 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
614 | 614 | } |
615 | - if (! isset($parameters['historize'])) { |
|
616 | - $parameters['historize'] = true; |
|
615 | + if (!isset($parameters['historize'])) { |
|
616 | + $parameters['historize']=true; |
|
617 | 617 | } |
618 | 618 | return $this->getOnClick($element, "", $responseElement, $parameters); |
619 | 619 | } |
@@ -629,21 +629,21 @@ discard block |
||
629 | 629 | * 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) |
630 | 630 | * @return $this |
631 | 631 | */ |
632 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
633 | - $parameters['attr'] = 'href'; |
|
632 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
633 | + $parameters['attr']='href'; |
|
634 | 634 | if (JString::isNull($responseElement)) { |
635 | - $responseElement = '%$(this).attr("data-target")%'; |
|
635 | + $responseElement='%$(this).attr("data-target")%'; |
|
636 | 636 | } else { |
637 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
637 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
638 | 638 | } |
639 | - if (! isset($parameters['historize'])) { |
|
640 | - $parameters['historize'] = true; |
|
639 | + if (!isset($parameters['historize'])) { |
|
640 | + $parameters['historize']=true; |
|
641 | 641 | } |
642 | 642 | return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
643 | 643 | } |
644 | 644 | |
645 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
|
646 | - $parameters['params'] = $params; |
|
645 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
646 | + $parameters['params']=$params; |
|
647 | 647 | return $this->_ajax('POST', $url, $responseElement, $parameters); |
648 | 648 | } |
649 | 649 | |
@@ -659,8 +659,8 @@ discard block |
||
659 | 659 | * @param array $parameters |
660 | 660 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
661 | 661 | */ |
662 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
663 | - $parameters['immediatly'] = true; |
|
662 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
663 | + $parameters['immediatly']=true; |
|
664 | 664 | return $this->_post($url, $params, $responseElement, $parameters); |
665 | 665 | } |
666 | 666 | |
@@ -677,8 +677,8 @@ discard block |
||
677 | 677 | * @param array $parameters |
678 | 678 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
679 | 679 | */ |
680 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
681 | - $parameters['immediatly'] = false; |
|
680 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
681 | + $parameters['immediatly']=false; |
|
682 | 682 | return $this->_post($url, $params, $responseElement, $parameters); |
683 | 683 | } |
684 | 684 | |
@@ -697,9 +697,9 @@ discard block |
||
697 | 697 | * @param array $parameters |
698 | 698 | * 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,"listenerOn"=>false) |
699 | 699 | */ |
700 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
701 | - $parameters['method'] = 'post'; |
|
702 | - $parameters['params'] = $params; |
|
700 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
701 | + $parameters['method']='post'; |
|
702 | + $parameters['params']=$params; |
|
703 | 703 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
704 | 704 | } |
705 | 705 | |
@@ -717,66 +717,66 @@ discard block |
||
717 | 717 | * @param array $parameters |
718 | 718 | * 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,"listenerOn"=>false) |
719 | 719 | */ |
720 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
720 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
721 | 721 | return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
722 | 722 | } |
723 | 723 | |
724 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
724 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
725 | 725 | if (isset($this->params['ajax'])) { |
726 | 726 | extract($this->params['ajax']); |
727 | 727 | } |
728 | - $params = '{}'; |
|
729 | - $validation = false; |
|
728 | + $params='{}'; |
|
729 | + $validation=false; |
|
730 | 730 | \extract($parameters); |
731 | - $async = ($async) ? 'true' : 'false'; |
|
732 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
733 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
734 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
735 | - if (! isset($contentType) || $contentType != 'false') { |
|
736 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
731 | + $async=($async) ? 'true' : 'false'; |
|
732 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
733 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
734 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
735 | + if (!isset($contentType) || $contentType!='false') { |
|
736 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
737 | 737 | if (isset($params)) { |
738 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
738 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
739 | 739 | } |
740 | 740 | } else { |
741 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
741 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
742 | 742 | } |
743 | - $responseElement = $this->_getResponseElement($responseElement); |
|
744 | - $retour .= "var self=this;\n"; |
|
745 | - $before = isset($before) ? $before : ""; |
|
746 | - $retour .= $before; |
|
747 | - if ($hasLoader === true) { |
|
743 | + $responseElement=$this->_getResponseElement($responseElement); |
|
744 | + $retour.="var self=this;\n"; |
|
745 | + $before=isset($before) ? $before : ""; |
|
746 | + $retour.=$before; |
|
747 | + if ($hasLoader===true) { |
|
748 | 748 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
749 | - } elseif ($hasLoader === 'response') { |
|
749 | + } elseif ($hasLoader==='response') { |
|
750 | 750 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
751 | - } elseif ($hasLoader === 'internal') { |
|
752 | - $retour .= "\n$(this).addClass('loading');"; |
|
751 | + } elseif ($hasLoader==='internal') { |
|
752 | + $retour.="\n$(this).addClass('loading');"; |
|
753 | 753 | } |
754 | - $ajaxParameters = [ |
|
754 | + $ajaxParameters=[ |
|
755 | 755 | "url" => "url", |
756 | 756 | "method" => "'POST'", |
757 | 757 | "data" => "params", |
758 | 758 | "async" => $async |
759 | 759 | ]; |
760 | 760 | if (isset($headers)) { |
761 | - $ajaxParameters["headers"] = $headers; |
|
761 | + $ajaxParameters["headers"]=$headers; |
|
762 | 762 | } |
763 | 763 | if (isset($partial)) { |
764 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
765 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
764 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
765 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
766 | 766 | } |
767 | 767 | $this->createAjaxParameters($ajaxParameters, $parameters); |
768 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
769 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n"; |
|
768 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
769 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
770 | 770 | |
771 | 771 | if ($validation) { |
772 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
773 | - " . $retour . " |
|
772 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
773 | + " . $retour." |
|
774 | 774 | }});\n"; |
775 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
775 | + $retour.="$('#".$form."').submit();\n"; |
|
776 | 776 | } |
777 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
777 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
778 | 778 | if ($immediatly) |
779 | - $this->jquery_code_for_compile[] = $retour; |
|
779 | + $this->jquery_code_for_compile[]=$retour; |
|
780 | 780 | return $retour; |
781 | 781 | } |
782 | 782 | |
@@ -792,8 +792,8 @@ discard block |
||
792 | 792 | * @param array $parameters |
793 | 793 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
794 | 794 | */ |
795 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
796 | - $parameters['immediatly'] = true; |
|
795 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
796 | + $parameters['immediatly']=true; |
|
797 | 797 | return $this->_postForm($url, $form, $responseElement, $parameters); |
798 | 798 | } |
799 | 799 | |
@@ -810,8 +810,8 @@ discard block |
||
810 | 810 | * @param array $parameters |
811 | 811 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
812 | 812 | */ |
813 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
814 | - $parameters['immediatly'] = false; |
|
813 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
814 | + $parameters['immediatly']=false; |
|
815 | 815 | return $this->_postForm($url, $form, $responseElement, $parameters); |
816 | 816 | } |
817 | 817 | |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | * @param array $parameters |
829 | 829 | * 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,"listenerOn"=>false) |
830 | 830 | */ |
831 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
831 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
832 | 832 | $this->setDefaultParameters($parameters, [ |
833 | 833 | 'preventDefault' => true, |
834 | 834 | 'stopPropagation' => true, |
@@ -850,11 +850,11 @@ discard block |
||
850 | 850 | * @param array $parameters |
851 | 851 | * 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,"listenerOn"=>false) |
852 | 852 | */ |
853 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
853 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
854 | 854 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
855 | 855 | } |
856 | 856 | |
857 | - public function addCsrf($name = 'csrf-token') { |
|
857 | + public function addCsrf($name='csrf-token') { |
|
858 | 858 | return " |
859 | 859 | $.ajaxSetup({ |
860 | 860 | beforeSend: function(xhr, settings) { |