@@ -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,"listenerOn"=>false) |
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,15 +629,15 @@ 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,"listenerOn"=>false) |
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 | } |
@@ -655,26 +655,26 @@ discard block |
||
655 | 655 | * 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,"listenerOn"=>false) |
656 | 656 | * @return $this |
657 | 657 | */ |
658 | - public function postFormAction($element, $formId = "", $responseElement = "", $parameters = array()) { |
|
659 | - $parameters['attr'] = 'action'; |
|
658 | + public function postFormAction($element, $formId="", $responseElement="", $parameters=array()) { |
|
659 | + $parameters['attr']='action'; |
|
660 | 660 | if (JString::isNull($responseElement)) { |
661 | - $responseElement = '%$(self).closest("form").attr("data-target")%'; |
|
661 | + $responseElement='%$(self).closest("form").attr("data-target")%'; |
|
662 | 662 | } else { |
663 | - $responseElement = '%$(self).closest("form").attr("data-target") || "' . $responseElement . '"%'; |
|
663 | + $responseElement='%$(self).closest("form").attr("data-target") || "'.$responseElement.'"%'; |
|
664 | 664 | } |
665 | 665 | if (JString::isNull($formId)) { |
666 | - $formId = '%$(self).closest("form").attr("id")%'; |
|
666 | + $formId='%$(self).closest("form").attr("id")%'; |
|
667 | 667 | } else { |
668 | - $formId = '%$(self).closest("form").attr("id") || "' . $formId . '"%'; |
|
668 | + $formId='%$(self).closest("form").attr("id") || "'.$formId.'"%'; |
|
669 | 669 | } |
670 | - if (! isset($parameters['historize'])) { |
|
671 | - $parameters['historize'] = true; |
|
670 | + if (!isset($parameters['historize'])) { |
|
671 | + $parameters['historize']=true; |
|
672 | 672 | } |
673 | 673 | return $this->postFormOnClick($element, '', $formId, $responseElement, $parameters); |
674 | 674 | } |
675 | 675 | |
676 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
|
677 | - $parameters['params'] = $params; |
|
676 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
677 | + $parameters['params']=$params; |
|
678 | 678 | return $this->_ajax('POST', $url, $responseElement, $parameters); |
679 | 679 | } |
680 | 680 | |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @param array $parameters |
691 | 691 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
692 | 692 | */ |
693 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
694 | - $parameters['immediatly'] = true; |
|
693 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
694 | + $parameters['immediatly']=true; |
|
695 | 695 | return $this->_post($url, $params, $responseElement, $parameters); |
696 | 696 | } |
697 | 697 | |
@@ -708,8 +708,8 @@ discard block |
||
708 | 708 | * @param array $parameters |
709 | 709 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
710 | 710 | */ |
711 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
712 | - $parameters['immediatly'] = false; |
|
711 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
712 | + $parameters['immediatly']=false; |
|
713 | 713 | return $this->_post($url, $params, $responseElement, $parameters); |
714 | 714 | } |
715 | 715 | |
@@ -728,9 +728,9 @@ discard block |
||
728 | 728 | * @param array $parameters |
729 | 729 | * 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) |
730 | 730 | */ |
731 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
732 | - $parameters['method'] = 'post'; |
|
733 | - $parameters['params'] = $params; |
|
731 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
732 | + $parameters['method']='post'; |
|
733 | + $parameters['params']=$params; |
|
734 | 734 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
735 | 735 | } |
736 | 736 | |
@@ -748,66 +748,66 @@ discard block |
||
748 | 748 | * @param array $parameters |
749 | 749 | * 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) |
750 | 750 | */ |
751 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
751 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
752 | 752 | return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
753 | 753 | } |
754 | 754 | |
755 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
755 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
756 | 756 | if (isset($this->params['ajax'])) { |
757 | 757 | extract($this->params['ajax']); |
758 | 758 | } |
759 | - $params = '{}'; |
|
760 | - $validation = false; |
|
759 | + $params='{}'; |
|
760 | + $validation=false; |
|
761 | 761 | \extract($parameters); |
762 | - $async = ($async) ? 'true' : 'false'; |
|
763 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
764 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
765 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
766 | - if (! isset($contentType) || $contentType != 'false') { |
|
767 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
762 | + $async=($async) ? 'true' : 'false'; |
|
763 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
764 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
765 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
766 | + if (!isset($contentType) || $contentType!='false') { |
|
767 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
768 | 768 | if (isset($params)) { |
769 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
769 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
770 | 770 | } |
771 | 771 | } else { |
772 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
772 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
773 | 773 | } |
774 | - $responseElement = $this->_getResponseElement($responseElement); |
|
775 | - $retour .= "var self=this;\n"; |
|
776 | - $before = isset($before) ? $before : ""; |
|
777 | - $retour .= $before; |
|
778 | - if ($hasLoader === true) { |
|
774 | + $responseElement=$this->_getResponseElement($responseElement); |
|
775 | + $retour.="var self=this;\n"; |
|
776 | + $before=isset($before) ? $before : ""; |
|
777 | + $retour.=$before; |
|
778 | + if ($hasLoader===true) { |
|
779 | 779 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
780 | - } elseif ($hasLoader === 'response') { |
|
780 | + } elseif ($hasLoader==='response') { |
|
781 | 781 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
782 | - } elseif ($hasLoader === 'internal') { |
|
783 | - $retour .= "\n$(this).addClass('loading');"; |
|
782 | + } elseif ($hasLoader==='internal') { |
|
783 | + $retour.="\n$(this).addClass('loading');"; |
|
784 | 784 | } |
785 | - $ajaxParameters = [ |
|
785 | + $ajaxParameters=[ |
|
786 | 786 | "url" => "url", |
787 | 787 | "method" => "'POST'", |
788 | 788 | "data" => "params", |
789 | 789 | "async" => $async |
790 | 790 | ]; |
791 | 791 | if (isset($headers)) { |
792 | - $ajaxParameters["headers"] = $headers; |
|
792 | + $ajaxParameters["headers"]=$headers; |
|
793 | 793 | } |
794 | 794 | if (isset($partial)) { |
795 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
796 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
795 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
796 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
797 | 797 | } |
798 | 798 | $this->createAjaxParameters($ajaxParameters, $parameters); |
799 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
800 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n"; |
|
799 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
800 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
801 | 801 | |
802 | 802 | if ($validation) { |
803 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
804 | - " . $retour . " |
|
803 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
804 | + " . $retour." |
|
805 | 805 | }});\n"; |
806 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
806 | + $retour.="$('#".$form."').submit();\n"; |
|
807 | 807 | } |
808 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
808 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
809 | 809 | if ($immediatly) |
810 | - $this->jquery_code_for_compile[] = $retour; |
|
810 | + $this->jquery_code_for_compile[]=$retour; |
|
811 | 811 | return $retour; |
812 | 812 | } |
813 | 813 | |
@@ -823,8 +823,8 @@ discard block |
||
823 | 823 | * @param array $parameters |
824 | 824 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
825 | 825 | */ |
826 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
827 | - $parameters['immediatly'] = true; |
|
826 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
827 | + $parameters['immediatly']=true; |
|
828 | 828 | return $this->_postForm($url, $form, $responseElement, $parameters); |
829 | 829 | } |
830 | 830 | |
@@ -841,8 +841,8 @@ discard block |
||
841 | 841 | * @param array $parameters |
842 | 842 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
843 | 843 | */ |
844 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
845 | - $parameters['immediatly'] = false; |
|
844 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
845 | + $parameters['immediatly']=false; |
|
846 | 846 | return $this->_postForm($url, $form, $responseElement, $parameters); |
847 | 847 | } |
848 | 848 | |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | * @param array $parameters |
860 | 860 | * 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) |
861 | 861 | */ |
862 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
862 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
863 | 863 | $this->setDefaultParameters($parameters, [ |
864 | 864 | 'preventDefault' => true, |
865 | 865 | 'stopPropagation' => true, |
@@ -881,11 +881,11 @@ discard block |
||
881 | 881 | * @param array $parameters |
882 | 882 | * 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) |
883 | 883 | */ |
884 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
884 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
885 | 885 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
886 | 886 | } |
887 | 887 | |
888 | - public function addCsrf($name = 'csrf-token') { |
|
888 | + public function addCsrf($name='csrf-token') { |
|
889 | 889 | return " |
890 | 890 | $.ajaxSetup({ |
891 | 891 | beforeSend: function(xhr, settings) { |
@@ -14,44 +14,44 @@ discard block |
||
14 | 14 | */ |
15 | 15 | abstract class HtmlCollection extends HtmlDoubleElement { |
16 | 16 | |
17 | - public function __construct($identifier,$tagName="div"){ |
|
18 | - parent::__construct($identifier,$tagName); |
|
17 | + public function __construct($identifier, $tagName="div") { |
|
18 | + parent::__construct($identifier, $tagName); |
|
19 | 19 | $this->content=array(); |
20 | 20 | } |
21 | 21 | |
22 | - public function addItems($items){ |
|
23 | - if(JArray::isAssociative($items)){ |
|
24 | - foreach ($items as $k=>$v){ |
|
25 | - $this->addItem([$k,$v]); |
|
22 | + public function addItems($items) { |
|
23 | + if (JArray::isAssociative($items)) { |
|
24 | + foreach ($items as $k=>$v) { |
|
25 | + $this->addItem([$k, $v]); |
|
26 | 26 | } |
27 | - }else{ |
|
28 | - foreach ($items as $item){ |
|
27 | + } else { |
|
28 | + foreach ($items as $item) { |
|
29 | 29 | $this->addItem($item); |
30 | 30 | } |
31 | 31 | } |
32 | 32 | return $this; |
33 | 33 | } |
34 | 34 | |
35 | - public function setItems($items){ |
|
35 | + public function setItems($items) { |
|
36 | 36 | $this->content=$items; |
37 | 37 | return $this; |
38 | 38 | } |
39 | 39 | |
40 | - public function getItems(){ |
|
40 | + public function getItems() { |
|
41 | 41 | return $this->content; |
42 | 42 | } |
43 | 43 | |
44 | - protected function getItemToAdd($item){ |
|
44 | + protected function getItemToAdd($item) { |
|
45 | 45 | $itemO=$item; |
46 | - if($this->createCondition($item)===true){ |
|
46 | + if ($this->createCondition($item)===true) { |
|
47 | 47 | $itemO=$this->createItem($item); |
48 | 48 | } |
49 | 49 | return $itemO; |
50 | 50 | } |
51 | 51 | |
52 | - protected function setItemIdentifier($item,$classname,$index){ |
|
53 | - if($item instanceof BaseWidget){ |
|
54 | - if(JString::isNull($item->getIdentifier())){ |
|
52 | + protected function setItemIdentifier($item, $classname, $index) { |
|
53 | + if ($item instanceof BaseWidget) { |
|
54 | + if (JString::isNull($item->getIdentifier())) { |
|
55 | 55 | $item->setIdentifier($classname."-".$this->identifier."-".$index); |
56 | 56 | } |
57 | 57 | } |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | * @param HtmlDoubleElement|string|array $item |
63 | 63 | * @return \Ajax\common\html\HtmlDoubleElement |
64 | 64 | */ |
65 | - public function addItem($item){ |
|
65 | + public function addItem($item) { |
|
66 | 66 | $itemO=$this->getItemToAdd($item); |
67 | 67 | $this->addContent($itemO); |
68 | 68 | return $itemO; |
69 | 69 | } |
70 | 70 | |
71 | - public function insertItem($item,$position=0){ |
|
71 | + public function insertItem($item, $position=0) { |
|
72 | 72 | $itemO=$this->getItemToAdd($item); |
73 | - \array_splice( $this->content, $position, 0, array($itemO)); |
|
73 | + \array_splice($this->content, $position, 0, array($itemO)); |
|
74 | 74 | return $itemO; |
75 | 75 | } |
76 | 76 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return \Ajax\common\html\HtmlDoubleElement |
81 | 81 | */ |
82 | 82 | public function getItem($index) { |
83 | - if (is_int($index)&& isset($this->content[$index])) |
|
83 | + if (is_int($index) && isset($this->content[$index])) |
|
84 | 84 | return $this->content[$index]; |
85 | 85 | else { |
86 | 86 | $elm=$this->getElementById($index, $this->content); |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | return $this; |
94 | 94 | } |
95 | 95 | |
96 | - public function removeItem($index){ |
|
96 | + public function removeItem($index) { |
|
97 | 97 | return array_splice($this->content, $index, 1); |
98 | 98 | } |
99 | 99 | |
100 | - public function count(){ |
|
100 | + public function count() { |
|
101 | 101 | return \sizeof($this->content); |
102 | 102 | } |
103 | 103 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | return $this->addItem($function($object)); |
109 | 109 | } |
110 | 110 | |
111 | - public function apply($callBack){ |
|
112 | - foreach ($this->content as $item){ |
|
111 | + public function apply($callBack) { |
|
112 | + foreach ($this->content as $item) { |
|
113 | 113 | $callBack($item); |
114 | 114 | } |
115 | 115 | return $this; |
@@ -129,23 +129,23 @@ discard block |
||
129 | 129 | */ |
130 | 130 | abstract protected function createItem($value); |
131 | 131 | |
132 | - protected function createCondition($value){ |
|
132 | + protected function createCondition($value) { |
|
133 | 133 | return !($value instanceof BaseHtml); |
134 | 134 | } |
135 | 135 | |
136 | - protected function contentAs($tagName){ |
|
137 | - foreach ($this->content as $item){ |
|
136 | + protected function contentAs($tagName) { |
|
137 | + foreach ($this->content as $item) { |
|
138 | 138 | $item->setTagName($tagName); |
139 | 139 | } |
140 | 140 | return $this; |
141 | 141 | } |
142 | 142 | |
143 | - public function setProperties($properties){ |
|
143 | + public function setProperties($properties) { |
|
144 | 144 | $i=0; |
145 | - foreach ($properties as $k=>$v){ |
|
145 | + foreach ($properties as $k=>$v) { |
|
146 | 146 | $c=$this->content[$i++]; |
147 | - if(isset($c)) |
|
148 | - $c->setProperty($k,$v); |
|
147 | + if (isset($c)) |
|
148 | + $c->setProperty($k, $v); |
|
149 | 149 | else |
150 | 150 | return $this; |
151 | 151 | } |
@@ -158,15 +158,15 @@ discard block |
||
158 | 158 | * @param array|mixed $values |
159 | 159 | * @return $this |
160 | 160 | */ |
161 | - public function setPropertyValues($property,$values){ |
|
162 | - if(\is_array($values)===false){ |
|
163 | - $values=\array_fill(0, $this->count(),$values); |
|
161 | + public function setPropertyValues($property, $values) { |
|
162 | + if (\is_array($values)===false) { |
|
163 | + $values=\array_fill(0, $this->count(), $values); |
|
164 | 164 | } |
165 | - foreach ($values as $i=>$value){ |
|
166 | - if(isset($this->content[$i])){ |
|
167 | - $this->content[$i]->setProperty($property,$value); |
|
165 | + foreach ($values as $i=>$value) { |
|
166 | + if (isset($this->content[$i])) { |
|
167 | + $this->content[$i]->setProperty($property, $value); |
|
168 | 168 | } |
169 | - else{ |
|
169 | + else { |
|
170 | 170 | return $this; |
171 | 171 | } |
172 | 172 | } |
@@ -179,15 +179,15 @@ discard block |
||
179 | 179 | * @param array|mixed $values |
180 | 180 | * @return $this |
181 | 181 | */ |
182 | - public function addPropertyValues($property,$values){ |
|
183 | - if(\is_array($values)===false){ |
|
184 | - $values=\array_fill(0, $this->count(),$values); |
|
182 | + public function addPropertyValues($property, $values) { |
|
183 | + if (\is_array($values)===false) { |
|
184 | + $values=\array_fill(0, $this->count(), $values); |
|
185 | 185 | } |
186 | - foreach ($values as $i=>$value){ |
|
187 | - if(isset($this->content[$i])){ |
|
188 | - $this->content[$i++]->addToProperty($property,$value); |
|
186 | + foreach ($values as $i=>$value) { |
|
187 | + if (isset($this->content[$i])) { |
|
188 | + $this->content[$i++]->addToProperty($property, $value); |
|
189 | 189 | } |
190 | - else{ |
|
190 | + else { |
|
191 | 191 | return $this; |
192 | 192 | } |
193 | 193 | } |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
198 | 198 | $index=0; |
199 | 199 | $classname=\strtolower(JReflection::shortClassName($this)); |
200 | - foreach ($this->content as $item){ |
|
201 | - $this->setItemIdentifier($item,$classname,$index++); |
|
200 | + foreach ($this->content as $item) { |
|
201 | + $this->setItemIdentifier($item, $classname, $index++); |
|
202 | 202 | } |
203 | - return parent::compile($js,$view); |
|
203 | + return parent::compile($js, $view); |
|
204 | 204 | } |
205 | 205 | |
206 | - public function getItemById($identifier){ |
|
206 | + public function getItemById($identifier) { |
|
207 | 207 | return $this->getElementById($identifier, $this->content); |
208 | 208 | } |
209 | 209 | |
@@ -212,13 +212,13 @@ discard block |
||
212 | 212 | * @param string $target |
213 | 213 | * @return HtmlCollection |
214 | 214 | */ |
215 | - public function asLinks($hrefs=[],$target=NUll) { |
|
216 | - foreach ( $this->content as $index=>$item ) { |
|
217 | - if($item instanceof HtmlDoubleElement){ |
|
215 | + public function asLinks($hrefs=[], $target=NUll) { |
|
216 | + foreach ($this->content as $index=>$item) { |
|
217 | + if ($item instanceof HtmlDoubleElement) { |
|
218 | 218 | $href=""; |
219 | - if(isset($hrefs[$index])) |
|
219 | + if (isset($hrefs[$index])) |
|
220 | 220 | $href=$hrefs[$index]; |
221 | - $item->asLink($href,$target); |
|
221 | + $item->asLink($href, $target); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | return $this; |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @param int $length If length is omitted, removes everything from offset to the end of the array. If length is specified and is positive, then that many elements will be removed. If length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. If length is specified and is zero, no elements will be removed. Tip: to remove everything from offset to the end of the array when replacement is also specified, use count($input) for length. |
231 | 231 | * @return $this |
232 | 232 | */ |
233 | - public function splice($offset,$length=null){ |
|
234 | - $this->content=array_slice($this->content, $offset,$length); |
|
233 | + public function splice($offset, $length=null) { |
|
234 | + $this->content=array_slice($this->content, $offset, $length); |
|
235 | 235 | return $this; |
236 | 236 | } |
237 | 237 | } |