|
@@ -15,80 +15,80 @@ discard block |
|
|
block discarded – undo |
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
|
$retour='(function(){'.$retour.'})();'; |
84
|
84
|
if ($immediatly) { |
85
|
|
- $this->jquery_code_for_compile[] = $retour; |
|
85
|
+ $this->jquery_code_for_compile[]=$retour; |
86
|
86
|
} |
87
|
87
|
return $retour; |
88
|
88
|
} |
89
|
89
|
|
90
|
90
|
protected function createAjaxParameters(&$original, $parameters) { |
91
|
|
- $validParameters = [ |
|
91
|
+ $validParameters=[ |
92
|
92
|
"contentType" => "%value%", |
93
|
93
|
"dataType" => "'%value%'", |
94
|
94
|
"beforeSend" => "function(jqXHR,settings){%value%}", |
|
@@ -97,21 +97,21 @@ discard block |
|
|
block discarded – undo |
97
|
97
|
]; |
98
|
98
|
foreach ($validParameters as $param => $mask) { |
99
|
99
|
if (isset($parameters[$param])) { |
100
|
|
- $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
100
|
+ $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
101
|
101
|
} |
102
|
102
|
} |
103
|
103
|
} |
104
|
104
|
|
105
|
105
|
protected function implodeAjaxParameters($ajaxParameters) { |
106
|
|
- $s = ''; |
|
106
|
+ $s=''; |
107
|
107
|
foreach ($ajaxParameters as $k => $v) { |
108
|
|
- if ($s !== '') { |
109
|
|
- $s .= ','; |
|
108
|
+ if ($s!=='') { |
|
109
|
+ $s.=','; |
110
|
110
|
} |
111
|
111
|
if (is_array($v)) { |
112
|
|
- $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
112
|
+ $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
113
|
113
|
} else { |
114
|
|
- $s .= "'{$k}':{$v}"; |
|
114
|
+ $s.="'{$k}':{$v}"; |
115
|
115
|
} |
116
|
116
|
} |
117
|
117
|
return $s; |
|
@@ -119,29 +119,29 @@ discard block |
|
|
block discarded – undo |
119
|
119
|
|
120
|
120
|
protected function _addJsCondition($jsCondition, $jsSource) { |
121
|
121
|
if (isset($jsCondition)) { |
122
|
|
- return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
122
|
+ return "if(".$jsCondition."){\n".$jsSource."\n}"; |
123
|
123
|
} |
124
|
124
|
return $jsSource; |
125
|
125
|
} |
126
|
126
|
|
127
|
127
|
protected function _getAjaxUrl($url, $attr) { |
128
|
|
- $url = $this->_correctAjaxUrl($url); |
129
|
|
- $retour = "let url='" . $url . "';"; |
130
|
|
- $slash = "/"; |
131
|
|
- if (JString::endswith($url, "/") === true) { |
132
|
|
- $slash = ""; |
|
128
|
+ $url=$this->_correctAjaxUrl($url); |
|
129
|
+ $retour="let url='".$url."';"; |
|
130
|
+ $slash="/"; |
|
131
|
+ if (JString::endswith($url, "/")===true) { |
|
132
|
+ $slash=""; |
133
|
133
|
} |
134
|
134
|
|
135
|
135
|
if (JString::isNotNull($attr)) { |
136
|
|
- if ($attr === "value") { |
137
|
|
- $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
138
|
|
- } elseif ($attr === "html") { |
139
|
|
- $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
140
|
|
- } elseif (\substr($attr, 0, 3) === "js:") { |
141
|
|
- $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
142
|
|
- } elseif ($attr !== null && $attr !== "") { |
143
|
|
- $retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';"; |
144
|
|
- $retour .= "url=!(new RegExp('^((http|https|ftp):\/\/)')).test(elmUrl)?url+'" . $slash . "'+elmUrl:elmUrl;\n"; |
|
136
|
+ if ($attr==="value") { |
|
137
|
+ $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
138
|
+ } elseif ($attr==="html") { |
|
139
|
+ $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
140
|
+ } elseif (\substr($attr, 0, 3)==="js:") { |
|
141
|
+ $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
142
|
+ } elseif ($attr!==null && $attr!=="") { |
|
143
|
+ $retour.="let elmUrl=$(this).attr('".$attr."')||'';"; |
|
144
|
+ $retour.="url=!(new RegExp('^((http|https|ftp):\/\/)')).test(elmUrl)?url+'".$slash."'+elmUrl:elmUrl;\n"; |
145
|
145
|
} |
146
|
146
|
} |
147
|
147
|
return $retour; |
|
@@ -151,44 +151,44 @@ discard block |
|
|
block discarded – undo |
151
|
151
|
return "window.onpopstate = function(e){if(e.state){let target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
152
|
152
|
} |
153
|
153
|
|
154
|
|
- protected function autoActiveLinks($previousURL = "window.location.href") { |
155
|
|
- $result = "\nif (typeof getHref !== 'function'){function getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}}"; |
156
|
|
- $result .= "\nlet myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
154
|
+ protected function autoActiveLinks($previousURL="window.location.href") { |
|
155
|
+ $result="\nif (typeof getHref !== 'function'){function getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}}"; |
|
156
|
+ $result.="\nlet myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
157
|
157
|
return $result; |
158
|
158
|
} |
159
|
159
|
|
160
|
|
- protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history = null) { |
161
|
|
- $retour = ""; |
162
|
|
- $call = null; |
|
160
|
+ protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $history=null) { |
|
161
|
+ $retour=""; |
|
162
|
+ $call=null; |
163
|
163
|
if (JString::isNotNull($responseElement)) { |
164
|
164
|
if (isset($ajaxTransition)) { |
165
|
|
- $call = $this->setAjaxDataCall($ajaxTransition); |
|
165
|
+ $call=$this->setAjaxDataCall($ajaxTransition); |
166
|
166
|
} elseif (isset($this->ajaxTransition)) { |
167
|
|
- $call = $this->ajaxTransition; |
|
167
|
+ $call=$this->ajaxTransition; |
168
|
168
|
} |
169
|
169
|
if (\is_callable($call)) |
170
|
|
- $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
170
|
+ $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
171
|
171
|
else |
172
|
|
- $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
172
|
+ $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
173
|
173
|
} |
174
|
174
|
if (isset($history)) { |
175
|
175
|
if ($this->params["autoActiveLinks"]) { |
176
|
|
- $retour .= $this->autoActiveLinks("url"); |
|
176
|
+ $retour.=$this->autoActiveLinks("url"); |
177
|
177
|
} |
178
|
|
- $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
178
|
+ $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
179
|
179
|
} |
180
|
|
- $retour .= "\t" . $jsCallback . "\n"; |
|
180
|
+ $retour.="\t".$jsCallback."\n"; |
181
|
181
|
return $retour; |
182
|
182
|
} |
183
|
183
|
|
184
|
184
|
protected function removeLoader($hasLoader) { |
185
|
|
- if ($hasLoader === true) { |
|
185
|
+ if ($hasLoader===true) { |
186
|
186
|
return "\n$('body').find('.ajax-loader').remove();"; |
187
|
187
|
} |
188
|
|
- if ($hasLoader === 'internal') { |
|
188
|
+ if ($hasLoader==='internal') { |
189
|
189
|
return "\n$(self).removeClass('loading');"; |
190
|
190
|
} |
191
|
|
- if ($hasLoader === 'internal-x') { |
|
191
|
+ if ($hasLoader==='internal-x') { |
192
|
192
|
return "\n$(self).children('.ajax-loader').remove();"; |
193
|
193
|
} |
194
|
194
|
return "\n$('body').find('.loading').removeClass('loading');"; |
|
@@ -196,71 +196,71 @@ discard block |
|
|
block discarded – undo |
196
|
196
|
|
197
|
197
|
protected function _getResponseElement($responseElement) { |
198
|
198
|
if (JString::isNotNull($responseElement)) { |
199
|
|
- $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
199
|
+ $responseElement=Javascript::prep_jquery_selector($responseElement); |
200
|
200
|
} |
201
|
201
|
return $responseElement; |
202
|
202
|
} |
203
|
203
|
|
204
|
204
|
protected function _getFormElement($formElement) { |
205
|
205
|
if (JString::isNotNull($formElement)) { |
206
|
|
- $formElement = Javascript::prep_value($formElement); |
|
206
|
+ $formElement=Javascript::prep_value($formElement); |
207
|
207
|
} |
208
|
208
|
return $formElement; |
209
|
209
|
} |
210
|
210
|
|
211
|
211
|
protected function _correctAjaxUrl($url) { |
212
|
|
- if ($url !== "/" && JString::endsWith($url, "/") === true) |
213
|
|
- $url = substr($url, 0, strlen($url) - 1); |
214
|
|
- if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
215
|
|
- $url = $this->getUrl($url); |
|
212
|
+ if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
213
|
+ $url=substr($url, 0, strlen($url)-1); |
|
214
|
+ if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
215
|
+ $url=$this->getUrl($url); |
216
|
216
|
} |
217
|
217
|
return $url; |
218
|
218
|
} |
219
|
219
|
|
220
|
|
- public static function _correctParams($params, $ajaxParameters = []) { |
|
220
|
+ public static function _correctParams($params, $ajaxParameters=[]) { |
221
|
221
|
if (JString::isNull($params)) { |
222
|
222
|
return ""; |
223
|
223
|
} |
224
|
224
|
if (\preg_match("@^\{.*?\}$@", $params)) { |
225
|
|
- if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
226
|
|
- return '$.param(' . $params . ')'; |
|
225
|
+ if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
226
|
+ return '$.param('.$params.')'; |
227
|
227
|
} else { |
228
|
|
- return 'JSON.stringify(' . $params . ')'; |
|
228
|
+ return 'JSON.stringify('.$params.')'; |
229
|
229
|
} |
230
|
230
|
} |
231
|
231
|
return $params; |
232
|
232
|
} |
233
|
233
|
|
234
|
234
|
public static function _implodeParams($parameters) { |
235
|
|
- $allParameters = []; |
|
235
|
+ $allParameters=[]; |
236
|
236
|
foreach ($parameters as $params) { |
237
|
237
|
if (isset($params)) |
238
|
|
- $allParameters[] = self::_correctParams($params); |
|
238
|
+ $allParameters[]=self::_correctParams($params); |
239
|
239
|
} |
240
|
240
|
return \implode("+'&'+", $allParameters); |
241
|
241
|
} |
242
|
242
|
|
243
|
|
- protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
244
|
|
- if (! isset($ajaxLoader)) { |
245
|
|
- $ajaxLoader = $this->ajaxLoader; |
|
243
|
+ protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
244
|
+ if (!isset($ajaxLoader)) { |
|
245
|
+ $ajaxLoader=$this->ajaxLoader; |
246
|
246
|
} |
247
|
|
- $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
248
|
|
- $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
247
|
+ $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
248
|
+ $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
249
|
249
|
} |
250
|
250
|
|
251
|
|
- protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
252
|
|
- if (! isset($ajaxLoader)) { |
253
|
|
- $ajaxLoader = $this->ajaxLoader; |
|
251
|
+ protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
252
|
+ if (!isset($ajaxLoader)) { |
|
253
|
+ $ajaxLoader=$this->ajaxLoader; |
254
|
254
|
} |
255
|
|
- $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
256
|
|
- $retour .= "{$responseElement}.empty();\n"; |
257
|
|
- $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
255
|
+ $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
256
|
+ $retour.="{$responseElement}.empty();\n"; |
|
257
|
+ $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
258
|
258
|
} |
259
|
259
|
|
260
|
260
|
protected function setAjaxDataCall($params) { |
261
|
|
- $result = null; |
262
|
|
- if (! \is_callable($params)) { |
263
|
|
- $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
261
|
+ $result=null; |
|
262
|
+ if (!\is_callable($params)) { |
|
263
|
+ $result=function($responseElement, $jqueryDone='html') use ($params) { |
264
|
264
|
return AjaxTransition::{$params}($responseElement, $jqueryDone); |
265
|
265
|
}; |
266
|
266
|
} |
|
@@ -269,13 +269,13 @@ discard block |
|
|
block discarded – undo |
269
|
269
|
|
270
|
270
|
protected function setDefaultParameters(&$parameters, $default) { |
271
|
271
|
foreach ($default as $k => $v) { |
272
|
|
- if (! isset($parameters[$k])) |
273
|
|
- $parameters[$k] = $v; |
|
272
|
+ if (!isset($parameters[$k])) |
|
273
|
+ $parameters[$k]=$v; |
274
|
274
|
} |
275
|
275
|
} |
276
|
276
|
|
277
|
277
|
public function setAjaxLoader($loader) { |
278
|
|
- $this->ajaxLoader = $loader; |
|
278
|
+ $this->ajaxLoader=$loader; |
279
|
279
|
} |
280
|
280
|
|
281
|
281
|
/** |
|
@@ -286,7 +286,7 @@ discard block |
|
|
block discarded – undo |
286
|
286
|
* @param string $responseElement |
287
|
287
|
* selector of the HTML element displaying the answer |
288
|
288
|
*/ |
289
|
|
- private function _get($url, $responseElement = '', $parameters = []) { |
|
289
|
+ private function _get($url, $responseElement='', $parameters=[]) { |
290
|
290
|
return $this->_ajax('get', $url, $responseElement, $parameters); |
291
|
291
|
} |
292
|
292
|
|
|
@@ -300,8 +300,8 @@ discard block |
|
|
block discarded – undo |
300
|
300
|
* @param array $parameters |
301
|
301
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
302
|
302
|
*/ |
303
|
|
- public function get($url, $responseElement = '', $parameters = []) { |
304
|
|
- $parameters['immediatly'] = true; |
|
303
|
+ public function get($url, $responseElement='', $parameters=[]) { |
|
304
|
+ $parameters['immediatly']=true; |
305
|
305
|
return $this->_get($url, $responseElement, $parameters); |
306
|
306
|
} |
307
|
307
|
|
|
@@ -317,8 +317,8 @@ discard block |
|
|
block discarded – undo |
317
|
317
|
* @param array $parameters |
318
|
318
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
319
|
319
|
*/ |
320
|
|
- public function ajax($method, $url, $responseElement = '', $parameters = []) { |
321
|
|
- $parameters['immediatly'] = true; |
|
320
|
+ public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
321
|
+ $parameters['immediatly']=true; |
322
|
322
|
return $this->_ajax($method, $url, $responseElement, $parameters); |
323
|
323
|
} |
324
|
324
|
|
|
@@ -340,7 +340,7 @@ discard block |
|
|
block discarded – undo |
340
|
340
|
* $immediatly |
341
|
341
|
* @return string |
342
|
342
|
*/ |
343
|
|
- public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) { |
|
343
|
+ public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
344
|
344
|
return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
345
|
345
|
} |
346
|
346
|
|
|
@@ -356,8 +356,8 @@ discard block |
|
|
block discarded – undo |
356
|
356
|
* @param array $parameters |
357
|
357
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
358
|
358
|
*/ |
359
|
|
- public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) { |
360
|
|
- $parameters['immediatly'] = false; |
|
359
|
+ public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
360
|
+ $parameters['immediatly']=false; |
361
|
361
|
return $this->_ajax($method, $url, $responseElement, $parameters); |
362
|
362
|
} |
363
|
363
|
|
|
@@ -371,15 +371,15 @@ discard block |
|
|
block discarded – undo |
371
|
371
|
* @param array $parameters |
372
|
372
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
373
|
373
|
*/ |
374
|
|
- private function _json($url, $method = "get", $parameters = []) { |
375
|
|
- $parameters = \array_merge($parameters, [ |
|
374
|
+ private function _json($url, $method="get", $parameters=[]) { |
|
375
|
+ $parameters=\array_merge($parameters, [ |
376
|
376
|
"hasLoader" => false |
377
|
377
|
]); |
378
|
|
- $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
379
|
|
- $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
380
|
|
- $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"; |
381
|
|
- $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
382
|
|
- $parameters["jsCallback"] = $retour; |
|
378
|
+ $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
379
|
+ $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
380
|
+ $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"; |
|
381
|
+ $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
382
|
+ $parameters["jsCallback"]=$retour; |
383
|
383
|
return $this->_ajax($method, $url, null, $parameters); |
384
|
384
|
} |
385
|
385
|
|
|
@@ -393,7 +393,7 @@ discard block |
|
|
block discarded – undo |
393
|
393
|
* @param array $parameters |
394
|
394
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
395
|
395
|
*/ |
396
|
|
- public function json($url, $method = "get", $parameters = []) { |
|
396
|
+ public function json($url, $method="get", $parameters=[]) { |
397
|
397
|
return $this->_json($url, $method, $parameters); |
398
|
398
|
} |
399
|
399
|
|
|
@@ -409,7 +409,7 @@ discard block |
|
|
block discarded – undo |
409
|
409
|
* @param array $parameters |
410
|
410
|
* default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
411
|
411
|
*/ |
412
|
|
- public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) { |
|
412
|
+ public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
413
|
413
|
$this->setDefaultParameters($parameters, [ |
414
|
414
|
'preventDefault' => true, |
415
|
415
|
'stopPropagation' => true, |
|
@@ -429,8 +429,8 @@ discard block |
|
|
block discarded – undo |
429
|
429
|
* @param array $parameters |
430
|
430
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
431
|
431
|
*/ |
432
|
|
- public function jsonDeferred($url, $method = 'get', $parameters = []) { |
433
|
|
- $parameters['immediatly'] = false; |
|
432
|
+ public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
433
|
+ $parameters['immediatly']=false; |
434
|
434
|
return $this->_json($url, $method, $parameters); |
435
|
435
|
} |
436
|
436
|
|
|
@@ -445,29 +445,29 @@ discard block |
|
|
block discarded – undo |
445
|
445
|
* @param array $parameters |
446
|
446
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
447
|
447
|
*/ |
448
|
|
- private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
449
|
|
- $parameters = \array_merge($parameters, [ |
|
448
|
+ private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
449
|
+ $parameters=\array_merge($parameters, [ |
450
|
450
|
"hasLoader" => false |
451
|
451
|
]); |
452
|
|
- $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
453
|
|
- $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
454
|
|
- $context = isset($parameters['context']) ? $parameters['context'] : null; |
455
|
|
- if ($context === null) { |
456
|
|
- $parent = "$('" . $maskSelector . "').parent()"; |
457
|
|
- $newElm = "$('#'+newId)"; |
|
452
|
+ $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
453
|
+ $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
454
|
+ $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
455
|
+ if ($context===null) { |
|
456
|
+ $parent="$('".$maskSelector."').parent()"; |
|
457
|
+ $newElm="$('#'+newId)"; |
458
|
458
|
} else { |
459
|
|
- $parent = $context; |
460
|
|
- $newElm = $context . ".find('#'+newId)"; |
|
459
|
+ $parent=$context; |
|
460
|
+ $newElm=$context.".find('#'+newId)"; |
461
|
461
|
} |
462
|
|
- $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
463
|
|
- $retour = $parent . ".find('.{$rowClass}').remove();"; |
464
|
|
- $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(); |
|
462
|
+ $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
463
|
+ $retour=$parent.".find('.{$rowClass}').remove();"; |
|
464
|
+ $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(); |
465
|
465
|
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"; |
466
|
|
- $retour .= $appendTo; |
467
|
|
- $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"; |
468
|
|
- $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
469
|
|
- $retour .= "\t" . $jsCallback; |
470
|
|
- $parameters["jsCallback"] = $retour; |
|
466
|
+ $retour.=$appendTo; |
|
467
|
+ $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"; |
|
468
|
+ $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
469
|
+ $retour.="\t".$jsCallback; |
|
470
|
+ $parameters["jsCallback"]=$retour; |
471
|
471
|
return $this->_ajax($method, $url, null, $parameters); |
472
|
472
|
} |
473
|
473
|
|
|
@@ -482,7 +482,7 @@ discard block |
|
|
block discarded – undo |
482
|
482
|
* @param array $parameters |
483
|
483
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
484
|
484
|
*/ |
485
|
|
- public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
485
|
+ public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
486
|
486
|
return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
487
|
487
|
} |
488
|
488
|
|
|
@@ -497,8 +497,8 @@ discard block |
|
|
block discarded – undo |
497
|
497
|
* @param array $parameters |
498
|
498
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
499
|
499
|
*/ |
500
|
|
- public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) { |
501
|
|
- $parameters['immediatly'] = false; |
|
500
|
+ public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
501
|
+ $parameters['immediatly']=false; |
502
|
502
|
return $this->jsonArray($maskSelector, $url, $method, $parameters); |
503
|
503
|
} |
504
|
504
|
|
|
@@ -514,7 +514,7 @@ discard block |
|
|
block discarded – undo |
514
|
514
|
* @param array $parameters |
515
|
515
|
* default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
516
|
516
|
*/ |
517
|
|
- public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) { |
|
517
|
+ public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
518
|
518
|
$this->setDefaultParameters($parameters, [ |
519
|
519
|
'preventDefault' => true, |
520
|
520
|
'stopPropagation' => true, |
|
@@ -535,8 +535,8 @@ discard block |
|
|
block discarded – undo |
535
|
535
|
* @param array $parameters |
536
|
536
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
537
|
537
|
*/ |
538
|
|
- public function getDeferred($url, $responseElement = "", $parameters = []) { |
539
|
|
- $parameters['immediatly'] = false; |
|
538
|
+ public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
539
|
+ $parameters['immediatly']=false; |
540
|
540
|
return $this->_get($url, $responseElement, $parameters); |
541
|
541
|
} |
542
|
542
|
|
|
@@ -555,8 +555,8 @@ discard block |
|
|
block discarded – undo |
555
|
555
|
* @param array $parameters |
556
|
556
|
* 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) |
557
|
557
|
*/ |
558
|
|
- public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
559
|
|
- $parameters['method'] = 'get'; |
|
558
|
+ public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
559
|
+ $parameters['method']='get'; |
560
|
560
|
return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
561
|
561
|
} |
562
|
562
|
|
|
@@ -575,7 +575,7 @@ discard block |
|
|
block discarded – undo |
575
|
575
|
* @param array $parameters |
576
|
576
|
* 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) |
577
|
577
|
*/ |
578
|
|
- public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) { |
|
578
|
+ public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
579
|
579
|
$this->setDefaultParameters($parameters, [ |
580
|
580
|
'preventDefault' => true, |
581
|
581
|
'stopPropagation' => true, |
|
@@ -599,7 +599,7 @@ discard block |
|
|
block discarded – undo |
599
|
599
|
* @param array $parameters |
600
|
600
|
* 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) |
601
|
601
|
*/ |
602
|
|
- public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
602
|
+ public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
603
|
603
|
return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
604
|
604
|
} |
605
|
605
|
|
|
@@ -616,7 +616,7 @@ discard block |
|
|
block discarded – undo |
616
|
616
|
* @param array $parameters |
617
|
617
|
* 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) |
618
|
618
|
*/ |
619
|
|
- public function getOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
619
|
+ public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
620
|
620
|
return $this->getOn('click', $element, $url, $responseElement, $parameters); |
621
|
621
|
} |
622
|
622
|
|
|
@@ -631,18 +631,18 @@ discard block |
|
|
block discarded – undo |
631
|
631
|
* 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) |
632
|
632
|
* @return $this |
633
|
633
|
*/ |
634
|
|
- public function getHref($element, $responseElement = "", $parameters = array()) { |
635
|
|
- $parameters['attr'] = 'href'; |
|
634
|
+ public function getHref($element, $responseElement="", $parameters=array()) { |
|
635
|
+ $parameters['attr']='href'; |
636
|
636
|
if (JString::isNull($responseElement)) { |
637
|
|
- $responseElement = '%$(self).attr("data-target")%'; |
|
637
|
+ $responseElement='%$(self).attr("data-target")%'; |
638
|
638
|
} else { |
639
|
|
- $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
639
|
+ $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
640
|
640
|
} |
641
|
|
- if (! isset($parameters['historize'])) { |
642
|
|
- $parameters['historize'] = true; |
|
641
|
+ if (!isset($parameters['historize'])) { |
|
642
|
+ $parameters['historize']=true; |
643
|
643
|
} |
644
|
|
- if (! isset($parameters['jsCallback'])) { |
645
|
|
- $parameters['jsCallback'] = 'let event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
644
|
+ if (!isset($parameters['jsCallback'])) { |
|
645
|
+ $parameters['jsCallback']='let event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
646
|
646
|
} |
647
|
647
|
return $this->getOnClick($element, "", $responseElement, $parameters); |
648
|
648
|
} |
|
@@ -658,15 +658,15 @@ discard block |
|
|
block discarded – undo |
658
|
658
|
* 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) |
659
|
659
|
* @return $this |
660
|
660
|
*/ |
661
|
|
- public function postHref($element, $responseElement = "", $parameters = array()) { |
662
|
|
- $parameters['attr'] = 'href'; |
|
661
|
+ public function postHref($element, $responseElement="", $parameters=array()) { |
|
662
|
+ $parameters['attr']='href'; |
663
|
663
|
if (JString::isNull($responseElement)) { |
664
|
|
- $responseElement = '%$(this).attr("data-target")%'; |
|
664
|
+ $responseElement='%$(this).attr("data-target")%'; |
665
|
665
|
} else { |
666
|
|
- $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
666
|
+ $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
667
|
667
|
} |
668
|
|
- if (! isset($parameters['historize'])) { |
669
|
|
- $parameters['historize'] = true; |
|
668
|
+ if (!isset($parameters['historize'])) { |
|
669
|
+ $parameters['historize']=true; |
670
|
670
|
} |
671
|
671
|
return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
672
|
672
|
} |
|
@@ -682,29 +682,29 @@ discard block |
|
|
block discarded – undo |
682
|
682
|
* 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) |
683
|
683
|
* @return $this |
684
|
684
|
*/ |
685
|
|
- public function postFormAction($element, $responseElement = "", $parameters = array()) { |
686
|
|
- $parameters['attr'] = 'action'; |
|
685
|
+ public function postFormAction($element, $responseElement="", $parameters=array()) { |
|
686
|
+ $parameters['attr']='action'; |
687
|
687
|
if (JString::isNull($responseElement)) { |
688
|
|
- $responseElement = '%$(self).attr("data-target")%'; |
|
688
|
+ $responseElement='%$(self).attr("data-target")%'; |
689
|
689
|
} else { |
690
|
|
- $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
690
|
+ $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
691
|
691
|
} |
692
|
|
- $formId = '%$(this).attr("id")%'; |
693
|
|
- if (! isset($parameters['historize'])) { |
694
|
|
- $parameters['historize'] = true; |
|
692
|
+ $formId='%$(this).attr("id")%'; |
|
693
|
+ if (!isset($parameters['historize'])) { |
|
694
|
+ $parameters['historize']=true; |
695
|
695
|
} |
696
|
|
- $parameters['preventDefault'] = true; |
697
|
|
- if (! isset($parameters['hasLoader'])) { |
698
|
|
- $parameters['hasLoader'] = '$(self).find("button, input[type=submit], input[type=button]")'; |
|
696
|
+ $parameters['preventDefault']=true; |
|
697
|
+ if (!isset($parameters['hasLoader'])) { |
|
698
|
+ $parameters['hasLoader']='$(self).find("button, input[type=submit], input[type=button]")'; |
699
|
699
|
} |
700
|
|
- if (! isset($parameters['jsCallback'])) { |
701
|
|
- $parameters['jsCallback'] = 'let event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
700
|
+ if (!isset($parameters['jsCallback'])) { |
|
701
|
+ $parameters['jsCallback']='let event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
702
|
702
|
} |
703
|
703
|
return $this->postFormOn('submit', $element, '', $formId, $responseElement, $parameters); |
704
|
704
|
} |
705
|
705
|
|
706
|
|
- private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
707
|
|
- $parameters['params'] = $params; |
|
706
|
+ private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
707
|
+ $parameters['params']=$params; |
708
|
708
|
return $this->_ajax('POST', $url, $responseElement, $parameters); |
709
|
709
|
} |
710
|
710
|
|
|
@@ -720,8 +720,8 @@ discard block |
|
|
block discarded – undo |
720
|
720
|
* @param array $parameters |
721
|
721
|
* default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
722
|
722
|
*/ |
723
|
|
- public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
724
|
|
- $parameters['immediatly'] = true; |
|
723
|
+ public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
724
|
+ $parameters['immediatly']=true; |
725
|
725
|
return $this->_post($url, $params, $responseElement, $parameters); |
726
|
726
|
} |
727
|
727
|
|
|
@@ -738,8 +738,8 @@ discard block |
|
|
block discarded – undo |
738
|
738
|
* @param array $parameters |
739
|
739
|
* default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
740
|
740
|
*/ |
741
|
|
- public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
742
|
|
- $parameters['immediatly'] = false; |
|
741
|
+ public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
742
|
+ $parameters['immediatly']=false; |
743
|
743
|
return $this->_post($url, $params, $responseElement, $parameters); |
744
|
744
|
} |
745
|
745
|
|
|
@@ -758,9 +758,9 @@ discard block |
|
|
block discarded – undo |
758
|
758
|
* @param array $parameters |
759
|
759
|
* 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) |
760
|
760
|
*/ |
761
|
|
- public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
762
|
|
- $parameters['method'] = 'post'; |
763
|
|
- $parameters['params'] = $params; |
|
761
|
+ public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
762
|
+ $parameters['method']='post'; |
|
763
|
+ $parameters['params']=$params; |
764
|
764
|
return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
765
|
765
|
} |
766
|
766
|
|
|
@@ -778,75 +778,75 @@ discard block |
|
|
block discarded – undo |
778
|
778
|
* @param array $parameters |
779
|
779
|
* 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) |
780
|
780
|
*/ |
781
|
|
- public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
781
|
+ public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
782
|
782
|
return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
783
|
783
|
} |
784
|
784
|
|
785
|
|
- private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
785
|
+ private function _postForm($url, $form, $responseElement, $parameters=[]) { |
786
|
786
|
if (isset($this->params['ajax'])) { |
787
|
787
|
extract($this->params['ajax']); |
788
|
788
|
} |
789
|
|
- $params = '{}'; |
790
|
|
- $validation = false; |
|
789
|
+ $params='{}'; |
|
790
|
+ $validation=false; |
791
|
791
|
\extract($parameters); |
792
|
|
- $async = ($async) ? 'true' : 'false'; |
793
|
|
- $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
794
|
|
- $retour = $this->_getAjaxUrl($url, $attr); |
795
|
|
- $form = $this->_getFormElement($form); |
796
|
|
- $retour .= "\n$('#'+" . $form . ").trigger('ajaxSubmit');"; |
797
|
|
- if (! isset($contentType) || $contentType != 'false') { |
798
|
|
- $retour .= "\nlet params=$('#'+" . $form . ").serialize();\n"; |
|
792
|
+ $async=($async) ? 'true' : 'false'; |
|
793
|
+ $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
794
|
+ $retour=$this->_getAjaxUrl($url, $attr); |
|
795
|
+ $form=$this->_getFormElement($form); |
|
796
|
+ $retour.="\n$('#'+".$form.").trigger('ajaxSubmit');"; |
|
797
|
+ if (!isset($contentType) || $contentType!='false') { |
|
798
|
+ $retour.="\nlet params=$('#'+".$form.").serialize();\n"; |
799
|
799
|
if (isset($params)) { |
800
|
|
- $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
800
|
+ $retour.="params+='&'+".self::_correctParams($params).";\n"; |
801
|
801
|
} |
802
|
802
|
} else { |
803
|
|
- $retour .= "\nlet params=new FormData($('#'+" . $form . ")[0]);\n"; |
|
803
|
+ $retour.="\nlet params=new FormData($('#'+".$form.")[0]);\n"; |
804
|
804
|
} |
805
|
|
- $responseElement = $this->_getResponseElement($responseElement); |
806
|
|
- $retour .= "let self=this;\n"; |
807
|
|
- $before = isset($before) ? $before : ""; |
808
|
|
- $retour .= $before; |
809
|
|
- if ($hasLoader === true) { |
|
805
|
+ $responseElement=$this->_getResponseElement($responseElement); |
|
806
|
+ $retour.="let self=this;\n"; |
|
807
|
+ $before=isset($before) ? $before : ""; |
|
808
|
+ $retour.=$before; |
|
809
|
+ if ($hasLoader===true) { |
810
|
810
|
$this->addLoading($retour, $responseElement, $ajaxLoader); |
811
|
|
- } elseif ($hasLoader === 'response') { |
|
811
|
+ } elseif ($hasLoader==='response') { |
812
|
812
|
$this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
813
|
|
- } elseif ($hasLoader === 'internal-x') { |
|
813
|
+ } elseif ($hasLoader==='internal-x') { |
814
|
814
|
$this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
815
|
|
- } elseif ($hasLoader === 'internal') { |
816
|
|
- $retour .= "\n$(this).addClass('loading');"; |
|
815
|
+ } elseif ($hasLoader==='internal') { |
|
816
|
+ $retour.="\n$(this).addClass('loading');"; |
817
|
817
|
} elseif (\is_string($hasLoader)) { |
818
|
|
- $retour .= "\n$hasLoader.addClass('loading');"; |
|
818
|
+ $retour.="\n$hasLoader.addClass('loading');"; |
819
|
819
|
} |
820
|
|
- $ajaxParameters = [ |
|
820
|
+ $ajaxParameters=[ |
821
|
821
|
"url" => "url", |
822
|
822
|
"method" => "'POST'", |
823
|
823
|
"data" => "params", |
824
|
824
|
"async" => $async |
825
|
825
|
]; |
826
|
826
|
if (isset($headers)) { |
827
|
|
- $ajaxParameters["headers"] = $headers; |
|
827
|
+ $ajaxParameters["headers"]=$headers; |
828
|
828
|
} |
829
|
829
|
if (isset($partial)) { |
830
|
|
- $ajaxParameters["xhr"] = "xhrProvider"; |
831
|
|
- $retour .= "let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
830
|
+ $ajaxParameters["xhr"]="xhrProvider"; |
|
831
|
+ $retour.="let xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
832
|
832
|
} |
833
|
833
|
$this->createAjaxParameters($ajaxParameters, $parameters); |
834
|
|
- $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
835
|
|
- $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) . "})"; |
|
834
|
+ $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
835
|
+ $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."})"; |
836
|
836
|
if (isset($error)) { |
837
|
|
- $retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})'; |
|
837
|
+ $retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})'; |
838
|
838
|
} |
839
|
|
- $retour .= '.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {' . ($always ?? '') . $this->removeLoader($hasLoader) . '})'; |
840
|
|
- $retour .= ";\n"; |
|
839
|
+ $retour.='.always(function( dataOrjqXHR, textStatus, jqXHROrerrorThrown ) {'.($always ?? '').$this->removeLoader($hasLoader).'})'; |
|
840
|
+ $retour.=";\n"; |
841
|
841
|
if ($validation) { |
842
|
|
- $retour = "$('#'+" . $form . ").validate({submitHandler: function(form) { |
843
|
|
- " . $retour . " |
|
842
|
+ $retour="$('#'+".$form.").validate({submitHandler: function(form) { |
|
843
|
+ " . $retour." |
844
|
844
|
}});\n"; |
845
|
|
- $retour .= "$('#'+" . $form . ").submit();\n"; |
|
845
|
+ $retour.="$('#'+".$form.").submit();\n"; |
846
|
846
|
} |
847
|
|
- $retour = $this->_addJsCondition($jsCondition, $retour); |
|
847
|
+ $retour=$this->_addJsCondition($jsCondition, $retour); |
848
|
848
|
if ($immediatly) |
849
|
|
- $this->jquery_code_for_compile[] = $retour; |
|
849
|
+ $this->jquery_code_for_compile[]=$retour; |
850
|
850
|
return $retour; |
851
|
851
|
} |
852
|
852
|
|
|
@@ -862,8 +862,8 @@ discard block |
|
|
block discarded – undo |
862
|
862
|
* @param array $parameters |
863
|
863
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
864
|
864
|
*/ |
865
|
|
- public function postForm($url, $form, $responseElement, $parameters = []) { |
866
|
|
- $parameters['immediatly'] = true; |
|
865
|
+ public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
866
|
+ $parameters['immediatly']=true; |
867
|
867
|
return $this->_postForm($url, $form, $responseElement, $parameters); |
868
|
868
|
} |
869
|
869
|
|
|
@@ -880,8 +880,8 @@ discard block |
|
|
block discarded – undo |
880
|
880
|
* @param array $parameters |
881
|
881
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
882
|
882
|
*/ |
883
|
|
- public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
884
|
|
- $parameters['immediatly'] = false; |
|
883
|
+ public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
884
|
+ $parameters['immediatly']=false; |
885
|
885
|
return $this->_postForm($url, $form, $responseElement, $parameters); |
886
|
886
|
} |
887
|
887
|
|
|
@@ -898,7 +898,7 @@ discard block |
|
|
block discarded – undo |
898
|
898
|
* @param array $parameters |
899
|
899
|
* 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) |
900
|
900
|
*/ |
901
|
|
- public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
901
|
+ public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
902
|
902
|
$this->setDefaultParameters($parameters, [ |
903
|
903
|
'preventDefault' => true, |
904
|
904
|
'stopPropagation' => true, |
|
@@ -920,11 +920,11 @@ discard block |
|
|
block discarded – undo |
920
|
920
|
* @param array $parameters |
921
|
921
|
* 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) |
922
|
922
|
*/ |
923
|
|
- public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
923
|
+ public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
924
|
924
|
return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
925
|
925
|
} |
926
|
926
|
|
927
|
|
- public function addCsrf($name = 'csrf-token') { |
|
927
|
+ public function addCsrf($name='csrf-token') { |
928
|
928
|
return " |
929
|
929
|
$.ajaxSetup({ |
930
|
930
|
beforeSend: function(xhr, settings) { |