@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * @property string identifier |
12 | 12 | * @property BaseHtml _self |
13 | 13 | */ |
14 | -trait BaseHtmlEventsTrait{ |
|
14 | +trait BaseHtmlEventsTrait { |
|
15 | 15 | |
16 | - protected $_events=array (); |
|
16 | + protected $_events=array(); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param string $event |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * @return BaseHtml |
24 | 24 | */ |
25 | 25 | public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
26 | - if ($stopPropagation === true) { |
|
27 | - $jsCode=Javascript::$stopPropagation . $jsCode; |
|
26 | + if ($stopPropagation===true) { |
|
27 | + $jsCode=Javascript::$stopPropagation.$jsCode; |
|
28 | 28 | } |
29 | - if ($preventDefault === true) { |
|
30 | - $jsCode=Javascript::$preventDefault . $jsCode; |
|
29 | + if ($preventDefault===true) { |
|
30 | + $jsCode=Javascript::$preventDefault.$jsCode; |
|
31 | 31 | } |
32 | 32 | return $this->_addEvent($event, $jsCode); |
33 | 33 | } |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | public function _addEvent($event, $jsCode) { |
41 | 41 | if (array_key_exists($event, $this->_events)) { |
42 | 42 | if (\is_array($this->_events[$event])) { |
43 | - if(array_search($jsCode, $this->_events[$event])===false){ |
|
43 | + if (array_search($jsCode, $this->_events[$event])===false) { |
|
44 | 44 | $this->_events[$event][]=$jsCode; |
45 | 45 | } |
46 | 46 | } else { |
47 | - $this->_events[$event]=array ($this->_events[$event],$jsCode ); |
|
47 | + $this->_events[$event]=array($this->_events[$event], $jsCode); |
|
48 | 48 | } |
49 | 49 | } else { |
50 | 50 | $this->_events[$event]=$jsCode; |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | return $this->onClick($jsCode); |
72 | 72 | } |
73 | 73 | |
74 | - public function onCreate($jsCode){ |
|
75 | - if(isset($this->_events["_create"])){ |
|
74 | + public function onCreate($jsCode) { |
|
75 | + if (isset($this->_events["_create"])) { |
|
76 | 76 | $this->_events["_create"][]=$jsCode; |
77 | - }else{ |
|
77 | + } else { |
|
78 | 78 | $this->_events["_create"]=[$jsCode]; |
79 | 79 | } |
80 | 80 | return $this; |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | public function addEventsOnRun(JsUtils $js=NULL) { |
84 | 84 | $this->_eventsOnCreate($js); |
85 | 85 | if (isset($this->_bsComponent)) { |
86 | - foreach ( $this->_events as $event => $jsCode ) { |
|
86 | + foreach ($this->_events as $event => $jsCode) { |
|
87 | 87 | $code=$jsCode; |
88 | 88 | if (\is_array($jsCode)) { |
89 | 89 | $code=""; |
90 | - foreach ( $jsCode as $jsC ) { |
|
90 | + foreach ($jsCode as $jsC) { |
|
91 | 91 | if ($jsC instanceof AjaxCall) { |
92 | - $code.="\n" . $jsC->compile($js); |
|
92 | + $code.="\n".$jsC->compile($js); |
|
93 | 93 | } else { |
94 | - $code.="\n" . $jsC; |
|
94 | + $code.="\n".$jsC; |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | } elseif ($jsCode instanceof AjaxCall) { |
@@ -99,18 +99,18 @@ discard block |
||
99 | 99 | } |
100 | 100 | $this->_bsComponent->addEvent($event, $code); |
101 | 101 | } |
102 | - $this->_events=array (); |
|
102 | + $this->_events=array(); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - protected function _eventsOnCreate(JsUtils $js=NULL){ |
|
107 | - if(isset($this->_events["_create"])){ |
|
106 | + protected function _eventsOnCreate(JsUtils $js=NULL) { |
|
107 | + if (isset($this->_events["_create"])) { |
|
108 | 108 | $create=$this->_events["_create"]; |
109 | - if(\is_array($create)){ |
|
109 | + if (\is_array($create)) { |
|
110 | 110 | $create=\implode("", $create); |
111 | 111 | } |
112 | - if(isset($js) && $create!=="") |
|
113 | - $js->exec($create,true); |
|
112 | + if (isset($js) && $create!=="") |
|
113 | + $js->exec($create, true); |
|
114 | 114 | unset($this->_events["_create"]); |
115 | 115 | } |
116 | 116 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @return $this |
125 | 125 | */ |
126 | 126 | public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) { |
127 | - $params=array ("url" => $url,"responseElement" => $responseElement ); |
|
127 | + $params=array("url" => $url, "responseElement" => $responseElement); |
|
128 | 128 | $params=array_merge($params, $parameters); |
129 | 129 | $this->_addEvent($event, new AjaxCall($operation, $params)); |
130 | 130 | return $this; |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | **/ |
168 | 168 | public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) { |
169 | 169 | $allParameters=[]; |
170 | - if(isset($parameters["params"])){ |
|
170 | + if (isset($parameters["params"])) { |
|
171 | 171 | $allParameters[]=JsUtils::_correctParams($parameters["params"]); |
172 | 172 | } |
173 | - if(isset($params)){ |
|
173 | + if (isset($params)) { |
|
174 | 174 | $allParameters[]=JsUtils::_correctParams($params); |
175 | 175 | } |
176 | 176 | $parameters["params"]=\implode("+'&'+", $allParameters); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | } |
218 | 218 | |
219 | 219 | public function jsDoJquery($jqueryCall, $param="") { |
220 | - return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . Javascript::prep_value($param) . ");"; |
|
220 | + return "$('#".$this->identifier."').".$jqueryCall."(".Javascript::prep_value($param).");"; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | public function executeOnRun($jsCode) { |
@@ -237,6 +237,6 @@ discard block |
||
237 | 237 | } |
238 | 238 | |
239 | 239 | public function jsToggle($value) { |
240 | - return $this->jsDoJquery("toggle",$value); |
|
240 | + return $this->jsDoJquery("toggle", $value); |
|
241 | 241 | } |
242 | 242 | } |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
18 | 18 | |
19 | 19 | abstract public function getUrl($url); |
20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
21 | 21 | |
22 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
23 | - if(isset($this->params["ajax"])){ |
|
22 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
23 | + if (isset($this->params["ajax"])) { |
|
24 | 24 | extract($this->params["ajax"]); |
25 | 25 | } |
26 | 26 | extract($parameters); |
@@ -30,100 +30,100 @@ discard block |
||
30 | 30 | $originalSelector=$responseElement; |
31 | 31 | $responseElement=$this->_getResponseElement($responseElement); |
32 | 32 | $retour.="var self=this;\n"; |
33 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
34 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
35 | - }elseif($hasLoader==="internal"){ |
|
33 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
34 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
35 | + }elseif ($hasLoader==="internal") { |
|
36 | 36 | $retour.="\n$(this).addClass('loading');"; |
37 | 37 | } |
38 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
38 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
39 | 39 | |
40 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
40 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
41 | 41 | |
42 | - if(isset($params)){ |
|
42 | + if (isset($params)) { |
|
43 | 43 | $ajaxParameters["data"]=self::_correctParams($params); |
44 | 44 | } |
45 | - if(isset($headers)){ |
|
45 | + if (isset($headers)) { |
|
46 | 46 | $ajaxParameters["headers"]=$headers; |
47 | 47 | } |
48 | 48 | $this->createAjaxParameters($ajaxParameters, $parameters); |
49 | 49 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
51 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
51 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
52 | 52 | if ($immediatly) |
53 | 53 | $this->jquery_code_for_compile[]=$retour; |
54 | 54 | return $retour; |
55 | 55 | } |
56 | 56 | |
57 | - protected function createAjaxParameters(&$original,$parameters){ |
|
58 | - $validParameters=["dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
59 | - foreach ($validParameters as $param=>$mask){ |
|
60 | - if(isset($parameters[$param])){ |
|
57 | + protected function createAjaxParameters(&$original, $parameters) { |
|
58 | + $validParameters=["dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
59 | + foreach ($validParameters as $param=>$mask) { |
|
60 | + if (isset($parameters[$param])) { |
|
61 | 61 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
67 | - $s = ''; foreach ($ajaxParameters as $k=>$v) { if ($s !== '') { $s .= ','; } $s .= "'{$k}':{$v}"; } |
|
66 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
67 | + $s=''; foreach ($ajaxParameters as $k=>$v) { if ($s!=='') { $s.=','; } $s.="'{$k}':{$v}"; } |
|
68 | 68 | return $s; |
69 | 69 | } |
70 | 70 | |
71 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
72 | - if(isset($jsCondition)){ |
|
71 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
72 | + if (isset($jsCondition)) { |
|
73 | 73 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
74 | 74 | } |
75 | 75 | return $jsSource; |
76 | 76 | } |
77 | 77 | |
78 | 78 | |
79 | - protected function _getAjaxUrl($url,$attr){ |
|
79 | + protected function _getAjaxUrl($url, $attr) { |
|
80 | 80 | $url=$this->_correctAjaxUrl($url); |
81 | 81 | $retour="url='".$url."';"; |
82 | 82 | $slash="/"; |
83 | - if(JString::endswith($url, "/")===true){ |
|
83 | + if (JString::endswith($url, "/")===true) { |
|
84 | 84 | $slash=""; |
85 | 85 | } |
86 | - if(JString::isNotNull($attr)){ |
|
87 | - if ($attr==="value"){ |
|
86 | + if (JString::isNotNull($attr)) { |
|
87 | + if ($attr==="value") { |
|
88 | 88 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
89 | - }elseif ($attr==="html"){ |
|
89 | + }elseif ($attr==="html") { |
|
90 | 90 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
91 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
91 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
92 | 92 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
93 | - }elseif($attr!==null && $attr!=="") |
|
93 | + }elseif ($attr!==null && $attr!=="") |
|
94 | 94 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
95 | 95 | } |
96 | 96 | return $retour; |
97 | 97 | } |
98 | 98 | |
99 | - protected function onPopstate(){ |
|
99 | + protected function onPopstate() { |
|
100 | 100 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
101 | 101 | } |
102 | 102 | |
103 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
104 | - $retour="";$call=null; |
|
103 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
104 | + $retour=""; $call=null; |
|
105 | 105 | if (JString::isNotNull($responseElement)) { |
106 | - if(isset($ajaxTransition)){ |
|
106 | + if (isset($ajaxTransition)) { |
|
107 | 107 | $call=$this->setAjaxDataCall($ajaxTransition); |
108 | - }elseif(isset($this->ajaxTransition)){ |
|
108 | + }elseif (isset($this->ajaxTransition)) { |
|
109 | 109 | $call=$this->ajaxTransition; |
110 | 110 | } |
111 | - if(\is_callable($call)) |
|
112 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
111 | + if (\is_callable($call)) |
|
112 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
113 | 113 | else |
114 | 114 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
115 | 115 | } |
116 | - if(isset($history)){ |
|
116 | + if (isset($history)) { |
|
117 | 117 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
118 | 118 | } |
119 | - if($hasLoader==="internal"){ |
|
119 | + if ($hasLoader==="internal") { |
|
120 | 120 | $retour.="\n$(self).removeClass('loading');"; |
121 | 121 | } |
122 | 122 | $retour.="\t".$jsCallback."\n"; |
123 | 123 | return $retour; |
124 | 124 | } |
125 | 125 | |
126 | - protected function _getResponseElement($responseElement){ |
|
126 | + protected function _getResponseElement($responseElement) { |
|
127 | 127 | if (JString::isNotNull($responseElement)) { |
128 | 128 | $responseElement=Javascript::prep_value($responseElement); |
129 | 129 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
@@ -134,33 +134,33 @@ discard block |
||
134 | 134 | protected function _correctAjaxUrl($url) { |
135 | 135 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
136 | 136 | $url=substr($url, 0, strlen($url)-1); |
137 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
137 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
138 | 138 | $url=$this->getUrl($url); |
139 | 139 | } |
140 | 140 | return $url; |
141 | 141 | } |
142 | 142 | |
143 | - public static function _correctParams($params){ |
|
144 | - if(JString::isNull($params)){ |
|
143 | + public static function _correctParams($params) { |
|
144 | + if (JString::isNull($params)) { |
|
145 | 145 | return ""; |
146 | 146 | } |
147 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
147 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
148 | 148 | return '$.param('.$params.')'; |
149 | 149 | } |
150 | 150 | return $params; |
151 | 151 | } |
152 | 152 | |
153 | - public static function _implodeParams($parameters){ |
|
153 | + public static function _implodeParams($parameters) { |
|
154 | 154 | $allParameters=[]; |
155 | - foreach ($parameters as $params){ |
|
156 | - if(isset($params)) |
|
155 | + foreach ($parameters as $params) { |
|
156 | + if (isset($params)) |
|
157 | 157 | $allParameters[]=self::_correctParams($params); |
158 | 158 | } |
159 | 159 | return \implode("+'&'+", $allParameters); |
160 | 160 | } |
161 | 161 | |
162 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
163 | - if(!isset($ajaxLoader)){ |
|
162 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
163 | + if (!isset($ajaxLoader)) { |
|
164 | 164 | $ajaxLoader=$this->ajaxLoader; |
165 | 165 | } |
166 | 166 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
169 | 169 | } |
170 | 170 | |
171 | - protected function setAjaxDataCall($params){ |
|
171 | + protected function setAjaxDataCall($params) { |
|
172 | 172 | $result=null; |
173 | - if(!\is_callable($params)){ |
|
174 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
175 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
173 | + if (!\is_callable($params)) { |
|
174 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
175 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
176 | 176 | }; |
177 | 177 | } |
178 | 178 | return $result; |
179 | 179 | } |
180 | 180 | |
181 | - protected function setDefaultParameters(&$parameters,$default){ |
|
182 | - foreach ($default as $k=>$v){ |
|
183 | - if(!isset($parameters[$k])) |
|
181 | + protected function setDefaultParameters(&$parameters, $default) { |
|
182 | + foreach ($default as $k=>$v) { |
|
183 | + if (!isset($parameters[$k])) |
|
184 | 184 | $parameters[$k]=$v; |
185 | 185 | } |
186 | 186 | } |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * @param string $url The url of the request |
195 | 195 | * @param string $responseElement selector of the HTML element displaying the answer |
196 | 196 | */ |
197 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
198 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
197 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
198 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * @param string $responseElement selector of the HTML element displaying the answer |
205 | 205 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
206 | 206 | */ |
207 | - public function get($url, $responseElement="",$parameters=[]) { |
|
207 | + public function get($url, $responseElement="", $parameters=[]) { |
|
208 | 208 | $parameters["immediatly"]=true; |
209 | - return $this->_get($url,$responseElement,$parameters); |
|
209 | + return $this->_get($url, $responseElement, $parameters); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * @param string $responseElement selector of the HTML element displaying the answer |
217 | 217 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
218 | 218 | */ |
219 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
219 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
220 | 220 | $parameters["immediatly"]=true; |
221 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
221 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | * @param string $responseElement selector of the HTML element displaying the answer |
229 | 229 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
230 | 230 | */ |
231 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
231 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
232 | 232 | $parameters["immediatly"]=false; |
233 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
233 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,15 +239,15 @@ discard block |
||
239 | 239 | * @param string $method Method used |
240 | 240 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
241 | 241 | */ |
242 | - private function _json($url, $method="get",$parameters=[]) { |
|
243 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
242 | + private function _json($url, $method="get", $parameters=[]) { |
|
243 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
244 | 244 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
245 | 245 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
246 | 246 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n\tfor(var key in data){" |
247 | 247 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
248 | 248 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
249 | 249 | $parameters["jsCallback"]=$retour; |
250 | - return $this->_ajax($method, $url,null,$parameters); |
|
250 | + return $this->_ajax($method, $url, null, $parameters); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
258 | 258 | */ |
259 | 259 | public function json($url, $method="get", $parameters=[]) { |
260 | - return $this->_json($url,$method,$parameters); |
|
260 | + return $this->_json($url, $method, $parameters); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | * @param string $method default get |
269 | 269 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
270 | 270 | */ |
271 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
272 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
273 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
271 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
272 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
273 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
283 | 283 | $parameters["immediatly"]=false; |
284 | - return $this->_json($url,$method,$parameters); |
|
284 | + return $this->_json($url, $method, $parameters); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -292,26 +292,26 @@ discard block |
||
292 | 292 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
293 | 293 | */ |
294 | 294 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
295 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
295 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
296 | 296 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
297 | 297 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
298 | 298 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
299 | - if($context===null){ |
|
299 | + if ($context===null) { |
|
300 | 300 | $parent="$('".$maskSelector."').parent()"; |
301 | - $newElm = "$('#'+newId)"; |
|
302 | - }else{ |
|
301 | + $newElm="$('#'+newId)"; |
|
302 | + } else { |
|
303 | 303 | $parent=$context; |
304 | - $newElm = $context.".find('#'+newId)"; |
|
304 | + $newElm=$context.".find('#'+newId)"; |
|
305 | 305 | } |
306 | 306 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
307 | 307 | $retour=$parent.".find('.{$rowClass}').remove();"; |
308 | 308 | $retour.="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\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(); |
309 | 309 | 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"; |
310 | - $retour.= $appendTo; |
|
310 | + $retour.=$appendTo; |
|
311 | 311 | $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"; |
312 | 312 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
313 | 313 | $parameters["jsCallback"]=$retour; |
314 | - return $this->_ajax($method, $url,null,$parameters); |
|
314 | + return $this->_ajax($method, $url, null, $parameters); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
323 | 323 | */ |
324 | 324 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
325 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
325 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -345,9 +345,9 @@ discard block |
||
345 | 345 | * @param string $method Method used, default : get |
346 | 346 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
347 | 347 | */ |
348 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
349 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
350 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
348 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
349 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
350 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
361 | 361 | $parameters["immediatly"]=false; |
362 | - return $this->_get($url, $responseElement,$parameters); |
|
362 | + return $this->_get($url, $responseElement, $parameters); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * @param array $parameters 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) |
373 | 373 | */ |
374 | 374 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
375 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
376 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
375 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
376 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | * @param array $parameters 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) |
387 | 387 | */ |
388 | 388 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
389 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
390 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
389 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
390 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -414,9 +414,9 @@ discard block |
||
414 | 414 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
415 | 415 | } |
416 | 416 | |
417 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
417 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
418 | 418 | $parameters["params"]=$params; |
419 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
419 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -426,8 +426,8 @@ discard block |
||
426 | 426 | * @param string $params JSON parameters |
427 | 427 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
428 | 428 | */ |
429 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
430 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
429 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
430 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | * @param string $responseElement selector of the HTML element displaying the answer |
439 | 439 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
440 | 440 | */ |
441 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
441 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
442 | 442 | $parameters["immediatly"]=false; |
443 | 443 | return $this->_post($url, $params, $responseElement, $parameters); |
444 | 444 | } |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | * @param array $parameters 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) |
455 | 455 | */ |
456 | 456 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
457 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
458 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
457 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
458 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -473,33 +473,33 @@ discard block |
||
473 | 473 | |
474 | 474 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
475 | 475 | //$params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$ajaxLoader=null;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL;$async=true; |
476 | - if(isset($this->params["ajax"])){ |
|
476 | + if (isset($this->params["ajax"])) { |
|
477 | 477 | extract($this->params["ajax"]); |
478 | 478 | } |
479 | - $params="{}";$validation=false; |
|
479 | + $params="{}"; $validation=false; |
|
480 | 480 | \extract($parameters); |
481 | - $async=($async)?"true":"false"; |
|
481 | + $async=($async) ? "true" : "false"; |
|
482 | 482 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
483 | 483 | $retour=$this->_getAjaxUrl($url, $attr); |
484 | 484 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
485 | 485 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
486 | - if(isset($params)){ |
|
486 | + if (isset($params)) { |
|
487 | 487 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
488 | 488 | } |
489 | 489 | $responseElement=$this->_getResponseElement($responseElement); |
490 | 490 | $retour.="var self=this;\n"; |
491 | - if($hasLoader===true){ |
|
492 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
493 | - }elseif($hasLoader==="internal"){ |
|
491 | + if ($hasLoader===true) { |
|
492 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
493 | + }elseif ($hasLoader==="internal") { |
|
494 | 494 | $retour.="\n$(this).addClass('loading');"; |
495 | 495 | } |
496 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
497 | - if(isset($headers)){ |
|
496 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
497 | + if (isset($headers)) { |
|
498 | 498 | $ajaxParameters["headers"]=$headers; |
499 | 499 | } |
500 | 500 | $this->createAjaxParameters($ajaxParameters, $parameters); |
501 | 501 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
502 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
502 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
503 | 503 | |
504 | 504 | if ($validation) { |
505 | 505 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @param array $parameters 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) |
550 | 550 | */ |
551 | 551 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
552 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
553 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
552 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
553 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |