@@ -15,79 +15,79 @@ 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 .= "let 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.="let 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 | } elseif (\is_string($hasLoader)) { |
48 | 48 | $this->addLoading($retour, $hasLoader, $ajaxLoader); |
49 | 49 | } |
50 | - $ajaxParameters = [ |
|
50 | + $ajaxParameters=[ |
|
51 | 51 | "url" => "url", |
52 | - "method" => "'" . \strtoupper($method) . "'" |
|
52 | + "method" => "'".\strtoupper($method)."'" |
|
53 | 53 | ]; |
54 | 54 | |
55 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
55 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
56 | 56 | |
57 | 57 | if (isset($params)) { |
58 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
58 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
59 | 59 | } |
60 | 60 | if (isset($headers)) { |
61 | - $ajaxParameters["headers"] = $headers; |
|
61 | + $ajaxParameters["headers"]=$headers; |
|
62 | 62 | } |
63 | 63 | if ($csrf) { |
64 | - $csrf = (is_string($csrf)) ? $csrf : 'csrf-token'; |
|
65 | - $parameters["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
64 | + $csrf=(is_string($csrf)) ? $csrf : 'csrf-token'; |
|
65 | + $parameters["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
66 | 66 | } |
67 | 67 | if (isset($partial)) { |
68 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
69 | - $retour .= "let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
68 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
69 | + $retour.="let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
70 | 70 | } elseif (isset($upload)) { |
71 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
72 | - $retour .= 'let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.upload.addEventListener("progress", function(event) {if (event.lengthComputable) {' . $upload . '}}, false);'; |
|
71 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
72 | + $retour.='let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.upload.addEventListener("progress", function(event) {if (event.lengthComputable) {'.$upload.'}}, false);'; |
|
73 | 73 | } |
74 | 74 | $this->createAjaxParameters($ajaxParameters, $parameters); |
75 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
76 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, ($historize ? $originalSelector : null)) . "})"; |
|
75 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
76 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, ($historize ? $originalSelector : null))."})"; |
|
77 | 77 | if (isset($error)) { |
78 | - $retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})'; |
|
78 | + $retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})'; |
|
79 | 79 | } |
80 | - $retour .= '.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {' . ($always ?? '') . $this->removeLoader($hasLoader) . '})'; |
|
81 | - $retour .= ";\n"; |
|
82 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
80 | + $retour.='.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {'.($always ?? '').$this->removeLoader($hasLoader).'})'; |
|
81 | + $retour.=";\n"; |
|
82 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
83 | 83 | if ($immediatly) { |
84 | - $this->jquery_code_for_compile[] = $retour; |
|
84 | + $this->jquery_code_for_compile[]=$retour; |
|
85 | 85 | } |
86 | 86 | return $retour; |
87 | 87 | } |
88 | 88 | |
89 | 89 | protected function createAjaxParameters(&$original, $parameters) { |
90 | - $validParameters = [ |
|
90 | + $validParameters=[ |
|
91 | 91 | "contentType" => "%value%", |
92 | 92 | "dataType" => "'%value%'", |
93 | 93 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -96,21 +96,21 @@ discard block |
||
96 | 96 | ]; |
97 | 97 | foreach ($validParameters as $param => $mask) { |
98 | 98 | if (isset($parameters[$param])) { |
99 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
99 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | 104 | protected function implodeAjaxParameters($ajaxParameters) { |
105 | - $s = ''; |
|
105 | + $s=''; |
|
106 | 106 | foreach ($ajaxParameters as $k => $v) { |
107 | - if ($s !== '') { |
|
108 | - $s .= ','; |
|
107 | + if ($s!=='') { |
|
108 | + $s.=','; |
|
109 | 109 | } |
110 | 110 | if (is_array($v)) { |
111 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
111 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
112 | 112 | } else { |
113 | - $s .= "'{$k}':{$v}"; |
|
113 | + $s.="'{$k}':{$v}"; |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | return $s; |
@@ -118,29 +118,29 @@ discard block |
||
118 | 118 | |
119 | 119 | protected function _addJsCondition($jsCondition, $jsSource) { |
120 | 120 | if (isset($jsCondition)) { |
121 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
121 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
122 | 122 | } |
123 | 123 | return $jsSource; |
124 | 124 | } |
125 | 125 | |
126 | 126 | protected function _getAjaxUrl($url, $attr) { |
127 | - $url = $this->_correctAjaxUrl($url); |
|
128 | - $retour = "let url='" . $url . "';"; |
|
129 | - $slash = "/"; |
|
130 | - if (JString::endswith($url, "/") === true) { |
|
131 | - $slash = ""; |
|
127 | + $url=$this->_correctAjaxUrl($url); |
|
128 | + $retour="let url='".$url."';"; |
|
129 | + $slash="/"; |
|
130 | + if (JString::endswith($url, "/")===true) { |
|
131 | + $slash=""; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | if (JString::isNotNull($attr)) { |
135 | - if ($attr === "value") { |
|
136 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
137 | - } elseif ($attr === "html") { |
|
138 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
139 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
140 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
141 | - } elseif ($attr !== null && $attr !== "") { |
|
142 | - $retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';"; |
|
143 | - $retour .= "url=!(new RegExp('^((http|https|ftp):\/\/)')).test(elmUrl)?url+'" . $slash . "'+elmUrl:elmUrl;\n"; |
|
135 | + if ($attr==="value") { |
|
136 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
137 | + } elseif ($attr==="html") { |
|
138 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
139 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
140 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
141 | + } elseif ($attr!==null && $attr!=="") { |
|
142 | + $retour.="let elmUrl=$(this).attr('".$attr."')||'';"; |
|
143 | + $retour.="url=!(new RegExp('^((http|https|ftp):\/\/)')).test(elmUrl)?url+'".$slash."'+elmUrl:elmUrl;\n"; |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | return $retour; |
@@ -150,44 +150,44 @@ discard block |
||
150 | 150 | return "window.onpopstate = function(e){if(e.state){let target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
151 | 151 | } |
152 | 152 | |
153 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
154 | - $result = "\nif (typeof getHref !== 'function'){function getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}}"; |
|
155 | - $result .= "\nlet myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
153 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
154 | + $result="\nif (typeof getHref !== 'function'){function getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}}"; |
|
155 | + $result.="\nlet myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
156 | 156 | return $result; |
157 | 157 | } |
158 | 158 | |
159 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history = null) { |
|
160 | - $retour = ""; |
|
161 | - $call = null; |
|
159 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history=null) { |
|
160 | + $retour=""; |
|
161 | + $call=null; |
|
162 | 162 | if (JString::isNotNull($responseElement)) { |
163 | 163 | if (isset($ajaxTransition)) { |
164 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
164 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
165 | 165 | } elseif (isset($this->ajaxTransition)) { |
166 | - $call = $this->ajaxTransition; |
|
166 | + $call=$this->ajaxTransition; |
|
167 | 167 | } |
168 | 168 | if (\is_callable($call)) |
169 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
169 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
170 | 170 | else |
171 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
171 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
172 | 172 | } |
173 | 173 | if (isset($history)) { |
174 | 174 | if ($this->params["autoActiveLinks"]) { |
175 | - $retour .= $this->autoActiveLinks("url"); |
|
175 | + $retour.=$this->autoActiveLinks("url"); |
|
176 | 176 | } |
177 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
177 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
178 | 178 | } |
179 | - $retour .= "\t" . $jsCallback . "\n"; |
|
179 | + $retour.="\t".$jsCallback."\n"; |
|
180 | 180 | return $retour; |
181 | 181 | } |
182 | 182 | |
183 | 183 | protected function removeLoader($hasLoader) { |
184 | - if ($hasLoader === true) { |
|
184 | + if ($hasLoader===true) { |
|
185 | 185 | return "\n$('body').find('.ajax-loader').remove();"; |
186 | 186 | } |
187 | - if ($hasLoader === 'internal') { |
|
187 | + if ($hasLoader==='internal') { |
|
188 | 188 | return "\n$(self).removeClass('loading');"; |
189 | 189 | } |
190 | - if ($hasLoader === 'internal-x') { |
|
190 | + if ($hasLoader==='internal-x') { |
|
191 | 191 | return "\n$(self).children('.ajax-loader').remove();"; |
192 | 192 | } |
193 | 193 | return "\n$('body').find('.loading').removeClass('loading');"; |
@@ -195,71 +195,71 @@ discard block |
||
195 | 195 | |
196 | 196 | protected function _getResponseElement($responseElement) { |
197 | 197 | if (JString::isNotNull($responseElement)) { |
198 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
198 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
199 | 199 | } |
200 | 200 | return $responseElement; |
201 | 201 | } |
202 | 202 | |
203 | 203 | protected function _getFormElement($formElement) { |
204 | 204 | if (JString::isNotNull($formElement)) { |
205 | - $formElement = Javascript::prep_value($formElement); |
|
205 | + $formElement=Javascript::prep_value($formElement); |
|
206 | 206 | } |
207 | 207 | return $formElement; |
208 | 208 | } |
209 | 209 | |
210 | 210 | protected function _correctAjaxUrl($url) { |
211 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
212 | - $url = substr($url, 0, strlen($url) - 1); |
|
213 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
214 | - $url = $this->getUrl($url); |
|
211 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
212 | + $url=substr($url, 0, strlen($url)-1); |
|
213 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
214 | + $url=$this->getUrl($url); |
|
215 | 215 | } |
216 | 216 | return $url; |
217 | 217 | } |
218 | 218 | |
219 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
219 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
220 | 220 | if (JString::isNull($params)) { |
221 | 221 | return ""; |
222 | 222 | } |
223 | 223 | if (\preg_match("@^\{.*?\}$@", $params)) { |
224 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
225 | - return '$.param(' . $params . ')'; |
|
224 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
225 | + return '$.param('.$params.')'; |
|
226 | 226 | } else { |
227 | - return 'JSON.stringify(' . $params . ')'; |
|
227 | + return 'JSON.stringify('.$params.')'; |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | return $params; |
231 | 231 | } |
232 | 232 | |
233 | 233 | public static function _implodeParams($parameters) { |
234 | - $allParameters = []; |
|
234 | + $allParameters=[]; |
|
235 | 235 | foreach ($parameters as $params) { |
236 | 236 | if (isset($params)) |
237 | - $allParameters[] = self::_correctParams($params); |
|
237 | + $allParameters[]=self::_correctParams($params); |
|
238 | 238 | } |
239 | 239 | return \implode("+'&'+", $allParameters); |
240 | 240 | } |
241 | 241 | |
242 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
243 | - if (! isset($ajaxLoader)) { |
|
244 | - $ajaxLoader = $this->ajaxLoader; |
|
242 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
243 | + if (!isset($ajaxLoader)) { |
|
244 | + $ajaxLoader=$this->ajaxLoader; |
|
245 | 245 | } |
246 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
247 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
246 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
247 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
248 | 248 | } |
249 | 249 | |
250 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
251 | - if (! isset($ajaxLoader)) { |
|
252 | - $ajaxLoader = $this->ajaxLoader; |
|
250 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
251 | + if (!isset($ajaxLoader)) { |
|
252 | + $ajaxLoader=$this->ajaxLoader; |
|
253 | 253 | } |
254 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
255 | - $retour .= "{$responseElement}.empty();\n"; |
|
256 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
254 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
255 | + $retour.="{$responseElement}.empty();\n"; |
|
256 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | protected function setAjaxDataCall($params) { |
260 | - $result = null; |
|
261 | - if (! \is_callable($params)) { |
|
262 | - $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
260 | + $result=null; |
|
261 | + if (!\is_callable($params)) { |
|
262 | + $result=function($responseElement, $jqueryDone='html') use ($params) { |
|
263 | 263 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
264 | 264 | }; |
265 | 265 | } |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | |
269 | 269 | protected function setDefaultParameters(&$parameters, $default) { |
270 | 270 | foreach ($default as $k => $v) { |
271 | - if (! isset($parameters[$k])) |
|
272 | - $parameters[$k] = $v; |
|
271 | + if (!isset($parameters[$k])) |
|
272 | + $parameters[$k]=$v; |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | public function setAjaxLoader($loader) { |
277 | - $this->ajaxLoader = $loader; |
|
277 | + $this->ajaxLoader=$loader; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @param string $responseElement |
286 | 286 | * selector of the HTML element displaying the answer |
287 | 287 | */ |
288 | - private function _get($url, $responseElement = '', $parameters = []) { |
|
288 | + private function _get($url, $responseElement='', $parameters=[]) { |
|
289 | 289 | return $this->_ajax('get', $url, $responseElement, $parameters); |
290 | 290 | } |
291 | 291 | |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | * @param array $parameters |
300 | 300 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
301 | 301 | */ |
302 | - public function get($url, $responseElement = '', $parameters = []) { |
|
303 | - $parameters['immediatly'] = true; |
|
302 | + public function get($url, $responseElement='', $parameters=[]) { |
|
303 | + $parameters['immediatly']=true; |
|
304 | 304 | return $this->_get($url, $responseElement, $parameters); |
305 | 305 | } |
306 | 306 | |
@@ -316,8 +316,8 @@ discard block |
||
316 | 316 | * @param array $parameters |
317 | 317 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
318 | 318 | */ |
319 | - public function ajax($method, $url, $responseElement = '', $parameters = []) { |
|
320 | - $parameters['immediatly'] = true; |
|
319 | + public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
320 | + $parameters['immediatly']=true; |
|
321 | 321 | return $this->_ajax($method, $url, $responseElement, $parameters); |
322 | 322 | } |
323 | 323 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * $immediatly |
340 | 340 | * @return string |
341 | 341 | */ |
342 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) { |
|
342 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
|
343 | 343 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
344 | 344 | } |
345 | 345 | |
@@ -355,8 +355,8 @@ discard block |
||
355 | 355 | * @param array $parameters |
356 | 356 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
357 | 357 | */ |
358 | - public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) { |
|
359 | - $parameters['immediatly'] = false; |
|
358 | + public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
359 | + $parameters['immediatly']=false; |
|
360 | 360 | return $this->_ajax($method, $url, $responseElement, $parameters); |
361 | 361 | } |
362 | 362 | |
@@ -370,15 +370,15 @@ discard block |
||
370 | 370 | * @param array $parameters |
371 | 371 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
372 | 372 | */ |
373 | - private function _json($url, $method = "get", $parameters = []) { |
|
374 | - $parameters = \array_merge($parameters, [ |
|
373 | + private function _json($url, $method="get", $parameters=[]) { |
|
374 | + $parameters=\array_merge($parameters, [ |
|
375 | 375 | "hasLoader" => false |
376 | 376 | ]); |
377 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
378 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
379 | - $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"; |
|
380 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
381 | - $parameters["jsCallback"] = $retour; |
|
377 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
378 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
379 | + $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"; |
|
380 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
381 | + $parameters["jsCallback"]=$retour; |
|
382 | 382 | return $this->_ajax($method, $url, null, $parameters); |
383 | 383 | } |
384 | 384 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @param array $parameters |
393 | 393 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
394 | 394 | */ |
395 | - public function json($url, $method = "get", $parameters = []) { |
|
395 | + public function json($url, $method="get", $parameters=[]) { |
|
396 | 396 | return $this->_json($url, $method, $parameters); |
397 | 397 | } |
398 | 398 | |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * @param array $parameters |
409 | 409 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
410 | 410 | */ |
411 | - public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) { |
|
411 | + public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
|
412 | 412 | $this->setDefaultParameters($parameters, [ |
413 | 413 | 'preventDefault' => true, |
414 | 414 | 'stopPropagation' => true, |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @param array $parameters |
429 | 429 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
430 | 430 | */ |
431 | - public function jsonDeferred($url, $method = 'get', $parameters = []) { |
|
432 | - $parameters['immediatly'] = false; |
|
431 | + public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
432 | + $parameters['immediatly']=false; |
|
433 | 433 | return $this->_json($url, $method, $parameters); |
434 | 434 | } |
435 | 435 | |
@@ -444,29 +444,29 @@ discard block |
||
444 | 444 | * @param array $parameters |
445 | 445 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
446 | 446 | */ |
447 | - private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
448 | - $parameters = \array_merge($parameters, [ |
|
447 | + private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
448 | + $parameters=\array_merge($parameters, [ |
|
449 | 449 | "hasLoader" => false |
450 | 450 | ]); |
451 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
452 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
453 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
454 | - if ($context === null) { |
|
455 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
456 | - $newElm = "$('#'+newId)"; |
|
451 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
452 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
453 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
454 | + if ($context===null) { |
|
455 | + $parent="$('".$maskSelector."').parent()"; |
|
456 | + $newElm="$('#'+newId)"; |
|
457 | 457 | } else { |
458 | - $parent = $context; |
|
459 | - $newElm = $context . ".find('#'+newId)"; |
|
458 | + $parent=$context; |
|
459 | + $newElm=$context.".find('#'+newId)"; |
|
460 | 460 | } |
461 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
462 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
463 | - $retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n" . "\tlet created=false;let maskElm=$('" . $maskSelector . "').first();maskElm.hide();" . "\tlet newId=(maskElm.attr('id') || 'mask')+'-'+index;" . "\tlet newElm=" . $newElm . ";\n" . "\tif(!newElm.length){\n" . "\t\tnewElm=maskElm.clone(); |
|
461 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
462 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
463 | + $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tlet created=false;let maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tlet newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tlet newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
|
464 | 464 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ let newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
465 | - $retour .= $appendTo; |
|
466 | - $retour .= "\t}\n" . "\tfor(var key in value){\n" . "\t\t\tlet 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\tlet sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n" . "\t\t\tlet 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"; |
|
467 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
468 | - $retour .= "\t" . $jsCallback; |
|
469 | - $parameters["jsCallback"] = $retour; |
|
465 | + $retour.=$appendTo; |
|
466 | + $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tlet 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\tlet sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tlet 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"; |
|
467 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
468 | + $retour.="\t".$jsCallback; |
|
469 | + $parameters["jsCallback"]=$retour; |
|
470 | 470 | return $this->_ajax($method, $url, null, $parameters); |
471 | 471 | } |
472 | 472 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param array $parameters |
482 | 482 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
483 | 483 | */ |
484 | - public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
484 | + public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
485 | 485 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
486 | 486 | } |
487 | 487 | |
@@ -496,8 +496,8 @@ discard block |
||
496 | 496 | * @param array $parameters |
497 | 497 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
498 | 498 | */ |
499 | - public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) { |
|
500 | - $parameters['immediatly'] = false; |
|
499 | + public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
500 | + $parameters['immediatly']=false; |
|
501 | 501 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
502 | 502 | } |
503 | 503 | |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @param array $parameters |
514 | 514 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
515 | 515 | */ |
516 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) { |
|
516 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
|
517 | 517 | $this->setDefaultParameters($parameters, [ |
518 | 518 | 'preventDefault' => true, |
519 | 519 | 'stopPropagation' => true, |
@@ -534,8 +534,8 @@ discard block |
||
534 | 534 | * @param array $parameters |
535 | 535 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
536 | 536 | */ |
537 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
538 | - $parameters['immediatly'] = false; |
|
537 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
538 | + $parameters['immediatly']=false; |
|
539 | 539 | return $this->_get($url, $responseElement, $parameters); |
540 | 540 | } |
541 | 541 | |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | * @param array $parameters |
555 | 555 | * 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) |
556 | 556 | */ |
557 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
558 | - $parameters['method'] = 'get'; |
|
557 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
558 | + $parameters['method']='get'; |
|
559 | 559 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
560 | 560 | } |
561 | 561 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * @param array $parameters |
575 | 575 | * 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) |
576 | 576 | */ |
577 | - public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) { |
|
577 | + public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
|
578 | 578 | $this->setDefaultParameters($parameters, [ |
579 | 579 | 'preventDefault' => true, |
580 | 580 | 'stopPropagation' => true, |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * @param array $parameters |
599 | 599 | * 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) |
600 | 600 | */ |
601 | - public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
601 | + public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
602 | 602 | return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
603 | 603 | } |
604 | 604 | |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * @param array $parameters |
616 | 616 | * 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) |
617 | 617 | */ |
618 | - public function getOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
618 | + public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
619 | 619 | return $this->getOn('click', $element, $url, $responseElement, $parameters); |
620 | 620 | } |
621 | 621 | |
@@ -630,18 +630,18 @@ discard block |
||
630 | 630 | * 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) |
631 | 631 | * @return $this |
632 | 632 | */ |
633 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
634 | - $parameters['attr'] = 'href'; |
|
633 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
634 | + $parameters['attr']='href'; |
|
635 | 635 | if (JString::isNull($responseElement)) { |
636 | - $responseElement = '%$(self).attr("data-target")%'; |
|
636 | + $responseElement='%$(self).attr("data-target")%'; |
|
637 | 637 | } else { |
638 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
638 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
639 | 639 | } |
640 | - if (! isset($parameters['historize'])) { |
|
641 | - $parameters['historize'] = true; |
|
640 | + if (!isset($parameters['historize'])) { |
|
641 | + $parameters['historize']=true; |
|
642 | 642 | } |
643 | - if (! isset($parameters['jsCallback'])) { |
|
644 | - $parameters['jsCallback'] = 'let event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
643 | + if (!isset($parameters['jsCallback'])) { |
|
644 | + $parameters['jsCallback']='let event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
645 | 645 | } |
646 | 646 | return $this->getOnClick($element, "", $responseElement, $parameters); |
647 | 647 | } |
@@ -657,15 +657,15 @@ discard block |
||
657 | 657 | * 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) |
658 | 658 | * @return $this |
659 | 659 | */ |
660 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
661 | - $parameters['attr'] = 'href'; |
|
660 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
661 | + $parameters['attr']='href'; |
|
662 | 662 | if (JString::isNull($responseElement)) { |
663 | - $responseElement = '%$(this).attr("data-target")%'; |
|
663 | + $responseElement='%$(this).attr("data-target")%'; |
|
664 | 664 | } else { |
665 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
665 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
666 | 666 | } |
667 | - if (! isset($parameters['historize'])) { |
|
668 | - $parameters['historize'] = true; |
|
667 | + if (!isset($parameters['historize'])) { |
|
668 | + $parameters['historize']=true; |
|
669 | 669 | } |
670 | 670 | return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
671 | 671 | } |
@@ -681,29 +681,29 @@ discard block |
||
681 | 681 | * 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) |
682 | 682 | * @return $this |
683 | 683 | */ |
684 | - public function postFormAction($element, $responseElement = "", $parameters = array()) { |
|
685 | - $parameters['attr'] = 'action'; |
|
684 | + public function postFormAction($element, $responseElement="", $parameters=array()) { |
|
685 | + $parameters['attr']='action'; |
|
686 | 686 | if (JString::isNull($responseElement)) { |
687 | - $responseElement = '%$(self).attr("data-target")%'; |
|
687 | + $responseElement='%$(self).attr("data-target")%'; |
|
688 | 688 | } else { |
689 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
689 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
690 | 690 | } |
691 | - $formId = '%$(this).attr("id")%'; |
|
692 | - if (! isset($parameters['historize'])) { |
|
693 | - $parameters['historize'] = true; |
|
691 | + $formId='%$(this).attr("id")%'; |
|
692 | + if (!isset($parameters['historize'])) { |
|
693 | + $parameters['historize']=true; |
|
694 | 694 | } |
695 | - $parameters['preventDefault'] = true; |
|
696 | - if (! isset($parameters['hasLoader'])) { |
|
697 | - $parameters['hasLoader'] = '$(self).find("button, input[type=submit], input[type=button]")'; |
|
695 | + $parameters['preventDefault']=true; |
|
696 | + if (!isset($parameters['hasLoader'])) { |
|
697 | + $parameters['hasLoader']='$(self).find("button, input[type=submit], input[type=button]")'; |
|
698 | 698 | } |
699 | - if (! isset($parameters['jsCallback'])) { |
|
700 | - $parameters['jsCallback'] = 'let event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
699 | + if (!isset($parameters['jsCallback'])) { |
|
700 | + $parameters['jsCallback']='let event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
701 | 701 | } |
702 | 702 | return $this->postFormOn('submit', $element, '', $formId, $responseElement, $parameters); |
703 | 703 | } |
704 | 704 | |
705 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
|
706 | - $parameters['params'] = $params; |
|
705 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
706 | + $parameters['params']=$params; |
|
707 | 707 | return $this->_ajax('POST', $url, $responseElement, $parameters); |
708 | 708 | } |
709 | 709 | |
@@ -719,8 +719,8 @@ discard block |
||
719 | 719 | * @param array $parameters |
720 | 720 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
721 | 721 | */ |
722 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
723 | - $parameters['immediatly'] = true; |
|
722 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
723 | + $parameters['immediatly']=true; |
|
724 | 724 | return $this->_post($url, $params, $responseElement, $parameters); |
725 | 725 | } |
726 | 726 | |
@@ -737,8 +737,8 @@ discard block |
||
737 | 737 | * @param array $parameters |
738 | 738 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
739 | 739 | */ |
740 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
741 | - $parameters['immediatly'] = false; |
|
740 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
741 | + $parameters['immediatly']=false; |
|
742 | 742 | return $this->_post($url, $params, $responseElement, $parameters); |
743 | 743 | } |
744 | 744 | |
@@ -757,9 +757,9 @@ discard block |
||
757 | 757 | * @param array $parameters |
758 | 758 | * 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) |
759 | 759 | */ |
760 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
761 | - $parameters['method'] = 'post'; |
|
762 | - $parameters['params'] = $params; |
|
760 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
761 | + $parameters['method']='post'; |
|
762 | + $parameters['params']=$params; |
|
763 | 763 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
764 | 764 | } |
765 | 765 | |
@@ -777,75 +777,75 @@ discard block |
||
777 | 777 | * @param array $parameters |
778 | 778 | * 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) |
779 | 779 | */ |
780 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
780 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
781 | 781 | return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
782 | 782 | } |
783 | 783 | |
784 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
784 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
785 | 785 | if (isset($this->params['ajax'])) { |
786 | 786 | extract($this->params['ajax']); |
787 | 787 | } |
788 | - $params = '{}'; |
|
789 | - $validation = false; |
|
788 | + $params='{}'; |
|
789 | + $validation=false; |
|
790 | 790 | \extract($parameters); |
791 | - $async = ($async) ? 'true' : 'false'; |
|
792 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
793 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
794 | - $form = $this->_getFormElement($form); |
|
795 | - $retour .= "\n$('#'+" . $form . ").trigger('ajaxSubmit');"; |
|
796 | - if (! isset($contentType) || $contentType != 'false') { |
|
797 | - $retour .= "\nlet params=$('#'+" . $form . ").serialize();\n"; |
|
791 | + $async=($async) ? 'true' : 'false'; |
|
792 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
793 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
794 | + $form=$this->_getFormElement($form); |
|
795 | + $retour.="\n$('#'+".$form.").trigger('ajaxSubmit');"; |
|
796 | + if (!isset($contentType) || $contentType!='false') { |
|
797 | + $retour.="\nlet params=$('#'+".$form.").serialize();\n"; |
|
798 | 798 | if (isset($params)) { |
799 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
799 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
800 | 800 | } |
801 | 801 | } else { |
802 | - $retour .= "\nlet params=new FormData($('#'+" . $form . ")[0]);\n"; |
|
802 | + $retour.="\nlet params=new FormData($('#'+".$form.")[0]);\n"; |
|
803 | 803 | } |
804 | - $responseElement = $this->_getResponseElement($responseElement); |
|
805 | - $retour .= "let self=this;\n"; |
|
806 | - $before = isset($before) ? $before : ""; |
|
807 | - $retour .= $before; |
|
808 | - if ($hasLoader === true) { |
|
804 | + $responseElement=$this->_getResponseElement($responseElement); |
|
805 | + $retour.="let self=this;\n"; |
|
806 | + $before=isset($before) ? $before : ""; |
|
807 | + $retour.=$before; |
|
808 | + if ($hasLoader===true) { |
|
809 | 809 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
810 | - } elseif ($hasLoader === 'response') { |
|
810 | + } elseif ($hasLoader==='response') { |
|
811 | 811 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
812 | - } elseif ($hasLoader === 'internal-x') { |
|
812 | + } elseif ($hasLoader==='internal-x') { |
|
813 | 813 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
814 | - } elseif ($hasLoader === 'internal') { |
|
815 | - $retour .= "\n$(this).addClass('loading');"; |
|
814 | + } elseif ($hasLoader==='internal') { |
|
815 | + $retour.="\n$(this).addClass('loading');"; |
|
816 | 816 | } elseif (\is_string($hasLoader)) { |
817 | - $retour .= "\n$hasLoader.addClass('loading');"; |
|
817 | + $retour.="\n$hasLoader.addClass('loading');"; |
|
818 | 818 | } |
819 | - $ajaxParameters = [ |
|
819 | + $ajaxParameters=[ |
|
820 | 820 | "url" => "url", |
821 | 821 | "method" => "'POST'", |
822 | 822 | "data" => "params", |
823 | 823 | "async" => $async |
824 | 824 | ]; |
825 | 825 | if (isset($headers)) { |
826 | - $ajaxParameters["headers"] = $headers; |
|
826 | + $ajaxParameters["headers"]=$headers; |
|
827 | 827 | } |
828 | 828 | if (isset($partial)) { |
829 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
830 | - $retour .= "let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
829 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
830 | + $retour.="let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
831 | 831 | } |
832 | 832 | $this->createAjaxParameters($ajaxParameters, $parameters); |
833 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
834 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) . "})"; |
|
833 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
834 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."})"; |
|
835 | 835 | if (isset($error)) { |
836 | - $retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})'; |
|
836 | + $retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})'; |
|
837 | 837 | } |
838 | - $retour .= '.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {' . ($always ?? '') . $this->removeLoader($hasLoader) . '})'; |
|
839 | - $retour .= ";\n"; |
|
838 | + $retour.='.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {'.($always ?? '').$this->removeLoader($hasLoader).'})'; |
|
839 | + $retour.=";\n"; |
|
840 | 840 | if ($validation) { |
841 | - $retour = "$('#'+" . $form . ").validate({submitHandler: function(form) { |
|
842 | - " . $retour . " |
|
841 | + $retour="$('#'+".$form.").validate({submitHandler: function(form) { |
|
842 | + " . $retour." |
|
843 | 843 | }});\n"; |
844 | - $retour .= "$('#'+" . $form . ").submit();\n"; |
|
844 | + $retour.="$('#'+".$form.").submit();\n"; |
|
845 | 845 | } |
846 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
846 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
847 | 847 | if ($immediatly) |
848 | - $this->jquery_code_for_compile[] = $retour; |
|
848 | + $this->jquery_code_for_compile[]=$retour; |
|
849 | 849 | return $retour; |
850 | 850 | } |
851 | 851 | |
@@ -861,8 +861,8 @@ discard block |
||
861 | 861 | * @param array $parameters |
862 | 862 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
863 | 863 | */ |
864 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
865 | - $parameters['immediatly'] = true; |
|
864 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
865 | + $parameters['immediatly']=true; |
|
866 | 866 | return $this->_postForm($url, $form, $responseElement, $parameters); |
867 | 867 | } |
868 | 868 | |
@@ -879,8 +879,8 @@ discard block |
||
879 | 879 | * @param array $parameters |
880 | 880 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
881 | 881 | */ |
882 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
883 | - $parameters['immediatly'] = false; |
|
882 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
883 | + $parameters['immediatly']=false; |
|
884 | 884 | return $this->_postForm($url, $form, $responseElement, $parameters); |
885 | 885 | } |
886 | 886 | |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | * @param array $parameters |
898 | 898 | * 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) |
899 | 899 | */ |
900 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
900 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
901 | 901 | $this->setDefaultParameters($parameters, [ |
902 | 902 | 'preventDefault' => true, |
903 | 903 | 'stopPropagation' => true, |
@@ -919,11 +919,11 @@ discard block |
||
919 | 919 | * @param array $parameters |
920 | 920 | * 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) |
921 | 921 | */ |
922 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
922 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
923 | 923 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
924 | 924 | } |
925 | 925 | |
926 | - public function addCsrf($name = 'csrf-token') { |
|
926 | + public function addCsrf($name='csrf-token') { |
|
927 | 927 | return " |
928 | 928 | $.ajaxSetup({ |
929 | 929 | beforeSend: function(xhr, settings) { |
@@ -19,70 +19,70 @@ |
||
19 | 19 | $this->uiName='toast'; |
20 | 20 | } |
21 | 21 | |
22 | - public function close(){ |
|
22 | + public function close() { |
|
23 | 23 | return $this->addBehavior('close'); |
24 | 24 | } |
25 | 25 | |
26 | - public function setClass($value){ |
|
26 | + public function setClass($value) { |
|
27 | 27 | $this->params['class']=$value; |
28 | 28 | return $this; |
29 | 29 | } |
30 | 30 | |
31 | - public function setCloseIcon(){ |
|
31 | + public function setCloseIcon() { |
|
32 | 32 | $this->params['closeIcon']=true; |
33 | 33 | return $this; |
34 | 34 | } |
35 | 35 | |
36 | - public function setShowIcon($value=false){ |
|
36 | + public function setShowIcon($value=false) { |
|
37 | 37 | $this->params['showIcon']=$value; |
38 | 38 | return $this; |
39 | 39 | } |
40 | 40 | |
41 | - public function setCloseOnClick($value){ |
|
41 | + public function setCloseOnClick($value) { |
|
42 | 42 | $this->params['closeOnClick']=$value; |
43 | 43 | return $this; |
44 | 44 | } |
45 | 45 | |
46 | - public function setTitle($title){ |
|
46 | + public function setTitle($title) { |
|
47 | 47 | $this->params['title']=$title; |
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - public function setActions(array $actions){ |
|
52 | - foreach ($actions as &$action){ |
|
53 | - if(isset($action['click'])){ |
|
54 | - $js=\str_ireplace("\"","%quote%", $action['click']); |
|
51 | + public function setActions(array $actions) { |
|
52 | + foreach ($actions as &$action) { |
|
53 | + if (isset($action['click'])) { |
|
54 | + $js=\str_ireplace("\"", "%quote%", $action['click']); |
|
55 | 55 | $action['click']="%function(){".$js."}%"; |
56 | 56 | } |
57 | 57 | } |
58 | 58 | $this->params['actions']=$actions; |
59 | - if(count($actions)>0) { |
|
60 | - $this->params['displayTime'] = 0; |
|
59 | + if (count($actions)>0) { |
|
60 | + $this->params['displayTime']=0; |
|
61 | 61 | } |
62 | 62 | return $this; |
63 | 63 | } |
64 | 64 | |
65 | - public function setMessage($message){ |
|
65 | + public function setMessage($message) { |
|
66 | 66 | $this->params['message']=$message; |
67 | 67 | return $this; |
68 | 68 | } |
69 | 69 | |
70 | - public function setPosition($position){ |
|
70 | + public function setPosition($position) { |
|
71 | 71 | $this->params['position']=$position; |
72 | 72 | return $this; |
73 | 73 | } |
74 | 74 | |
75 | - public function setDisplayTime($time){ |
|
75 | + public function setDisplayTime($time) { |
|
76 | 76 | $this->params['displayTime']=$time; |
77 | 77 | return $this; |
78 | 78 | } |
79 | 79 | |
80 | - public function setShowProgress($value='top'){ |
|
80 | + public function setShowProgress($value='top') { |
|
81 | 81 | $this->params['showProgress']=$value; |
82 | 82 | return $this; |
83 | 83 | } |
84 | 84 | |
85 | - public function setClassProgress($value){ |
|
85 | + public function setClassProgress($value) { |
|
86 | 86 | $this->params['classProgress']=$value; |
87 | 87 | return $this; |
88 | 88 | } |
@@ -17,9 +17,9 @@ discard block |
||
17 | 17 | return $this; |
18 | 18 | } |
19 | 19 | |
20 | - protected function generateParamParts(){ |
|
20 | + protected function generateParamParts() { |
|
21 | 21 | $results=[]; |
22 | - foreach ($this->paramParts as $paramPart){ |
|
22 | + foreach ($this->paramParts as $paramPart) { |
|
23 | 23 | $results[]="{$this->uiName}(".\implode(",", $paramPart).")"; |
24 | 24 | } |
25 | 25 | return \implode(".", $results); |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | |
28 | 28 | public function getScript() { |
29 | 29 | $allParams=$this->params; |
30 | - $this->jquery_code_for_compile=array (); |
|
30 | + $this->jquery_code_for_compile=array(); |
|
31 | 31 | $this->compileJsCodes(); |
32 | 32 | $paramParts=""; |
33 | - if(\sizeof($this->paramParts)>0){ |
|
33 | + if (\sizeof($this->paramParts)>0) { |
|
34 | 34 | $paramParts=".".$this->generateParamParts(); |
35 | 35 | } |
36 | 36 | $this->jquery_code_for_compile []="$( \"".$this->attachTo."\" ).{$this->uiName}(".$this->getParamsAsJSON($allParams).")".$paramParts.";"; |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | return $this; |
44 | 44 | } |
45 | 45 | |
46 | - public function addComponentEvent($event,$jsCode){ |
|
47 | - $jsCode=\str_ireplace("\"","%quote%", $jsCode); |
|
46 | + public function addComponentEvent($event, $jsCode) { |
|
47 | + $jsCode=\str_ireplace("\"", "%quote%", $jsCode); |
|
48 | 48 | return $this->setParam($event, "%function(module){".$jsCode."}%"); |
49 | 49 | } |
50 | 50 | |
51 | - public function setJs(JsUtils $js){ |
|
51 | + public function setJs(JsUtils $js) { |
|
52 | 52 | $this->js=$js; |
53 | 53 | $js->semantic()->addComponent($this, $this->attachTo, $this->params); |
54 | 54 | } |