@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
10 | 10 | |
11 | 11 | public abstract function _prep_value($value); |
12 | - public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
12 | + public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
13 | 13 | protected function addLoading(&$retour, $responseElement) { |
14 | 14 | $loading_notifier='<div class="ajax-loader">'; |
15 | 15 | if ($this->ajaxLoader=='') { |
16 | 16 | $loading_notifier.="Loading..."; |
17 | - } else { |
|
17 | + }else { |
|
18 | 18 | $loading_notifier.=$this->ajaxLoader; |
19 | 19 | } |
20 | 20 | $loading_notifier.='</div>'; |
@@ -22,20 +22,20 @@ discard block |
||
22 | 22 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
23 | 23 | } |
24 | 24 | |
25 | - public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
26 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
|
25 | + public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
26 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $immediatly); |
|
27 | 27 | } |
28 | - public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
29 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
|
28 | + public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
29 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $immediatly); |
|
30 | 30 | } |
31 | 31 | |
32 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
33 | - if(JString::isNull($params)){$params="{}";} |
|
32 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
33 | + if (JString::isNull($params)) {$params="{}"; } |
|
34 | 34 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
35 | 35 | $retour=$this->_getAjaxUrl($url, $attr); |
36 | 36 | $responseElement=$this->_getResponseElement($responseElement); |
37 | 37 | $retour.="var self=this;\n"; |
38 | - if($hasLoader===true){ |
|
38 | + if ($hasLoader===true) { |
|
39 | 39 | $this->addLoading($retour, $responseElement); |
40 | 40 | } |
41 | 41 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
@@ -45,22 +45,22 @@ discard block |
||
45 | 45 | return $retour; |
46 | 46 | } |
47 | 47 | |
48 | - protected function _getAjaxUrl($url,$attr){ |
|
48 | + protected function _getAjaxUrl($url, $attr) { |
|
49 | 49 | $url=$this->_correctAjaxUrl($url); |
50 | 50 | $retour="url='".$url."';\n"; |
51 | 51 | $slash="/"; |
52 | - if(PhalconUtils::endsWith($url, "/")===true) |
|
52 | + if (PhalconUtils::endsWith($url, "/")===true) |
|
53 | 53 | $slash=""; |
54 | - if(JString::isNotNull($attr)){ |
|
54 | + if (JString::isNotNull($attr)) { |
|
55 | 55 | if ($attr=="value") |
56 | 56 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
57 | - else if($attr!=null && $attr!=="") |
|
57 | + else if ($attr!=null && $attr!=="") |
|
58 | 58 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
59 | 59 | } |
60 | 60 | return $retour; |
61 | 61 | } |
62 | 62 | |
63 | - protected function _getOnAjaxDone($responseElement,$jsCallback){ |
|
63 | + protected function _getOnAjaxDone($responseElement, $jsCallback) { |
|
64 | 64 | $retour=""; |
65 | 65 | if ($responseElement!=="") { |
66 | 66 | $retour="\t$({$responseElement}).html( data );\n"; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | return $retour; |
70 | 70 | } |
71 | 71 | |
72 | - protected function _getResponseElement($responseElement){ |
|
72 | + protected function _getResponseElement($responseElement) { |
|
73 | 73 | if ($responseElement!=="") { |
74 | 74 | $responseElement=$this->_prep_value($responseElement); |
75 | 75 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | protected function _correctAjaxUrl($url) { |
80 | 80 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
81 | 81 | $url=substr($url, 0, strlen($url)-1); |
82 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
82 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
83 | 83 | $url=$this->jsUtils->getUrl($url); |
84 | 84 | } |
85 | 85 | return $url; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param string $jsCallback javascript code to execute after the request |
94 | 94 | * @param boolean $immediatly |
95 | 95 | */ |
96 | - public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
96 | + public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
97 | 97 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
98 | 98 | $retour=$this->_getAjaxUrl($url, $attr); |
99 | 99 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param string $url the request address |
115 | 115 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
116 | 116 | */ |
117 | - public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
117 | + public function _jsonOn($event, $element, $url, $parameters=array()) { |
|
118 | 118 | $preventDefault=true; |
119 | 119 | $stopPropagation=true; |
120 | 120 | $jsCallback=null; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | $params="{}"; |
125 | 125 | $immediatly=true; |
126 | 126 | extract($parameters); |
127 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
127 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -136,19 +136,19 @@ discard block |
||
136 | 136 | * @param string $context jquery DOM element, array container. |
137 | 137 | * @param boolean $immediatly |
138 | 138 | */ |
139 | - public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
|
139 | + public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null, $immediatly=false) { |
|
140 | 140 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
141 | 141 | $retour=$this->_getAjaxUrl($url, $attr); |
142 | - if($context===null){ |
|
142 | + if ($context===null) { |
|
143 | 143 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
144 | - $newElm = "$('#'+newId)"; |
|
145 | - }else{ |
|
144 | + $newElm="$('#'+newId)"; |
|
145 | + }else { |
|
146 | 146 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
147 | - $newElm = $context.".find('#'+newId)"; |
|
147 | + $newElm=$context.".find('#'+newId)"; |
|
148 | 148 | } |
149 | 149 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
150 | 150 | $retour.="\tdata=$.parseJSON(data);$.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();newElm.attr('id',newId);\n"; |
151 | - $retour.= $appendTo; |
|
151 | + $retour.=$appendTo; |
|
152 | 152 | $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"; |
153 | 153 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
154 | 154 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -163,26 +163,26 @@ discard block |
||
163 | 163 | * @param string $url the request address |
164 | 164 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
165 | 165 | */ |
166 | - public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
166 | + public function _jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
167 | 167 | $preventDefault=true; |
168 | 168 | $stopPropagation=true; |
169 | 169 | $jsCallback=null; |
170 | 170 | $attr="id"; |
171 | 171 | $method="get"; |
172 | - $context = null; |
|
172 | + $context=null; |
|
173 | 173 | $params="{}"; |
174 | 174 | $immediatly=true; |
175 | 175 | extract($parameters); |
176 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
176 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
177 | 177 | } |
178 | 178 | |
179 | - public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
179 | + public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
180 | 180 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
181 | 181 | $retour=$this->_getAjaxUrl($url, $attr); |
182 | 182 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
183 | 183 | $responseElement=$this->_getResponseElement($responseElement); |
184 | 184 | $retour.="var self=this;\n"; |
185 | - if($hasLoader===true){ |
|
185 | + if ($hasLoader===true) { |
|
186 | 186 | $this->addLoading($retour, $responseElement); |
187 | 187 | } |
188 | 188 | $retour.="$.post(url,params).done(function( data ) {\n"; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @param string $responseElement |
210 | 210 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
211 | 211 | */ |
212 | - public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
212 | + public function _getOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
213 | 213 | $preventDefault=true; |
214 | 214 | $stopPropagation=true; |
215 | 215 | $jsCallback=null; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $hasLoader=true; |
218 | 218 | $immediatly=true; |
219 | 219 | extract($parameters); |
220 | - return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
|
220 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader), $event, $preventDefault, $stopPropagation, $immediatly); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @param string $responseElement |
231 | 231 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
232 | 232 | */ |
233 | - public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
233 | + public function _postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
234 | 234 | $preventDefault=true; |
235 | 235 | $stopPropagation=true; |
236 | 236 | $jsCallback=null; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $hasLoader=true; |
239 | 239 | $immediatly=true; |
240 | 240 | extract($parameters); |
241 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
|
241 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader), $event, $preventDefault, $stopPropagation, $immediatly); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param string $responseElement |
252 | 252 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true) |
253 | 253 | */ |
254 | - public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
254 | + public function _postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
255 | 255 | $preventDefault=true; |
256 | 256 | $stopPropagation=true; |
257 | 257 | $validation=false; |
@@ -260,6 +260,6 @@ discard block |
||
260 | 260 | $hasLoader=true; |
261 | 261 | $immediatly=true; |
262 | 262 | extract($parameters); |
263 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
|
263 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader), $event, $preventDefault, $stopPropagation, $immediatly); |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | \ No newline at end of file |
@@ -40,8 +40,9 @@ discard block |
||
40 | 40 | } |
41 | 41 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
42 | 42 | $retour.=$this->_getOnAjaxDone($responseElement, $jsCallback)."});\n"; |
43 | - if ($immediatly) |
|
44 | - $this->jquery_code_for_compile[]=$retour; |
|
43 | + if ($immediatly) { |
|
44 | + $this->jquery_code_for_compile[]=$retour; |
|
45 | + } |
|
45 | 46 | return $retour; |
46 | 47 | } |
47 | 48 | |
@@ -49,13 +50,15 @@ discard block |
||
49 | 50 | $url=$this->_correctAjaxUrl($url); |
50 | 51 | $retour="url='".$url."';\n"; |
51 | 52 | $slash="/"; |
52 | - if(PhalconUtils::endsWith($url, "/")===true) |
|
53 | - $slash=""; |
|
53 | + if(PhalconUtils::endsWith($url, "/")===true) { |
|
54 | + $slash=""; |
|
55 | + } |
|
54 | 56 | if(JString::isNotNull($attr)){ |
55 | - if ($attr=="value") |
|
56 | - $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
57 | - else if($attr!=null && $attr!=="") |
|
58 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
57 | + if ($attr=="value") { |
|
58 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
59 | + } else if($attr!=null && $attr!=="") { |
|
60 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
61 | + } |
|
59 | 62 | } |
60 | 63 | return $retour; |
61 | 64 | } |
@@ -77,8 +80,9 @@ discard block |
||
77 | 80 | } |
78 | 81 | |
79 | 82 | protected function _correctAjaxUrl($url) { |
80 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
81 | - $url=substr($url, 0, strlen($url)-1); |
|
83 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
84 | + $url=substr($url, 0, strlen($url)-1); |
|
85 | + } |
|
82 | 86 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
83 | 87 | $url=$this->jsUtils->getUrl($url); |
84 | 88 | } |
@@ -102,8 +106,9 @@ discard block |
||
102 | 106 | $retour.="\t".$jsCallback."\n". |
103 | 107 | "\t$(document).trigger('jsonReady',[data]);\n". |
104 | 108 | "});\n"; |
105 | - if ($immediatly) |
|
106 | - $this->jquery_code_for_compile[]=$retour; |
|
109 | + if ($immediatly) { |
|
110 | + $this->jquery_code_for_compile[]=$retour; |
|
111 | + } |
|
107 | 112 | return $retour; |
108 | 113 | } |
109 | 114 | |
@@ -142,7 +147,7 @@ discard block |
||
142 | 147 | if($context===null){ |
143 | 148 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
144 | 149 | $newElm = "$('#'+newId)"; |
145 | - }else{ |
|
150 | + } else{ |
|
146 | 151 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
147 | 152 | $newElm = $context.".find('#'+newId)"; |
148 | 153 | } |
@@ -152,8 +157,9 @@ discard block |
||
152 | 157 | $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"; |
153 | 158 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
154 | 159 | $retour.="\t".$jsCallback."\n"."});\n"; |
155 | - if ($immediatly) |
|
156 | - $this->jquery_code_for_compile[]=$retour; |
|
160 | + if ($immediatly) { |
|
161 | + $this->jquery_code_for_compile[]=$retour; |
|
162 | + } |
|
157 | 163 | return $retour; |
158 | 164 | } |
159 | 165 | /** |
@@ -194,8 +200,9 @@ discard block |
||
194 | 200 | }});\n"; |
195 | 201 | $retour.="$('#".$form."').submit();\n"; |
196 | 202 | } |
197 | - if ($immediatly) |
|
198 | - $this->jquery_code_for_compile[]=$retour; |
|
203 | + if ($immediatly) { |
|
204 | + $this->jquery_code_for_compile[]=$retour; |
|
205 | + } |
|
199 | 206 | return $retour; |
200 | 207 | } |
201 | 208 |