|
@@ -14,210 +14,210 @@ discard block |
|
|
block discarded – undo |
|
14
|
14
|
*/ |
|
15
|
15
|
trait JsUtilsAjaxTrait { |
|
16
|
16
|
protected $ajaxTransition; |
|
17
|
|
- protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
|
17
|
+ protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
18
|
18
|
abstract public function getUrl($url); |
|
19
|
|
- abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true, $listenerOn=false); |
|
20
|
|
- abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
21
|
|
- protected function _ajax($method, $url, $responseElement = "", $parameters = [ ]) { |
|
22
|
|
- if (isset ( $this->params ["ajax"] )) { |
|
23
|
|
- extract ( $this->params ["ajax"] ); |
|
24
|
|
- } |
|
25
|
|
- extract ( $parameters ); |
|
26
|
|
- |
|
27
|
|
- $jsCallback = isset ( $jsCallback ) ? $jsCallback : ""; |
|
28
|
|
- $retour = $this->_getAjaxUrl ( $url, $attr ); |
|
29
|
|
- $originalSelector = $responseElement; |
|
30
|
|
- $responseElement = $this->_getResponseElement ( $responseElement ); |
|
31
|
|
- $retour .= "var self=this;\n"; |
|
32
|
|
- $before = isset ( $before ) ? $before : ""; |
|
33
|
|
- $retour .= $before; |
|
34
|
|
- if ($hasLoader === true && JString::isNotNull ( $responseElement )) { |
|
35
|
|
- $this->addLoading ( $retour, $responseElement, $ajaxLoader ); |
|
36
|
|
- } elseif ($hasLoader === 'response') { |
|
37
|
|
- $this->addResponseLoading ( $retour, $responseElement, $ajaxLoader ); |
|
38
|
|
- } elseif ($hasLoader === 'internal') { |
|
39
|
|
- $retour .= "\n$(this).addClass('loading');"; |
|
40
|
|
- } |
|
41
|
|
- $ajaxParameters = [ |
|
|
19
|
+ abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
|
20
|
+ abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
|
21
|
+ protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
|
22
|
+ if (isset ($this->params ["ajax"])) { |
|
|
23
|
+ extract($this->params ["ajax"]); |
|
|
24
|
+ } |
|
|
25
|
+ extract($parameters); |
|
|
26
|
+ |
|
|
27
|
+ $jsCallback=isset ($jsCallback) ? $jsCallback : ""; |
|
|
28
|
+ $retour=$this->_getAjaxUrl($url, $attr); |
|
|
29
|
+ $originalSelector=$responseElement; |
|
|
30
|
+ $responseElement=$this->_getResponseElement($responseElement); |
|
|
31
|
+ $retour.="var self=this;\n"; |
|
|
32
|
+ $before=isset ($before) ? $before : ""; |
|
|
33
|
+ $retour.=$before; |
|
|
34
|
+ if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
|
35
|
+ $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
|
36
|
+ } elseif ($hasLoader==='response') { |
|
|
37
|
+ $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
|
|
38
|
+ } elseif ($hasLoader==='internal') { |
|
|
39
|
+ $retour.="\n$(this).addClass('loading');"; |
|
|
40
|
+ } |
|
|
41
|
+ $ajaxParameters=[ |
|
42
|
42
|
"url" => "url", |
|
43
|
|
- "method" => "'" . \strtoupper ( $method ) . "'" |
|
|
43
|
+ "method" => "'".\strtoupper($method)."'" |
|
44
|
44
|
]; |
|
45
|
45
|
|
|
46
|
|
- $ajaxParameters ["async"] = ($async ? "true" : "false"); |
|
|
46
|
+ $ajaxParameters ["async"]=($async ? "true" : "false"); |
|
47
|
47
|
|
|
48
|
|
- if (isset ( $params )) { |
|
49
|
|
- $ajaxParameters ["data"] = self::_correctParams ( $params, $parameters ); |
|
|
48
|
+ if (isset ($params)) { |
|
|
49
|
+ $ajaxParameters ["data"]=self::_correctParams($params, $parameters); |
|
50
|
50
|
} |
|
51
|
|
- if (isset ( $headers )) { |
|
52
|
|
- $ajaxParameters ["headers"] = $headers; |
|
|
51
|
+ if (isset ($headers)) { |
|
|
52
|
+ $ajaxParameters ["headers"]=$headers; |
|
53
|
53
|
} |
|
54
|
|
- if (isset ( $partial )) { |
|
55
|
|
- $ajaxParameters ["xhr"] = "xhrProvider"; |
|
56
|
|
- $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
|
54
|
+ if (isset ($partial)) { |
|
|
55
|
+ $ajaxParameters ["xhr"]="xhrProvider"; |
|
|
56
|
+ $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
57
|
57
|
} |
|
58
|
|
- $this->createAjaxParameters ( $ajaxParameters, $parameters ); |
|
59
|
|
- $retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
60
|
|
- $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null) ) . "});\n"; |
|
|
58
|
+ $this->createAjaxParameters($ajaxParameters, $parameters); |
|
|
59
|
+ $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
|
60
|
+ $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
61
|
61
|
|
|
62
|
|
- $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
|
|
62
|
+ $retour=$this->_addJsCondition($jsCondition, $retour); |
|
63
|
63
|
if ($immediatly) |
|
64
|
|
- $this->jquery_code_for_compile [] = $retour; |
|
|
64
|
+ $this->jquery_code_for_compile []=$retour; |
|
65
|
65
|
return $retour; |
|
66
|
66
|
} |
|
67
|
67
|
protected function createAjaxParameters(&$original, $parameters) { |
|
68
|
|
- $validParameters = [ |
|
|
68
|
+ $validParameters=[ |
|
69
|
69
|
"contentType" => "%value%", |
|
70
|
70
|
"dataType" => "'%value%'", |
|
71
|
71
|
"beforeSend" => "function(jqXHR,settings){%value%}", |
|
72
|
72
|
"complete" => "function(jqXHR){%value%}", |
|
73
|
73
|
"processData" => "%value%" |
|
74
|
74
|
]; |
|
75
|
|
- foreach ( $validParameters as $param => $mask ) { |
|
76
|
|
- if (isset ( $parameters [$param] )) { |
|
77
|
|
- $original [$param] = \str_replace ( "%value%", $parameters [$param], $mask ); |
|
|
75
|
+ foreach ($validParameters as $param => $mask) { |
|
|
76
|
+ if (isset ($parameters [$param])) { |
|
|
77
|
+ $original [$param]=\str_replace("%value%", $parameters [$param], $mask); |
|
78
|
78
|
} |
|
79
|
79
|
} |
|
80
|
80
|
} |
|
81
|
81
|
protected function implodeAjaxParameters($ajaxParameters) { |
|
82
|
|
- $s = ''; |
|
83
|
|
- foreach ( $ajaxParameters as $k => $v ) { |
|
84
|
|
- if ($s !== '') { |
|
85
|
|
- $s .= ','; |
|
|
82
|
+ $s=''; |
|
|
83
|
+ foreach ($ajaxParameters as $k => $v) { |
|
|
84
|
+ if ($s!=='') { |
|
|
85
|
+ $s.=','; |
|
86
|
86
|
} |
|
87
|
|
- if (is_array ( $v )) { |
|
88
|
|
- $s .= "'{$k}':{" . self::implodeAjaxParameters ( $v ) . "}"; |
|
|
87
|
+ if (is_array($v)) { |
|
|
88
|
+ $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
89
|
89
|
} else { |
|
90
|
|
- $s .= "'{$k}':{$v}"; |
|
|
90
|
+ $s.="'{$k}':{$v}"; |
|
91
|
91
|
} |
|
92
|
92
|
} |
|
93
|
93
|
return $s; |
|
94
|
94
|
} |
|
95
|
95
|
protected function _addJsCondition($jsCondition, $jsSource) { |
|
96
|
|
- if (isset ( $jsCondition )) { |
|
97
|
|
- return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
|
96
|
+ if (isset ($jsCondition)) { |
|
|
97
|
+ return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
98
|
98
|
} |
|
99
|
99
|
return $jsSource; |
|
100
|
100
|
} |
|
101
|
101
|
protected function _getAjaxUrl($url, $attr) { |
|
102
|
|
- $url = $this->_correctAjaxUrl ( $url ); |
|
103
|
|
- $retour = "url='" . $url . "';"; |
|
104
|
|
- $slash = "/"; |
|
105
|
|
- if (JString::endswith ( $url, "/" ) === true) { |
|
106
|
|
- $slash = ""; |
|
107
|
|
- } |
|
108
|
|
- if (JString::isNotNull ( $attr )) { |
|
109
|
|
- if ($attr === "value") { |
|
110
|
|
- $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
111
|
|
- } elseif ($attr === "html") { |
|
112
|
|
- $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
113
|
|
- } elseif (\substr ( $attr, 0, 3 ) === "js:") { |
|
114
|
|
- $retour .= "url=url+'" . $slash . "'+" . \substr ( $attr, 3 ) . ";\n"; |
|
115
|
|
- } elseif ($attr !== null && $attr !== "") |
|
116
|
|
- $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
|
102
|
+ $url=$this->_correctAjaxUrl($url); |
|
|
103
|
+ $retour="url='".$url."';"; |
|
|
104
|
+ $slash="/"; |
|
|
105
|
+ if (JString::endswith($url, "/")===true) { |
|
|
106
|
+ $slash=""; |
|
|
107
|
+ } |
|
|
108
|
+ if (JString::isNotNull($attr)) { |
|
|
109
|
+ if ($attr==="value") { |
|
|
110
|
+ $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
|
111
|
+ } elseif ($attr==="html") { |
|
|
112
|
+ $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
|
113
|
+ } elseif (\substr($attr, 0, 3)==="js:") { |
|
|
114
|
+ $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
|
115
|
+ } elseif ($attr!==null && $attr!=="") |
|
|
116
|
+ $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
117
|
117
|
} |
|
118
|
118
|
return $retour; |
|
119
|
119
|
} |
|
120
|
120
|
protected function onPopstate() { |
|
121
|
121
|
return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
|
122
|
122
|
} |
|
123
|
|
- protected function autoActiveLinks($previousURL = "window.location.href") { |
|
124
|
|
- $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
125
|
|
- $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
|
123
|
+ protected function autoActiveLinks($previousURL="window.location.href") { |
|
|
124
|
+ $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
|
125
|
+ $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
126
|
126
|
return $result; |
|
127
|
127
|
} |
|
128
|
|
- protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
129
|
|
- $retour = ""; |
|
130
|
|
- $call = null; |
|
131
|
|
- if (JString::isNotNull ( $responseElement )) { |
|
132
|
|
- if (isset ( $ajaxTransition )) { |
|
133
|
|
- $call = $this->setAjaxDataCall ( $ajaxTransition ); |
|
134
|
|
- } elseif (isset ( $this->ajaxTransition )) { |
|
135
|
|
- $call = $this->ajaxTransition; |
|
|
128
|
+ protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
|
129
|
+ $retour=""; |
|
|
130
|
+ $call=null; |
|
|
131
|
+ if (JString::isNotNull($responseElement)) { |
|
|
132
|
+ if (isset ($ajaxTransition)) { |
|
|
133
|
+ $call=$this->setAjaxDataCall($ajaxTransition); |
|
|
134
|
+ } elseif (isset ($this->ajaxTransition)) { |
|
|
135
|
+ $call=$this->ajaxTransition; |
|
136
|
136
|
} |
|
137
|
|
- if (\is_callable ( $call )) |
|
138
|
|
- $retour = "\t" . $call ( $responseElement, $jqueryDone ) . ";\n"; |
|
|
137
|
+ if (\is_callable($call)) |
|
|
138
|
+ $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
139
|
139
|
else |
|
140
|
|
- $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
|
140
|
+ $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
141
|
141
|
} |
|
142
|
|
- if (isset ( $history )) { |
|
|
142
|
+ if (isset ($history)) { |
|
143
|
143
|
if ($this->params ["autoActiveLinks"]) { |
|
144
|
|
- $retour .= $this->autoActiveLinks ( "url" ); |
|
|
144
|
+ $retour.=$this->autoActiveLinks("url"); |
|
145
|
145
|
} |
|
146
|
|
- $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value ( $history ) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
|
146
|
+ $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
147
|
147
|
} |
|
148
|
|
- if ($hasLoader === "internal") { |
|
149
|
|
- $retour .= "\n$(self).removeClass('loading');"; |
|
|
148
|
+ if ($hasLoader==="internal") { |
|
|
149
|
+ $retour.="\n$(self).removeClass('loading');"; |
|
150
|
150
|
} |
|
151
|
|
- $retour .= "\t" . $jsCallback . "\n"; |
|
|
151
|
+ $retour.="\t".$jsCallback."\n"; |
|
152
|
152
|
return $retour; |
|
153
|
153
|
} |
|
154
|
154
|
protected function _getResponseElement($responseElement) { |
|
155
|
|
- if (JString::isNotNull ( $responseElement )) { |
|
156
|
|
- $responseElement = Javascript::prep_jquery_selector ( $responseElement ); |
|
|
155
|
+ if (JString::isNotNull($responseElement)) { |
|
|
156
|
+ $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
157
|
157
|
} |
|
158
|
158
|
return $responseElement; |
|
159
|
159
|
} |
|
160
|
160
|
protected function _correctAjaxUrl($url) { |
|
161
|
|
- if ($url !== "/" && JString::endsWith ( $url, "/" ) === true) |
|
162
|
|
- $url = substr ( $url, 0, strlen ( $url ) - 1 ); |
|
163
|
|
- if (strncmp ( $url, 'http://', 7 ) != 0 && strncmp ( $url, 'https://', 8 ) != 0) { |
|
164
|
|
- $url = $this->getUrl ( $url ); |
|
|
161
|
+ if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
|
162
|
+ $url=substr($url, 0, strlen($url)-1); |
|
|
163
|
+ if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
|
164
|
+ $url=$this->getUrl($url); |
|
165
|
165
|
} |
|
166
|
166
|
return $url; |
|
167
|
167
|
} |
|
168
|
|
- public static function _correctParams($params, $ajaxParameters = [ ]) { |
|
169
|
|
- if (JString::isNull ( $params )) { |
|
|
168
|
+ public static function _correctParams($params, $ajaxParameters=[]) { |
|
|
169
|
+ if (JString::isNull($params)) { |
|
170
|
170
|
return ""; |
|
171
|
171
|
} |
|
172
|
|
- if (\preg_match ( "@^\{.*?\}$@", $params )) { |
|
173
|
|
- if (! isset ( $ajaxParameters ['contentType'] ) || ! JString::contains ( $ajaxParameters ['contentType'], 'json' )) { |
|
174
|
|
- return '$.param(' . $params . ')'; |
|
|
172
|
+ if (\preg_match("@^\{.*?\}$@", $params)) { |
|
|
173
|
+ if (!isset ($ajaxParameters ['contentType']) || !JString::contains($ajaxParameters ['contentType'], 'json')) { |
|
|
174
|
+ return '$.param('.$params.')'; |
|
175
|
175
|
} else { |
|
176
|
|
- return 'JSON.stringify(' . $params . ')'; |
|
|
176
|
+ return 'JSON.stringify('.$params.')'; |
|
177
|
177
|
} |
|
178
|
178
|
} |
|
179
|
179
|
return $params; |
|
180
|
180
|
} |
|
181
|
181
|
public static function _implodeParams($parameters) { |
|
182
|
|
- $allParameters = [ ]; |
|
183
|
|
- foreach ( $parameters as $params ) { |
|
184
|
|
- if (isset ( $params )) |
|
185
|
|
- $allParameters [] = self::_correctParams ( $params ); |
|
|
182
|
+ $allParameters=[]; |
|
|
183
|
+ foreach ($parameters as $params) { |
|
|
184
|
+ if (isset ($params)) |
|
|
185
|
+ $allParameters []=self::_correctParams($params); |
|
186
|
186
|
} |
|
187
|
|
- return \implode ( "+'&'+", $allParameters ); |
|
|
187
|
+ return \implode("+'&'+", $allParameters); |
|
188
|
188
|
} |
|
189
|
|
- protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
190
|
|
- if (! isset ( $ajaxLoader )) { |
|
191
|
|
- $ajaxLoader = $this->ajaxLoader; |
|
|
189
|
+ protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
|
190
|
+ if (!isset ($ajaxLoader)) { |
|
|
191
|
+ $ajaxLoader=$this->ajaxLoader; |
|
192
|
192
|
} |
|
193
|
|
- $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
194
|
|
- $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
|
193
|
+ $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
|
194
|
+ $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
195
|
195
|
} |
|
196
|
|
- protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
197
|
|
- if (! isset ( $ajaxLoader )) { |
|
198
|
|
- $ajaxLoader = $this->ajaxLoader; |
|
|
196
|
+ protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
|
197
|
+ if (!isset ($ajaxLoader)) { |
|
|
198
|
+ $ajaxLoader=$this->ajaxLoader; |
|
199
|
199
|
} |
|
200
|
|
- $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
201
|
|
- $retour .= "{$responseElement}.empty();\n"; |
|
202
|
|
- $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
|
200
|
+ $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
|
201
|
+ $retour.="{$responseElement}.empty();\n"; |
|
|
202
|
+ $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
203
|
203
|
} |
|
204
|
204
|
protected function setAjaxDataCall($params) { |
|
205
|
|
- $result = null; |
|
206
|
|
- if (! \is_callable ( $params )) { |
|
207
|
|
- $result = function ($responseElement, $jqueryDone = "html") use ($params) { |
|
208
|
|
- return AjaxTransition::{$params} ( $responseElement, $jqueryDone ); |
|
|
205
|
+ $result=null; |
|
|
206
|
+ if (!\is_callable($params)) { |
|
|
207
|
+ $result=function($responseElement, $jqueryDone="html") use ($params) { |
|
|
208
|
+ return AjaxTransition::{$params} ($responseElement, $jqueryDone); |
|
209
|
209
|
}; |
|
210
|
210
|
} |
|
211
|
211
|
return $result; |
|
212
|
212
|
} |
|
213
|
213
|
protected function setDefaultParameters(&$parameters, $default) { |
|
214
|
|
- foreach ( $default as $k => $v ) { |
|
215
|
|
- if (! isset ( $parameters [$k] )) |
|
216
|
|
- $parameters [$k] = $v; |
|
|
214
|
+ foreach ($default as $k => $v) { |
|
|
215
|
+ if (!isset ($parameters [$k])) |
|
|
216
|
+ $parameters [$k]=$v; |
|
217
|
217
|
} |
|
218
|
218
|
} |
|
219
|
219
|
public function setAjaxLoader($loader) { |
|
220
|
|
- $this->ajaxLoader = $loader; |
|
|
220
|
+ $this->ajaxLoader=$loader; |
|
221
|
221
|
} |
|
222
|
222
|
|
|
223
|
223
|
/** |
|
@@ -228,8 +228,8 @@ discard block |
|
|
block discarded – undo |
|
228
|
228
|
* @param string $responseElement |
|
229
|
229
|
* selector of the HTML element displaying the answer |
|
230
|
230
|
*/ |
|
231
|
|
- private function _get($url, $responseElement = "", $parameters = [ ]) { |
|
232
|
|
- return $this->_ajax ( "get", $url, $responseElement, $parameters ); |
|
|
231
|
+ private function _get($url, $responseElement="", $parameters=[]) { |
|
|
232
|
+ return $this->_ajax("get", $url, $responseElement, $parameters); |
|
233
|
233
|
} |
|
234
|
234
|
|
|
235
|
235
|
/** |
|
@@ -242,9 +242,9 @@ discard block |
|
|
block discarded – undo |
|
242
|
242
|
* @param array $parameters |
|
243
|
243
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
244
|
244
|
*/ |
|
245
|
|
- public function get($url, $responseElement = "", $parameters = [ ]) { |
|
246
|
|
- $parameters ["immediatly"] = true; |
|
247
|
|
- return $this->_get ( $url, $responseElement, $parameters ); |
|
|
245
|
+ public function get($url, $responseElement="", $parameters=[]) { |
|
|
246
|
+ $parameters ["immediatly"]=true; |
|
|
247
|
+ return $this->_get($url, $responseElement, $parameters); |
|
248
|
248
|
} |
|
249
|
249
|
|
|
250
|
250
|
/** |
|
@@ -259,9 +259,9 @@ discard block |
|
|
block discarded – undo |
|
259
|
259
|
* @param array $parameters |
|
260
|
260
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
261
|
261
|
*/ |
|
262
|
|
- public function ajax($method, $url, $responseElement = "", $parameters = [ ]) { |
|
263
|
|
- $parameters ["immediatly"] = true; |
|
264
|
|
- return $this->_ajax ( $method, $url, $responseElement, $parameters ); |
|
|
262
|
+ public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
|
263
|
+ $parameters ["immediatly"]=true; |
|
|
264
|
+ return $this->_ajax($method, $url, $responseElement, $parameters); |
|
265
|
265
|
} |
|
266
|
266
|
|
|
267
|
267
|
/** |
|
@@ -282,8 +282,8 @@ discard block |
|
|
block discarded – undo |
|
282
|
282
|
* $immediatly |
|
283
|
283
|
* @return string |
|
284
|
284
|
*/ |
|
285
|
|
- public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = "", $parameters = [ ], $immediatly = true) { |
|
286
|
|
- return $this->interval ( $this->ajaxDeferred ( $method, $url, $responseElement, $parameters ), $interval, $globalName, $immediatly ); |
|
|
285
|
+ public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[], $immediatly=true) { |
|
|
286
|
+ return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
|
287
|
287
|
} |
|
288
|
288
|
|
|
289
|
289
|
/** |
|
@@ -298,9 +298,9 @@ discard block |
|
|
block discarded – undo |
|
298
|
298
|
* @param array $parameters |
|
299
|
299
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
300
|
300
|
*/ |
|
301
|
|
- public function ajaxDeferred($method, $url, $responseElement = "", $parameters = [ ]) { |
|
302
|
|
- $parameters ["immediatly"] = false; |
|
303
|
|
- return $this->_ajax ( $method, $url, $responseElement, $parameters ); |
|
|
301
|
+ public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
|
302
|
+ $parameters ["immediatly"]=false; |
|
|
303
|
+ return $this->_ajax($method, $url, $responseElement, $parameters); |
|
304
|
304
|
} |
|
305
|
305
|
|
|
306
|
306
|
/** |
|
@@ -313,16 +313,16 @@ discard block |
|
|
block discarded – undo |
|
313
|
313
|
* @param array $parameters |
|
314
|
314
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
|
315
|
315
|
*/ |
|
316
|
|
- private function _json($url, $method = "get", $parameters = [ ]) { |
|
317
|
|
- $parameters = \array_merge ( $parameters, [ |
|
|
316
|
+ private function _json($url, $method="get", $parameters=[]) { |
|
|
317
|
+ $parameters=\array_merge($parameters, [ |
|
318
|
318
|
"hasLoader" => false |
|
319
|
|
- ] ); |
|
320
|
|
- $jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : ""; |
|
321
|
|
- $context = isset ( $parameters ['context'] ) ? $parameters ['context'] : "document"; |
|
322
|
|
- $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"; |
|
323
|
|
- $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
324
|
|
- $parameters ["jsCallback"] = $retour; |
|
325
|
|
- return $this->_ajax ( $method, $url, null, $parameters ); |
|
|
319
|
+ ]); |
|
|
320
|
+ $jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : ""; |
|
|
321
|
+ $context=isset ($parameters ['context']) ? $parameters ['context'] : "document"; |
|
|
322
|
+ $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"; |
|
|
323
|
+ $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
|
324
|
+ $parameters ["jsCallback"]=$retour; |
|
|
325
|
+ return $this->_ajax($method, $url, null, $parameters); |
|
326
|
326
|
} |
|
327
|
327
|
|
|
328
|
328
|
/** |
|
@@ -335,8 +335,8 @@ discard block |
|
|
block discarded – undo |
|
335
|
335
|
* @param array $parameters |
|
336
|
336
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
|
337
|
337
|
*/ |
|
338
|
|
- public function json($url, $method = "get", $parameters = [ ]) { |
|
339
|
|
- return $this->_json ( $url, $method, $parameters ); |
|
|
338
|
+ public function json($url, $method="get", $parameters=[]) { |
|
|
339
|
+ return $this->_json($url, $method, $parameters); |
|
340
|
340
|
} |
|
341
|
341
|
|
|
342
|
342
|
/** |
|
@@ -351,14 +351,14 @@ discard block |
|
|
block discarded – undo |
|
351
|
351
|
* @param array $parameters |
|
352
|
352
|
* default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
|
353
|
353
|
*/ |
|
354
|
|
- public function jsonOn($event, $element, $url, $method = "get", $parameters = array ()) { |
|
355
|
|
- $this->setDefaultParameters ( $parameters, [ |
|
|
354
|
+ public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
|
355
|
+ $this->setDefaultParameters($parameters, [ |
|
356
|
356
|
"preventDefault" => true, |
|
357
|
357
|
"stopPropagation" => true, |
|
358
|
358
|
"immediatly" => true, |
|
359
|
359
|
'listenerOn'=>false |
|
360
|
|
- ] ); |
|
361
|
|
- return $this->_add_event ( $element, $this->jsonDeferred ( $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ,$parameters['listenerOn']); |
|
|
360
|
+ ]); |
|
|
361
|
+ return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
362
|
362
|
} |
|
363
|
363
|
|
|
364
|
364
|
/** |
|
@@ -371,9 +371,9 @@ 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
|
|
- public function jsonDeferred($url, $method = "get", $parameters = [ ]) { |
|
375
|
|
- $parameters ["immediatly"] = false; |
|
376
|
|
- return $this->_json ( $url, $method, $parameters ); |
|
|
374
|
+ public function jsonDeferred($url, $method="get", $parameters=[]) { |
|
|
375
|
+ $parameters ["immediatly"]=false; |
|
|
376
|
+ return $this->_json($url, $method, $parameters); |
|
377
|
377
|
} |
|
378
|
378
|
|
|
379
|
379
|
/** |
|
@@ -387,30 +387,30 @@ discard block |
|
|
block discarded – undo |
|
387
|
387
|
* @param array $parameters |
|
388
|
388
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
|
389
|
389
|
*/ |
|
390
|
|
- private function _jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) { |
|
391
|
|
- $parameters = \array_merge ( $parameters, [ |
|
|
390
|
+ private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
|
391
|
+ $parameters=\array_merge($parameters, [ |
|
392
|
392
|
"hasLoader" => false |
|
393
|
|
- ] ); |
|
394
|
|
- $rowClass = isset ( $parameters ['rowClass'] ) ? $parameters ['rowClass'] : "_json"; |
|
395
|
|
- $jsCallback = isset ( $parameters ['jsCallback'] ) ? $parameters ['jsCallback'] : ""; |
|
396
|
|
- $context = isset ( $parameters ['context'] ) ? $parameters ['context'] : null; |
|
397
|
|
- if ($context === null) { |
|
398
|
|
- $parent = "$('" . $maskSelector . "').parent()"; |
|
399
|
|
- $newElm = "$('#'+newId)"; |
|
|
393
|
+ ]); |
|
|
394
|
+ $rowClass=isset ($parameters ['rowClass']) ? $parameters ['rowClass'] : "_json"; |
|
|
395
|
+ $jsCallback=isset ($parameters ['jsCallback']) ? $parameters ['jsCallback'] : ""; |
|
|
396
|
+ $context=isset ($parameters ['context']) ? $parameters ['context'] : null; |
|
|
397
|
+ if ($context===null) { |
|
|
398
|
+ $parent="$('".$maskSelector."').parent()"; |
|
|
399
|
+ $newElm="$('#'+newId)"; |
|
400
|
400
|
} else { |
|
401
|
|
- $parent = $context; |
|
402
|
|
- $newElm = $context . ".find('#'+newId)"; |
|
|
401
|
+ $parent=$context; |
|
|
402
|
+ $newElm=$context.".find('#'+newId)"; |
|
403
|
403
|
} |
|
404
|
|
- $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
405
|
|
- $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
406
|
|
- $retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n" . "\tvar created=false;var maskElm=$('" . $maskSelector . "').first();maskElm.hide();" . "\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;" . "\tvar newElm=" . $newElm . ";\n" . "\tif(!newElm.length){\n" . "\t\tnewElm=maskElm.clone(); |
|
|
404
|
+ $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
|
405
|
+ $retour=$parent.".find('.{$rowClass}').remove();"; |
|
|
406
|
+ $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\n$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
|
407
|
407
|
newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
|
408
|
|
- $retour .= $appendTo; |
|
409
|
|
- $retour .= "\t}\n" . "\tfor(var key in value){\n" . "\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n" . "\t\t\tif(html.indexOf('__'+key+'__')>-1){\n" . "\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n" . "\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n" . "\t\t\t}\n" . "\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n" . "\t\t\tvar selElm=$(sel,newElm);\n" . "\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n" . "\t\t}\n" . "}\n" . "\t$(newElm).show(true);" . "\n" . "\t$(newElm).removeClass('hide');" . "});\n"; |
|
410
|
|
- $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
411
|
|
- $retour .= "\t" . $jsCallback; |
|
412
|
|
- $parameters ["jsCallback"] = $retour; |
|
413
|
|
- return $this->_ajax ( $method, $url, null, $parameters ); |
|
|
408
|
+ $retour.=$appendTo; |
|
|
409
|
+ $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
|
|
410
|
+ $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
|
411
|
+ $retour.="\t".$jsCallback; |
|
|
412
|
+ $parameters ["jsCallback"]=$retour; |
|
|
413
|
+ return $this->_ajax($method, $url, null, $parameters); |
|
414
|
414
|
} |
|
415
|
415
|
|
|
416
|
416
|
/** |
|
@@ -424,8 +424,8 @@ discard block |
|
|
block discarded – undo |
|
424
|
424
|
* @param array $parameters |
|
425
|
425
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
|
426
|
426
|
*/ |
|
427
|
|
- public function jsonArray($maskSelector, $url, $method = "get", $parameters = [ ]) { |
|
428
|
|
- return $this->_jsonArray ( $maskSelector, $url, $method, $parameters ); |
|
|
427
|
+ public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
|
428
|
+ return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
429
|
429
|
} |
|
430
|
430
|
|
|
431
|
431
|
/** |
|
@@ -439,9 +439,9 @@ discard block |
|
|
block discarded – undo |
|
439
|
439
|
* @param array $parameters |
|
440
|
440
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
|
441
|
441
|
*/ |
|
442
|
|
- public function jsonArrayDeferred($maskSelector, $url, $method = "get", $parameters = [ ]) { |
|
443
|
|
- $parameters ["immediatly"] = false; |
|
444
|
|
- return $this->jsonArray ( $maskSelector, $url, $method, $parameters ); |
|
|
442
|
+ public function jsonArrayDeferred($maskSelector, $url, $method="get", $parameters=[]) { |
|
|
443
|
+ $parameters ["immediatly"]=false; |
|
|
444
|
+ return $this->jsonArray($maskSelector, $url, $method, $parameters); |
|
445
|
445
|
} |
|
446
|
446
|
|
|
447
|
447
|
/** |
|
@@ -456,14 +456,14 @@ discard block |
|
|
block discarded – undo |
|
456
|
456
|
* @param array $parameters |
|
457
|
457
|
* default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
|
458
|
458
|
*/ |
|
459
|
|
- public function jsonArrayOn($event, $element, $maskSelector, $url, $method = "get", $parameters = array ()) { |
|
460
|
|
- $this->setDefaultParameters ( $parameters, [ |
|
|
459
|
+ public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
|
460
|
+ $this->setDefaultParameters($parameters, [ |
|
461
|
461
|
"preventDefault" => true, |
|
462
|
462
|
"stopPropagation" => true, |
|
463
|
463
|
"immediatly" => true, |
|
464
|
464
|
'listenerOn'=>false |
|
465
|
|
- ] ); |
|
466
|
|
- return $this->_add_event ( $element, $this->jsonArrayDeferred ( $maskSelector, $url, $method, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ,$parameters['listenerOn']); |
|
|
465
|
+ ]); |
|
|
466
|
+ return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
467
|
467
|
} |
|
468
|
468
|
|
|
469
|
469
|
/** |
|
@@ -477,9 +477,9 @@ discard block |
|
|
block discarded – undo |
|
477
|
477
|
* @param array $parameters |
|
478
|
478
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
479
|
479
|
*/ |
|
480
|
|
- public function getDeferred($url, $responseElement = "", $parameters = [ ]) { |
|
481
|
|
- $parameters ["immediatly"] = false; |
|
482
|
|
- return $this->_get ( $url, $responseElement, $parameters ); |
|
|
480
|
+ public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
|
481
|
+ $parameters ["immediatly"]=false; |
|
|
482
|
+ return $this->_get($url, $responseElement, $parameters); |
|
483
|
483
|
} |
|
484
|
484
|
|
|
485
|
485
|
/** |
|
@@ -497,9 +497,9 @@ discard block |
|
|
block discarded – undo |
|
497
|
497
|
* @param array $parameters |
|
498
|
498
|
* 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) |
|
499
|
499
|
*/ |
|
500
|
|
- public function getOn($event, $element, $url, $responseElement = "", $parameters = array ()) { |
|
|
500
|
+ public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
501
|
501
|
$parameters['method']='get'; |
|
502
|
|
- return $this->ajaxOn($event, $element, $url,$responseElement,$parameters); |
|
|
502
|
+ return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
|
503
|
503
|
} |
|
504
|
504
|
|
|
505
|
505
|
/** |
|
@@ -517,15 +517,15 @@ discard block |
|
|
block discarded – undo |
|
517
|
517
|
* @param array $parameters |
|
518
|
518
|
* 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) |
|
519
|
519
|
*/ |
|
520
|
|
- public function ajaxOn($event, $element, $url, $responseElement = "", $parameters = array ()) { |
|
521
|
|
- $this->setDefaultParameters ( $parameters, [ |
|
|
520
|
+ public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
|
521
|
+ $this->setDefaultParameters($parameters, [ |
|
522
|
522
|
"preventDefault" => true, |
|
523
|
523
|
"stopPropagation" => true, |
|
524
|
524
|
"immediatly" => true, |
|
525
|
525
|
"method" => "get", |
|
526
|
526
|
"listenerOn"=>false |
|
527
|
|
- ] ); |
|
528
|
|
- return $this->_add_event ( $element, $this->ajaxDeferred ( $parameters ["method"], $url, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"],$parameters['listenerOn'] ); |
|
|
527
|
+ ]); |
|
|
528
|
+ return $this->_add_event($element, $this->ajaxDeferred($parameters ["method"], $url, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
529
|
529
|
} |
|
530
|
530
|
|
|
531
|
531
|
/** |
|
@@ -541,8 +541,8 @@ discard block |
|
|
block discarded – undo |
|
541
|
541
|
* @param array $parameters |
|
542
|
542
|
* 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) |
|
543
|
543
|
*/ |
|
544
|
|
- public function ajaxOnClick($element, $url, $responseElement = "", $parameters = array ()) { |
|
545
|
|
- return $this->ajaxOn ( "click", $element, $url, $responseElement, $parameters ); |
|
|
544
|
+ public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
|
545
|
+ return $this->ajaxOn("click", $element, $url, $responseElement, $parameters); |
|
546
|
546
|
} |
|
547
|
547
|
|
|
548
|
548
|
/** |
|
@@ -558,8 +558,8 @@ discard block |
|
|
block discarded – undo |
|
558
|
558
|
* @param array $parameters |
|
559
|
559
|
* 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) |
|
560
|
560
|
*/ |
|
561
|
|
- public function getOnClick($element, $url, $responseElement = "", $parameters = array ()) { |
|
562
|
|
- return $this->getOn ( "click", $element, $url, $responseElement, $parameters ); |
|
|
561
|
+ public function getOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
|
562
|
+ return $this->getOn("click", $element, $url, $responseElement, $parameters); |
|
563
|
563
|
} |
|
564
|
564
|
|
|
565
|
565
|
/** |
|
@@ -573,17 +573,17 @@ discard block |
|
|
block discarded – undo |
|
573
|
573
|
* 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) |
|
574
|
574
|
* @return $this |
|
575
|
575
|
*/ |
|
576
|
|
- public function getHref($element, $responseElement = "", $parameters = array ()) { |
|
577
|
|
- $parameters ["attr"] = "href"; |
|
578
|
|
- if (JString::isNull ( $responseElement )) { |
|
579
|
|
- $responseElement = '%$(self).attr("data-target")%'; |
|
|
576
|
+ public function getHref($element, $responseElement="", $parameters=array()) { |
|
|
577
|
+ $parameters ["attr"]="href"; |
|
|
578
|
+ if (JString::isNull($responseElement)) { |
|
|
579
|
+ $responseElement='%$(self).attr("data-target")%'; |
|
580
|
580
|
} else { |
|
581
|
|
- $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
|
581
|
+ $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
582
|
582
|
} |
|
583
|
|
- if (! isset ( $parameters ["historize"] )) { |
|
584
|
|
- $parameters ["historize"] = true; |
|
|
583
|
+ if (!isset ($parameters ["historize"])) { |
|
|
584
|
+ $parameters ["historize"]=true; |
|
585
|
585
|
} |
|
586
|
|
- return $this->getOnClick ( $element, "", $responseElement, $parameters ); |
|
|
586
|
+ return $this->getOnClick($element, "", $responseElement, $parameters); |
|
587
|
587
|
} |
|
588
|
588
|
|
|
589
|
589
|
/** |
|
@@ -597,21 +597,21 @@ discard block |
|
|
block discarded – undo |
|
597
|
597
|
* 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) |
|
598
|
598
|
* @return $this |
|
599
|
599
|
*/ |
|
600
|
|
- public function postHref($element, $responseElement = "", $parameters = array ()) { |
|
601
|
|
- $parameters ["attr"] = "href"; |
|
602
|
|
- if (JString::isNull ( $responseElement )) { |
|
603
|
|
- $responseElement = '%$(this).attr("data-target")%'; |
|
|
600
|
+ public function postHref($element, $responseElement="", $parameters=array()) { |
|
|
601
|
+ $parameters ["attr"]="href"; |
|
|
602
|
+ if (JString::isNull($responseElement)) { |
|
|
603
|
+ $responseElement='%$(this).attr("data-target")%'; |
|
604
|
604
|
} else { |
|
605
|
|
- $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
|
605
|
+ $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
606
|
606
|
} |
|
607
|
|
- if (! isset ( $parameters ["historize"] )) { |
|
608
|
|
- $parameters ["historize"] = true; |
|
|
607
|
+ if (!isset ($parameters ["historize"])) { |
|
|
608
|
+ $parameters ["historize"]=true; |
|
609
|
609
|
} |
|
610
|
|
- return $this->postOnClick ( $element, "", "{}", $responseElement, $parameters ); |
|
|
610
|
+ return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
611
|
611
|
} |
|
612
|
|
- private function _post($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
613
|
|
- $parameters ["params"] = $params; |
|
614
|
|
- return $this->_ajax ( "POST", $url, $responseElement, $parameters ); |
|
|
612
|
+ private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
|
613
|
+ $parameters ["params"]=$params; |
|
|
614
|
+ return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
615
|
615
|
} |
|
616
|
616
|
|
|
617
|
617
|
/** |
|
@@ -626,9 +626,9 @@ discard block |
|
|
block discarded – undo |
|
626
|
626
|
* @param array $parameters |
|
627
|
627
|
* default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
628
|
628
|
*/ |
|
629
|
|
- public function post($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
630
|
|
- $parameters ['immediatly'] = true; |
|
631
|
|
- return $this->_post ( $url, $params, $responseElement, $parameters ); |
|
|
629
|
+ public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
|
630
|
+ $parameters ['immediatly']=true; |
|
|
631
|
+ return $this->_post($url, $params, $responseElement, $parameters); |
|
632
|
632
|
} |
|
633
|
633
|
|
|
634
|
634
|
/** |
|
@@ -644,9 +644,9 @@ discard block |
|
|
block discarded – undo |
|
644
|
644
|
* @param array $parameters |
|
645
|
645
|
* default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
646
|
646
|
*/ |
|
647
|
|
- public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = [ ]) { |
|
648
|
|
- $parameters ["immediatly"] = false; |
|
649
|
|
- return $this->_post ( $url, $params, $responseElement, $parameters ); |
|
|
647
|
+ public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
|
648
|
+ $parameters ["immediatly"]=false; |
|
|
649
|
+ return $this->_post($url, $params, $responseElement, $parameters); |
|
650
|
650
|
} |
|
651
|
651
|
|
|
652
|
652
|
/** |
|
@@ -664,9 +664,9 @@ discard block |
|
|
block discarded – undo |
|
664
|
664
|
* @param array $parameters |
|
665
|
665
|
* 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) |
|
666
|
666
|
*/ |
|
667
|
|
- public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array ()) { |
|
|
667
|
+ public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
668
|
668
|
$parameters['method']='post'; |
|
669
|
|
- return $this->ajaxOn($event, $element, $url,$responseElement,$parameters); |
|
|
669
|
+ return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
|
670
|
670
|
} |
|
671
|
671
|
|
|
672
|
672
|
/** |
|
@@ -683,65 +683,65 @@ discard block |
|
|
block discarded – undo |
|
683
|
683
|
* @param array $parameters |
|
684
|
684
|
* 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) |
|
685
|
685
|
*/ |
|
686
|
|
- public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array ()) { |
|
687
|
|
- return $this->postOn ( 'click', $element, $url, $params, $responseElement, $parameters ); |
|
688
|
|
- } |
|
689
|
|
- private function _postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
690
|
|
- if (isset ( $this->params ['ajax'] )) { |
|
691
|
|
- extract ( $this->params ['ajax'] ); |
|
692
|
|
- } |
|
693
|
|
- $params = '{}'; |
|
694
|
|
- $validation = false; |
|
695
|
|
- \extract ( $parameters ); |
|
696
|
|
- $async = ($async) ? 'true' : 'false'; |
|
697
|
|
- $jsCallback = isset ( $jsCallback ) ? $jsCallback : ""; |
|
698
|
|
- $retour = $this->_getAjaxUrl ( $url, $attr ); |
|
699
|
|
- $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
700
|
|
- if (! isset ( $contentType ) || $contentType != 'false') { |
|
701
|
|
- $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
702
|
|
- if (isset ( $params )) { |
|
703
|
|
- $retour .= "params+='&'+" . self::_correctParams ( $params ) . ";\n"; |
|
|
686
|
+ public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
|
687
|
+ return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
|
|
688
|
+ } |
|
|
689
|
+ private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
|
690
|
+ if (isset ($this->params ['ajax'])) { |
|
|
691
|
+ extract($this->params ['ajax']); |
|
|
692
|
+ } |
|
|
693
|
+ $params='{}'; |
|
|
694
|
+ $validation=false; |
|
|
695
|
+ \extract($parameters); |
|
|
696
|
+ $async=($async) ? 'true' : 'false'; |
|
|
697
|
+ $jsCallback=isset ($jsCallback) ? $jsCallback : ""; |
|
|
698
|
+ $retour=$this->_getAjaxUrl($url, $attr); |
|
|
699
|
+ $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
|
700
|
+ if (!isset ($contentType) || $contentType!='false') { |
|
|
701
|
+ $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
|
702
|
+ if (isset ($params)) { |
|
|
703
|
+ $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
704
|
704
|
} |
|
705
|
705
|
} else { |
|
706
|
|
- $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
707
|
|
- } |
|
708
|
|
- $responseElement = $this->_getResponseElement ( $responseElement ); |
|
709
|
|
- $retour .= "var self=this;\n"; |
|
710
|
|
- $before = isset ( $before ) ? $before : ""; |
|
711
|
|
- $retour .= $before; |
|
712
|
|
- if ($hasLoader === true) { |
|
713
|
|
- $this->addLoading ( $retour, $responseElement, $ajaxLoader ); |
|
714
|
|
- } elseif ($hasLoader === 'response') { |
|
715
|
|
- $this->addResponseLoading ( $retour, $responseElement, $ajaxLoader ); |
|
716
|
|
- } elseif ($hasLoader === 'internal') { |
|
717
|
|
- $retour .= "\n$(this).addClass('loading');"; |
|
718
|
|
- } |
|
719
|
|
- $ajaxParameters = [ |
|
|
706
|
+ $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
|
707
|
+ } |
|
|
708
|
+ $responseElement=$this->_getResponseElement($responseElement); |
|
|
709
|
+ $retour.="var self=this;\n"; |
|
|
710
|
+ $before=isset ($before) ? $before : ""; |
|
|
711
|
+ $retour.=$before; |
|
|
712
|
+ if ($hasLoader===true) { |
|
|
713
|
+ $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
|
714
|
+ } elseif ($hasLoader==='response') { |
|
|
715
|
+ $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
|
|
716
|
+ } elseif ($hasLoader==='internal') { |
|
|
717
|
+ $retour.="\n$(this).addClass('loading');"; |
|
|
718
|
+ } |
|
|
719
|
+ $ajaxParameters=[ |
|
720
|
720
|
"url" => "url", |
|
721
|
721
|
"method" => "'POST'", |
|
722
|
722
|
"data" => "params", |
|
723
|
723
|
"async" => $async |
|
724
|
724
|
]; |
|
725
|
|
- if (isset ( $headers )) { |
|
726
|
|
- $ajaxParameters ["headers"] = $headers; |
|
|
725
|
+ if (isset ($headers)) { |
|
|
726
|
+ $ajaxParameters ["headers"]=$headers; |
|
727
|
727
|
} |
|
728
|
|
- if (isset ( $partial )) { |
|
729
|
|
- $ajaxParameters ["xhr"] = "xhrProvider"; |
|
730
|
|
- $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
|
728
|
+ if (isset ($partial)) { |
|
|
729
|
+ $ajaxParameters ["xhr"]="xhrProvider"; |
|
|
730
|
+ $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
731
|
731
|
} |
|
732
|
|
- $this->createAjaxParameters ( $ajaxParameters, $parameters ); |
|
733
|
|
- $retour .= "$.ajax({" . $this->implodeAjaxParameters ( $ajaxParameters ) . "}).done(function( data ) {\n"; |
|
734
|
|
- $retour .= $this->_getOnAjaxDone ( $responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader ) . "});\n"; |
|
|
732
|
+ $this->createAjaxParameters($ajaxParameters, $parameters); |
|
|
733
|
+ $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
|
734
|
+ $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
735
|
735
|
|
|
736
|
736
|
if ($validation) { |
|
737
|
|
- $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
738
|
|
- " . $retour . " |
|
|
737
|
+ $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
|
738
|
+ " . $retour." |
|
739
|
739
|
}});\n"; |
|
740
|
|
- $retour .= "$('#" . $form . "').submit();\n"; |
|
|
740
|
+ $retour.="$('#".$form."').submit();\n"; |
|
741
|
741
|
} |
|
742
|
|
- $retour = $this->_addJsCondition ( $jsCondition, $retour ); |
|
|
742
|
+ $retour=$this->_addJsCondition($jsCondition, $retour); |
|
743
|
743
|
if ($immediatly) |
|
744
|
|
- $this->jquery_code_for_compile [] = $retour; |
|
|
744
|
+ $this->jquery_code_for_compile []=$retour; |
|
745
|
745
|
return $retour; |
|
746
|
746
|
} |
|
747
|
747
|
|
|
@@ -757,9 +757,9 @@ discard block |
|
|
block discarded – undo |
|
757
|
757
|
* @param array $parameters |
|
758
|
758
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
759
|
759
|
*/ |
|
760
|
|
- public function postForm($url, $form, $responseElement, $parameters = [ ]) { |
|
761
|
|
- $parameters ['immediatly'] = true; |
|
762
|
|
- return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
|
760
|
+ public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
|
761
|
+ $parameters ['immediatly']=true; |
|
|
762
|
+ return $this->_postForm($url, $form, $responseElement, $parameters); |
|
763
|
763
|
} |
|
764
|
764
|
|
|
765
|
765
|
/** |
|
@@ -775,9 +775,9 @@ discard block |
|
|
block discarded – undo |
|
775
|
775
|
* @param array $parameters |
|
776
|
776
|
* default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
|
777
|
777
|
*/ |
|
778
|
|
- public function postFormDeferred($url, $form, $responseElement, $parameters = [ ]) { |
|
779
|
|
- $parameters ['immediatly'] = false; |
|
780
|
|
- return $this->_postForm ( $url, $form, $responseElement, $parameters ); |
|
|
778
|
+ public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
|
779
|
+ $parameters ['immediatly']=false; |
|
|
780
|
+ return $this->_postForm($url, $form, $responseElement, $parameters); |
|
781
|
781
|
} |
|
782
|
782
|
|
|
783
|
783
|
/** |
|
@@ -793,14 +793,14 @@ discard block |
|
|
block discarded – undo |
|
793
|
793
|
* @param array $parameters |
|
794
|
794
|
* 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) |
|
795
|
795
|
*/ |
|
796
|
|
- public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
797
|
|
- $this->setDefaultParameters ( $parameters, [ |
|
|
796
|
+ public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
|
797
|
+ $this->setDefaultParameters($parameters, [ |
|
798
|
798
|
'preventDefault' => true, |
|
799
|
799
|
'stopPropagation' => true, |
|
800
|
800
|
'immediatly' => true, |
|
801
|
801
|
'listenerOn'=>false |
|
802
|
|
- ] ); |
|
803
|
|
- return $this->_add_event ( $element, $this->postFormDeferred ( $url, $form, $responseElement, $parameters ), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"] ,$parameters['listenerOn']); |
|
|
802
|
+ ]); |
|
|
803
|
+ return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters ["preventDefault"], $parameters ["stopPropagation"], $parameters ["immediatly"], $parameters['listenerOn']); |
|
804
|
804
|
} |
|
805
|
805
|
|
|
806
|
806
|
/** |
|
@@ -815,7 +815,7 @@ discard block |
|
|
block discarded – undo |
|
815
|
815
|
* @param array $parameters |
|
816
|
816
|
* 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) |
|
817
|
817
|
*/ |
|
818
|
|
- public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array ()) { |
|
819
|
|
- return $this->postFormOn ( "click", $element, $url, $form, $responseElement, $parameters ); |
|
|
818
|
+ public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
|
819
|
+ return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
|
820
|
820
|
} |
|
821
|
821
|
} |