@@ -20,35 +20,35 @@ discard block |
||
20 | 20 | * @property string $identifier |
21 | 21 | */ |
22 | 22 | trait FieldsTrait { |
23 | - abstract public function addFields($fields=NULL,$label=NULL); |
|
23 | + abstract public function addFields($fields=NULL, $label=NULL); |
|
24 | 24 | abstract public function addItem($item); |
25 | 25 | abstract public function getItem($index); |
26 | 26 | abstract public function count(); |
27 | 27 | |
28 | - protected function createItem($value){ |
|
29 | - if(\is_array($value)){ |
|
30 | - $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
|
28 | + protected function createItem($value) { |
|
29 | + if (\is_array($value)) { |
|
30 | + $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id", ""), JArray::getDefaultValue($value, "label", null), JArray::getDefaultValue($value, "type", "text"), JArray::getDefaultValue($value, "value", ""), JArray::getDefaultValue($value, "placeholder", JArray::getDefaultValue($value, "label", null))); |
|
31 | 31 | return $itemO; |
32 | - }elseif(\is_object($value)){ |
|
32 | + }elseif (\is_object($value)) { |
|
33 | 33 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
34 | 34 | return $itemO; |
35 | - }else |
|
35 | + } else |
|
36 | 36 | return new HtmlFormInput($value); |
37 | 37 | } |
38 | 38 | |
39 | - protected function createCondition($value){ |
|
39 | + protected function createCondition($value) { |
|
40 | 40 | return \is_object($value)===false || $value instanceof \Ajax\semantic\html\elements\HtmlInput; |
41 | 41 | } |
42 | 42 | |
43 | - public function addInputs($inputs,$fieldslabel=null){ |
|
43 | + public function addInputs($inputs, $fieldslabel=null) { |
|
44 | 44 | $fields=array(); |
45 | - foreach ($inputs as $input){ |
|
45 | + foreach ($inputs as $input) { |
|
46 | 46 | \extract($input); |
47 | - $f=new HtmlFormInput("",""); |
|
47 | + $f=new HtmlFormInput("", ""); |
|
48 | 48 | $f->fromArray($input); |
49 | 49 | $fields[]=$f; |
50 | 50 | } |
51 | - return $this->addFields($fields,$fieldslabel); |
|
51 | + return $this->addFields($fields, $fieldslabel); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,35 +57,35 @@ discard block |
||
57 | 57 | * @param array|mixed $values |
58 | 58 | * @return HtmlFormFields |
59 | 59 | */ |
60 | - public function setFieldsPropertyValues($property,$values){ |
|
60 | + public function setFieldsPropertyValues($property, $values) { |
|
61 | 61 | $i=0; |
62 | - if(\is_array($values)===false){ |
|
63 | - $values=\array_fill(0, $this->count(),$values); |
|
62 | + if (\is_array($values)===false) { |
|
63 | + $values=\array_fill(0, $this->count(), $values); |
|
64 | 64 | } |
65 | - foreach ($values as $value){ |
|
65 | + foreach ($values as $value) { |
|
66 | 66 | $c=$this->content[$i++]; |
67 | - if(isset($c)){ |
|
67 | + if (isset($c)) { |
|
68 | 68 | $df=$c->getDataField(); |
69 | - $df->setProperty($property,$value); |
|
69 | + $df->setProperty($property, $value); |
|
70 | 70 | } |
71 | - else{ |
|
71 | + else { |
|
72 | 72 | return $this; |
73 | 73 | } |
74 | 74 | } |
75 | 75 | return $this; |
76 | 76 | } |
77 | 77 | |
78 | - public function addFieldRule($index,$type,$prompt=NULL,$value=NULL){ |
|
78 | + public function addFieldRule($index, $type, $prompt=NULL, $value=NULL) { |
|
79 | 79 | $field=$this->getItem($index); |
80 | - if(isset($field)){ |
|
81 | - $field->addRule($type,$prompt,$value); |
|
80 | + if (isset($field)) { |
|
81 | + $field->addRule($type, $prompt, $value); |
|
82 | 82 | } |
83 | 83 | return $this; |
84 | 84 | } |
85 | 85 | |
86 | - public function addFieldRules($index,$rules){ |
|
86 | + public function addFieldRules($index, $rules) { |
|
87 | 87 | $field=$this->getItem($index); |
88 | - if(isset($field)){ |
|
88 | + if (isset($field)) { |
|
89 | 89 | $field->addRules($rules); |
90 | 90 | } |
91 | 91 | return $this; |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * @param boolean $multiple |
101 | 101 | * @return HtmlFormDropdown |
102 | 102 | */ |
103 | - public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){ |
|
104 | - return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple)); |
|
103 | + public function addDropdown($identifier, $items=array(), $label=NULL, $value=NULL, $multiple=false) { |
|
104 | + return $this->addItem(new HtmlFormDropdown($identifier, $items, $label, $value, $multiple)); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | * @param boolean $asIcons |
112 | 112 | * @return HtmlButtonGroups |
113 | 113 | */ |
114 | - public function addButtonGroups($identifier,$elements=[],$asIcons=false){ |
|
115 | - return $this->addItem(new HtmlButtonGroups($identifier,$elements,$asIcons)); |
|
114 | + public function addButtonGroups($identifier, $elements=[], $asIcons=false) { |
|
115 | + return $this->addItem(new HtmlButtonGroups($identifier, $elements, $asIcons)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @param string $icon |
125 | 125 | * @return HtmlButtonGroups |
126 | 126 | */ |
127 | - public function addDropdownButton($identifier,$value,$items=[],$asCombo=false,$icon=null){ |
|
128 | - return $this->addItem(HtmlButton::dropdown($identifier, $value,$items,$asCombo,$icon)); |
|
127 | + public function addDropdownButton($identifier, $value, $items=[], $asCombo=false, $icon=null) { |
|
128 | + return $this->addItem(HtmlButton::dropdown($identifier, $value, $items, $asCombo, $icon)); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string $placeholder |
137 | 137 | * @return HtmlFormInput |
138 | 138 | */ |
139 | - public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){ |
|
140 | - return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder)); |
|
139 | + public function addInput($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL) { |
|
140 | + return $this->addItem(new HtmlFormInput($identifier, $label, $type, $value, $placeholder)); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -148,22 +148,22 @@ discard block |
||
148 | 148 | * @param int $rows |
149 | 149 | * @return HtmlTextarea |
150 | 150 | */ |
151 | - public function addTextarea($identifier, $label,$value=NULL,$placeholder=NULL,$rows=5){ |
|
152 | - return $this->addItem(new HtmlFormTextarea($identifier,$label,$value,$placeholder,$rows)); |
|
151 | + public function addTextarea($identifier, $label, $value=NULL, $placeholder=NULL, $rows=5) { |
|
152 | + return $this->addItem(new HtmlFormTextarea($identifier, $label, $value, $placeholder, $rows)); |
|
153 | 153 | } |
154 | 154 | |
155 | - public function addPassword($identifier, $label=NULL){ |
|
156 | - return $this->addItem(new HtmlFormInput($identifier,$label,"password","","")); |
|
155 | + public function addPassword($identifier, $label=NULL) { |
|
156 | + return $this->addItem(new HtmlFormInput($identifier, $label, "password", "", "")); |
|
157 | 157 | } |
158 | 158 | |
159 | - public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){ |
|
160 | - return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick)); |
|
159 | + public function addButton($identifier, $value, $cssStyle=NULL, $onClick=NULL) { |
|
160 | + return $this->addItem(new HtmlButton($identifier, $value, $cssStyle, $onClick)); |
|
161 | 161 | } |
162 | 162 | |
163 | - public function addButtonIcon($identifier,$icon,$cssStyle=NULL,$onClick=NULL){ |
|
163 | + public function addButtonIcon($identifier, $icon, $cssStyle=NULL, $onClick=NULL) { |
|
164 | 164 | $bt=new HtmlButton($identifier); |
165 | 165 | $bt->asIcon($icon); |
166 | - if(isset($onClick)) |
|
166 | + if (isset($onClick)) |
|
167 | 167 | $bt->onClick($onClick); |
168 | 168 | if (isset($cssStyle)) |
169 | 169 | $bt->addClass($cssStyle); |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | * @param string $type |
178 | 178 | * @return HtmlFormCheckbox |
179 | 179 | */ |
180 | - public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){ |
|
181 | - return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type)); |
|
180 | + public function addCheckbox($identifier, $label=NULL, $value=NULL, $type=NULL) { |
|
181 | + return $this->addItem(new HtmlFormCheckbox($identifier, $label, $value, $type)); |
|
182 | 182 | } |
183 | 183 | |
184 | - public function addRadio($identifier, $name,$label=NULL,$value=NULL){ |
|
185 | - return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value)); |
|
184 | + public function addRadio($identifier, $name, $label=NULL, $value=NULL) { |
|
185 | + return $this->addItem(new HtmlFormRadio($identifier, $name, $label, $value)); |
|
186 | 186 | } |
187 | 187 | |
188 | - public function addElement($identifier,$content,$label,$tagName="div",$baseClass=""){ |
|
189 | - $div=new HtmlSemDoubleElement($identifier,$tagName,$baseClass,$content); |
|
190 | - return $this->addItem(new HtmlFormField("field-".$identifier, $div,$label)); |
|
188 | + public function addElement($identifier, $content, $label, $tagName="div", $baseClass="") { |
|
189 | + $div=new HtmlSemDoubleElement($identifier, $tagName, $baseClass, $content); |
|
190 | + return $this->addItem(new HtmlFormField("field-".$identifier, $div, $label)); |
|
191 | 191 | } |
192 | 192 | } |
@@ -29,11 +29,12 @@ discard block |
||
29 | 29 | if(\is_array($value)){ |
30 | 30 | $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null))); |
31 | 31 | return $itemO; |
32 | - }elseif(\is_object($value)){ |
|
32 | + } elseif(\is_object($value)){ |
|
33 | 33 | $itemO=new HtmlFormField("field-".$this->identifier, $value); |
34 | 34 | return $itemO; |
35 | - }else |
|
36 | - return new HtmlFormInput($value); |
|
35 | + } else { |
|
36 | + return new HtmlFormInput($value); |
|
37 | + } |
|
37 | 38 | } |
38 | 39 | |
39 | 40 | protected function createCondition($value){ |
@@ -67,8 +68,7 @@ discard block |
||
67 | 68 | if(isset($c)){ |
68 | 69 | $df=$c->getDataField(); |
69 | 70 | $df->setProperty($property,$value); |
70 | - } |
|
71 | - else{ |
|
71 | + } else{ |
|
72 | 72 | return $this; |
73 | 73 | } |
74 | 74 | } |
@@ -163,10 +163,12 @@ discard block |
||
163 | 163 | public function addButtonIcon($identifier,$icon,$cssStyle=NULL,$onClick=NULL){ |
164 | 164 | $bt=new HtmlButton($identifier); |
165 | 165 | $bt->asIcon($icon); |
166 | - if(isset($onClick)) |
|
167 | - $bt->onClick($onClick); |
|
168 | - if (isset($cssStyle)) |
|
169 | - $bt->addClass($cssStyle); |
|
166 | + if(isset($onClick)) { |
|
167 | + $bt->onClick($onClick); |
|
168 | + } |
|
169 | + if (isset($cssStyle)) { |
|
170 | + $bt->addClass($cssStyle); |
|
171 | + } |
|
170 | 172 | return $this->addItem($bt); |
171 | 173 | } |
172 | 174 |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
19 | 19 | |
20 | 20 | abstract public function getUrl($url); |
21 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
22 | - abstract public function interval($jsCode,$time,$globalName=null,$immediatly=true); |
|
21 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
22 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
23 | 23 | |
24 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
25 | - if(isset($this->params["ajax"])){ |
|
24 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
25 | + if (isset($this->params["ajax"])) { |
|
26 | 26 | extract($this->params["ajax"]); |
27 | 27 | } |
28 | 28 | extract($parameters); |
@@ -32,121 +32,121 @@ discard block |
||
32 | 32 | $originalSelector=$responseElement; |
33 | 33 | $responseElement=$this->_getResponseElement($responseElement); |
34 | 34 | $retour.="var self=this;\n"; |
35 | - $before=isset($before)?$before:""; |
|
35 | + $before=isset($before) ? $before : ""; |
|
36 | 36 | $retour.=$before; |
37 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
38 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
39 | - }elseif($hasLoader==="internal"){ |
|
37 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
38 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
39 | + }elseif ($hasLoader==="internal") { |
|
40 | 40 | $retour.="\n$(this).addClass('loading');"; |
41 | 41 | } |
42 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
42 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
43 | 43 | |
44 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
44 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
45 | 45 | |
46 | - if(isset($params)){ |
|
47 | - $ajaxParameters["data"]=self::_correctParams($params,$parameters); |
|
46 | + if (isset($params)) { |
|
47 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
48 | 48 | } |
49 | - if(isset($headers)){ |
|
49 | + if (isset($headers)) { |
|
50 | 50 | $ajaxParameters["headers"]=$headers; |
51 | 51 | } |
52 | 52 | $this->createAjaxParameters($ajaxParameters, $parameters); |
53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
54 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
55 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
54 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
55 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
56 | 56 | if ($immediatly) |
57 | 57 | $this->jquery_code_for_compile[]=$retour; |
58 | 58 | return $retour; |
59 | 59 | } |
60 | 60 | |
61 | - protected function createAjaxParameters(&$original,$parameters){ |
|
62 | - $validParameters=["contentType"=>"%value%","dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
63 | - foreach ($validParameters as $param=>$mask){ |
|
64 | - if(isset($parameters[$param])){ |
|
61 | + protected function createAjaxParameters(&$original, $parameters) { |
|
62 | + $validParameters=["contentType"=>"%value%", "dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
63 | + foreach ($validParameters as $param=>$mask) { |
|
64 | + if (isset($parameters[$param])) { |
|
65 | 65 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
71 | - $s = ''; |
|
70 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
71 | + $s=''; |
|
72 | 72 | foreach ($ajaxParameters as $k=>$v) { |
73 | - if ($s !== '') { |
|
74 | - $s .= ','; |
|
73 | + if ($s!=='') { |
|
74 | + $s.=','; |
|
75 | 75 | } |
76 | - if(is_array($v)){ |
|
77 | - $s .= "'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
78 | - }else{ |
|
79 | - $s .= "'{$k}':{$v}"; |
|
76 | + if (is_array($v)) { |
|
77 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
78 | + } else { |
|
79 | + $s.="'{$k}':{$v}"; |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | return $s; |
83 | 83 | } |
84 | 84 | |
85 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
86 | - if(isset($jsCondition)){ |
|
85 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
86 | + if (isset($jsCondition)) { |
|
87 | 87 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
88 | 88 | } |
89 | 89 | return $jsSource; |
90 | 90 | } |
91 | 91 | |
92 | 92 | |
93 | - protected function _getAjaxUrl($url,$attr){ |
|
93 | + protected function _getAjaxUrl($url, $attr) { |
|
94 | 94 | $url=$this->_correctAjaxUrl($url); |
95 | 95 | $retour="url='".$url."';"; |
96 | 96 | $slash="/"; |
97 | - if(JString::endswith($url, "/")===true){ |
|
97 | + if (JString::endswith($url, "/")===true) { |
|
98 | 98 | $slash=""; |
99 | 99 | } |
100 | - if(JString::isNotNull($attr)){ |
|
101 | - if ($attr==="value"){ |
|
100 | + if (JString::isNotNull($attr)) { |
|
101 | + if ($attr==="value") { |
|
102 | 102 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
103 | - }elseif ($attr==="html"){ |
|
103 | + }elseif ($attr==="html") { |
|
104 | 104 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
105 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
105 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
106 | 106 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
107 | - }elseif($attr!==null && $attr!=="") |
|
107 | + }elseif ($attr!==null && $attr!=="") |
|
108 | 108 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
109 | 109 | } |
110 | 110 | return $retour; |
111 | 111 | } |
112 | 112 | |
113 | - protected function onPopstate(){ |
|
113 | + protected function onPopstate() { |
|
114 | 114 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
115 | 115 | } |
116 | 116 | |
117 | - protected function autoActiveLinks($previousURL="window.location.href"){ |
|
118 | - $result= "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
117 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
118 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
119 | 119 | $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
120 | 120 | return $result; |
121 | 121 | } |
122 | 122 | |
123 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
124 | - $retour="";$call=null; |
|
123 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
124 | + $retour=""; $call=null; |
|
125 | 125 | if (JString::isNotNull($responseElement)) { |
126 | - if(isset($ajaxTransition)){ |
|
126 | + if (isset($ajaxTransition)) { |
|
127 | 127 | $call=$this->setAjaxDataCall($ajaxTransition); |
128 | - }elseif(isset($this->ajaxTransition)){ |
|
128 | + }elseif (isset($this->ajaxTransition)) { |
|
129 | 129 | $call=$this->ajaxTransition; |
130 | 130 | } |
131 | - if(\is_callable($call)) |
|
132 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
131 | + if (\is_callable($call)) |
|
132 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
133 | 133 | else |
134 | 134 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
135 | 135 | } |
136 | - if(isset($history)){ |
|
137 | - if($this->params["autoActiveLinks"]){ |
|
136 | + if (isset($history)) { |
|
137 | + if ($this->params["autoActiveLinks"]) { |
|
138 | 138 | $retour.=$this->autoActiveLinks("url"); |
139 | 139 | } |
140 | 140 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
141 | 141 | } |
142 | - if($hasLoader==="internal"){ |
|
142 | + if ($hasLoader==="internal") { |
|
143 | 143 | $retour.="\n$(self).removeClass('loading');"; |
144 | 144 | } |
145 | 145 | $retour.="\t".$jsCallback."\n"; |
146 | 146 | return $retour; |
147 | 147 | } |
148 | 148 | |
149 | - protected function _getResponseElement($responseElement){ |
|
149 | + protected function _getResponseElement($responseElement) { |
|
150 | 150 | if (JString::isNotNull($responseElement)) { |
151 | 151 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
152 | 152 | } |
@@ -156,37 +156,37 @@ discard block |
||
156 | 156 | protected function _correctAjaxUrl($url) { |
157 | 157 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
158 | 158 | $url=substr($url, 0, strlen($url)-1); |
159 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
159 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
160 | 160 | $url=$this->getUrl($url); |
161 | 161 | } |
162 | 162 | return $url; |
163 | 163 | } |
164 | 164 | |
165 | - public static function _correctParams($params,$ajaxParameters=[]){ |
|
166 | - if(JString::isNull($params)){ |
|
165 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
166 | + if (JString::isNull($params)) { |
|
167 | 167 | return ""; |
168 | 168 | } |
169 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
170 | - if( !isset($ajaxParameters['contentType'])|| !UString::contains('json', $ajaxParameters['contentType'])){ |
|
169 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
170 | + if (!isset($ajaxParameters['contentType']) || !UString::contains('json', $ajaxParameters['contentType'])) { |
|
171 | 171 | return '$.param('.$params.')'; |
172 | - }else{ |
|
172 | + } else { |
|
173 | 173 | return 'JSON.stringify('.$params.')'; |
174 | 174 | } |
175 | 175 | } |
176 | 176 | return $params; |
177 | 177 | } |
178 | 178 | |
179 | - public static function _implodeParams($parameters){ |
|
179 | + public static function _implodeParams($parameters) { |
|
180 | 180 | $allParameters=[]; |
181 | - foreach ($parameters as $params){ |
|
182 | - if(isset($params)) |
|
181 | + foreach ($parameters as $params) { |
|
182 | + if (isset($params)) |
|
183 | 183 | $allParameters[]=self::_correctParams($params); |
184 | 184 | } |
185 | 185 | return \implode("+'&'+", $allParameters); |
186 | 186 | } |
187 | 187 | |
188 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
189 | - if(!isset($ajaxLoader)){ |
|
188 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
189 | + if (!isset($ajaxLoader)) { |
|
190 | 190 | $ajaxLoader=$this->ajaxLoader; |
191 | 191 | } |
192 | 192 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -194,19 +194,19 @@ discard block |
||
194 | 194 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
195 | 195 | } |
196 | 196 | |
197 | - protected function setAjaxDataCall($params){ |
|
197 | + protected function setAjaxDataCall($params) { |
|
198 | 198 | $result=null; |
199 | - if(!\is_callable($params)){ |
|
200 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
201 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
199 | + if (!\is_callable($params)) { |
|
200 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
201 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
202 | 202 | }; |
203 | 203 | } |
204 | 204 | return $result; |
205 | 205 | } |
206 | 206 | |
207 | - protected function setDefaultParameters(&$parameters,$default){ |
|
208 | - foreach ($default as $k=>$v){ |
|
209 | - if(!isset($parameters[$k])) |
|
207 | + protected function setDefaultParameters(&$parameters, $default) { |
|
208 | + foreach ($default as $k=>$v) { |
|
209 | + if (!isset($parameters[$k])) |
|
210 | 210 | $parameters[$k]=$v; |
211 | 211 | } |
212 | 212 | } |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | * @param string $url The url of the request |
221 | 221 | * @param string $responseElement selector of the HTML element displaying the answer |
222 | 222 | */ |
223 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
224 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
223 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
224 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param string $responseElement selector of the HTML element displaying the answer |
231 | 231 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
232 | 232 | */ |
233 | - public function get($url, $responseElement="",$parameters=[]) { |
|
233 | + public function get($url, $responseElement="", $parameters=[]) { |
|
234 | 234 | $parameters["immediatly"]=true; |
235 | - return $this->_get($url,$responseElement,$parameters); |
|
235 | + return $this->_get($url, $responseElement, $parameters); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | * @param string $responseElement selector of the HTML element displaying the answer |
243 | 243 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
244 | 244 | */ |
245 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
245 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
246 | 246 | $parameters["immediatly"]=true; |
247 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
247 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | * @param array $parameters The ajax parameters, default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
258 | 258 | * @return string |
259 | 259 | */ |
260 | - public function ajaxInterval($method,$url, $interval,$globalName=null,$responseElement="", $parameters=[]){ |
|
261 | - return $this->interval($this->ajaxDeferred($method, $url,$responseElement,$parameters), $interval,$globalName); |
|
260 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[]) { |
|
261 | + return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | * @param string $responseElement selector of the HTML element displaying the answer |
269 | 269 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
270 | 270 | */ |
271 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
271 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
272 | 272 | $parameters["immediatly"]=false; |
273 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
273 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | * @param string $method Method used |
280 | 280 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
281 | 281 | */ |
282 | - private function _json($url, $method="get",$parameters=[]) { |
|
283 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
282 | + private function _json($url, $method="get", $parameters=[]) { |
|
283 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
284 | 284 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
285 | 285 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
286 | 286 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";" |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
289 | 289 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
290 | 290 | $parameters["jsCallback"]=$retour; |
291 | - return $this->_ajax($method, $url,null,$parameters); |
|
291 | + return $this->_ajax($method, $url, null, $parameters); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
299 | 299 | */ |
300 | 300 | public function json($url, $method="get", $parameters=[]) { |
301 | - return $this->_json($url,$method,$parameters); |
|
301 | + return $this->_json($url, $method, $parameters); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | * @param string $method default get |
310 | 310 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
311 | 311 | */ |
312 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
313 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
314 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
312 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
313 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
314 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
324 | 324 | $parameters["immediatly"]=false; |
325 | - return $this->_json($url,$method,$parameters); |
|
325 | + return $this->_json($url, $method, $parameters); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -333,27 +333,27 @@ discard block |
||
333 | 333 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
334 | 334 | */ |
335 | 335 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
336 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
336 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
337 | 337 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
338 | 338 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
339 | 339 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
340 | - if($context===null){ |
|
340 | + if ($context===null) { |
|
341 | 341 | $parent="$('".$maskSelector."').parent()"; |
342 | - $newElm = "$('#'+newId)"; |
|
343 | - }else{ |
|
342 | + $newElm="$('#'+newId)"; |
|
343 | + } else { |
|
344 | 344 | $parent=$context; |
345 | - $newElm = $context.".find('#'+newId)"; |
|
345 | + $newElm=$context.".find('#'+newId)"; |
|
346 | 346 | } |
347 | 347 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
348 | 348 | $retour=$parent.".find('.{$rowClass}').remove();"; |
349 | 349 | $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(); |
350 | 350 | 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"; |
351 | - $retour.= $appendTo; |
|
351 | + $retour.=$appendTo; |
|
352 | 352 | $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"; |
353 | 353 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
354 | 354 | $retour.="\t".$jsCallback; |
355 | 355 | $parameters["jsCallback"]=$retour; |
356 | - return $this->_ajax($method, $url,null,$parameters); |
|
356 | + return $this->_ajax($method, $url, null, $parameters); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
365 | 365 | */ |
366 | 366 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
367 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
367 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -387,9 +387,9 @@ discard block |
||
387 | 387 | * @param string $method Method used, default : get |
388 | 388 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
389 | 389 | */ |
390 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
391 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
392 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
390 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
391 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
392 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | */ |
402 | 402 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
403 | 403 | $parameters["immediatly"]=false; |
404 | - return $this->_get($url, $responseElement,$parameters); |
|
404 | + return $this->_get($url, $responseElement, $parameters); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | /** |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | * @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) |
415 | 415 | */ |
416 | 416 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
417 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
418 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
417 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
418 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @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) |
429 | 429 | */ |
430 | 430 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
431 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
432 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
431 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
432 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -463,15 +463,15 @@ discard block |
||
463 | 463 | * @param array $parameters 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) |
464 | 464 | * @return $this |
465 | 465 | */ |
466 | - public function getHref($element,$responseElement="",$parameters=array()){ |
|
466 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
467 | 467 | $parameters["attr"]="href"; |
468 | - if(JString::isNull($responseElement)){ |
|
468 | + if (JString::isNull($responseElement)) { |
|
469 | 469 | $responseElement='%$(self).attr("data-target")%'; |
470 | 470 | } |
471 | - if(!isset($parameters["historize"])){ |
|
471 | + if (!isset($parameters["historize"])) { |
|
472 | 472 | $parameters["historize"]=true; |
473 | 473 | } |
474 | - return $this->getOnClick($element, "",$responseElement,$parameters); |
|
474 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -481,20 +481,20 @@ discard block |
||
481 | 481 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
482 | 482 | * @return $this |
483 | 483 | */ |
484 | - public function postHref($element,$responseElement="",$parameters=array()){ |
|
484 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
485 | 485 | $parameters["attr"]="href"; |
486 | - if(JString::isNull($responseElement)){ |
|
486 | + if (JString::isNull($responseElement)) { |
|
487 | 487 | $responseElement='%$(this).attr("data-target")%'; |
488 | 488 | } |
489 | - if(!isset($parameters["historize"])){ |
|
489 | + if (!isset($parameters["historize"])) { |
|
490 | 490 | $parameters["historize"]=true; |
491 | 491 | } |
492 | - return $this->postOnClick($element, "","{}",$responseElement,$parameters); |
|
492 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
493 | 493 | } |
494 | 494 | |
495 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
495 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
496 | 496 | $parameters["params"]=$params; |
497 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
497 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | * @param string $params JSON parameters |
505 | 505 | * @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) |
506 | 506 | */ |
507 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
508 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
507 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
508 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * @param string $responseElement selector of the HTML element displaying the answer |
517 | 517 | * @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) |
518 | 518 | */ |
519 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
519 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
520 | 520 | $parameters["immediatly"]=false; |
521 | 521 | return $this->_post($url, $params, $responseElement, $parameters); |
522 | 522 | } |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | * @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) |
533 | 533 | */ |
534 | 534 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
535 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
536 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
535 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
536 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -550,33 +550,33 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
553 | - if(isset($this->params["ajax"])){ |
|
553 | + if (isset($this->params["ajax"])) { |
|
554 | 554 | extract($this->params["ajax"]); |
555 | 555 | } |
556 | - $params="{}";$validation=false; |
|
556 | + $params="{}"; $validation=false; |
|
557 | 557 | \extract($parameters); |
558 | - $async=($async)?"true":"false"; |
|
558 | + $async=($async) ? "true" : "false"; |
|
559 | 559 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
560 | 560 | $retour=$this->_getAjaxUrl($url, $attr); |
561 | 561 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
562 | 562 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
563 | - if(isset($params)){ |
|
563 | + if (isset($params)) { |
|
564 | 564 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
565 | 565 | } |
566 | 566 | $responseElement=$this->_getResponseElement($responseElement); |
567 | 567 | $retour.="var self=this;\n"; |
568 | - if($hasLoader===true){ |
|
569 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
570 | - }elseif($hasLoader==="internal"){ |
|
568 | + if ($hasLoader===true) { |
|
569 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
570 | + }elseif ($hasLoader==="internal") { |
|
571 | 571 | $retour.="\n$(this).addClass('loading');"; |
572 | 572 | } |
573 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
574 | - if(isset($headers)){ |
|
573 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
574 | + if (isset($headers)) { |
|
575 | 575 | $ajaxParameters["headers"]=$headers; |
576 | 576 | } |
577 | 577 | $this->createAjaxParameters($ajaxParameters, $parameters); |
578 | 578 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
579 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
579 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
580 | 580 | |
581 | 581 | if ($validation) { |
582 | 582 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -626,8 +626,8 @@ discard block |
||
626 | 626 | * @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) |
627 | 627 | */ |
628 | 628 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
629 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
630 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
629 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
630 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $retour.=$before; |
37 | 37 | if($hasLoader===true && JString::isNotNull($responseElement)){ |
38 | 38 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
39 | - }elseif($hasLoader==="internal"){ |
|
39 | + } elseif($hasLoader==="internal"){ |
|
40 | 40 | $retour.="\n$(this).addClass('loading');"; |
41 | 41 | } |
42 | 42 | $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
@@ -53,8 +53,9 @@ discard block |
||
53 | 53 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
54 | 54 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
55 | 55 | $retour=$this->_addJsCondition($jsCondition,$retour); |
56 | - if ($immediatly) |
|
57 | - $this->jquery_code_for_compile[]=$retour; |
|
56 | + if ($immediatly) { |
|
57 | + $this->jquery_code_for_compile[]=$retour; |
|
58 | + } |
|
58 | 59 | return $retour; |
59 | 60 | } |
60 | 61 | |
@@ -75,7 +76,7 @@ discard block |
||
75 | 76 | } |
76 | 77 | if(is_array($v)){ |
77 | 78 | $s .= "'{$k}':{".self::implodeAjaxParameters($v)."}"; |
78 | - }else{ |
|
79 | + } else{ |
|
79 | 80 | $s .= "'{$k}':{$v}"; |
80 | 81 | } |
81 | 82 | } |
@@ -100,12 +101,13 @@ discard block |
||
100 | 101 | if(JString::isNotNull($attr)){ |
101 | 102 | if ($attr==="value"){ |
102 | 103 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
103 | - }elseif ($attr==="html"){ |
|
104 | + } elseif ($attr==="html"){ |
|
104 | 105 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
105 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
106 | + } elseif(\substr($attr, 0,3)==="js:"){ |
|
106 | 107 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
107 | - }elseif($attr!==null && $attr!=="") |
|
108 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
108 | + } elseif($attr!==null && $attr!=="") { |
|
109 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
110 | + } |
|
109 | 111 | } |
110 | 112 | return $retour; |
111 | 113 | } |
@@ -125,13 +127,14 @@ discard block |
||
125 | 127 | if (JString::isNotNull($responseElement)) { |
126 | 128 | if(isset($ajaxTransition)){ |
127 | 129 | $call=$this->setAjaxDataCall($ajaxTransition); |
128 | - }elseif(isset($this->ajaxTransition)){ |
|
130 | + } elseif(isset($this->ajaxTransition)){ |
|
129 | 131 | $call=$this->ajaxTransition; |
130 | 132 | } |
131 | - if(\is_callable($call)) |
|
132 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
133 | - else |
|
134 | - $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
133 | + if(\is_callable($call)) { |
|
134 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
135 | + } else { |
|
136 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
137 | + } |
|
135 | 138 | } |
136 | 139 | if(isset($history)){ |
137 | 140 | if($this->params["autoActiveLinks"]){ |
@@ -154,8 +157,9 @@ discard block |
||
154 | 157 | } |
155 | 158 | |
156 | 159 | protected function _correctAjaxUrl($url) { |
157 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
158 | - $url=substr($url, 0, strlen($url)-1); |
|
160 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
161 | + $url=substr($url, 0, strlen($url)-1); |
|
162 | + } |
|
159 | 163 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
160 | 164 | $url=$this->getUrl($url); |
161 | 165 | } |
@@ -169,7 +173,7 @@ discard block |
||
169 | 173 | if(\preg_match("@^\{.*?\}$@", $params)){ |
170 | 174 | if( !isset($ajaxParameters['contentType'])|| !UString::contains('json', $ajaxParameters['contentType'])){ |
171 | 175 | return '$.param('.$params.')'; |
172 | - }else{ |
|
176 | + } else{ |
|
173 | 177 | return 'JSON.stringify('.$params.')'; |
174 | 178 | } |
175 | 179 | } |
@@ -179,8 +183,9 @@ discard block |
||
179 | 183 | public static function _implodeParams($parameters){ |
180 | 184 | $allParameters=[]; |
181 | 185 | foreach ($parameters as $params){ |
182 | - if(isset($params)) |
|
183 | - $allParameters[]=self::_correctParams($params); |
|
186 | + if(isset($params)) { |
|
187 | + $allParameters[]=self::_correctParams($params); |
|
188 | + } |
|
184 | 189 | } |
185 | 190 | return \implode("+'&'+", $allParameters); |
186 | 191 | } |
@@ -206,8 +211,9 @@ discard block |
||
206 | 211 | |
207 | 212 | protected function setDefaultParameters(&$parameters,$default){ |
208 | 213 | foreach ($default as $k=>$v){ |
209 | - if(!isset($parameters[$k])) |
|
210 | - $parameters[$k]=$v; |
|
214 | + if(!isset($parameters[$k])) { |
|
215 | + $parameters[$k]=$v; |
|
216 | + } |
|
211 | 217 | } |
212 | 218 | } |
213 | 219 | |
@@ -340,7 +346,7 @@ discard block |
||
340 | 346 | if($context===null){ |
341 | 347 | $parent="$('".$maskSelector."').parent()"; |
342 | 348 | $newElm = "$('#'+newId)"; |
343 | - }else{ |
|
349 | + } else{ |
|
344 | 350 | $parent=$context; |
345 | 351 | $newElm = $context.".find('#'+newId)"; |
346 | 352 | } |
@@ -567,7 +573,7 @@ discard block |
||
567 | 573 | $retour.="var self=this;\n"; |
568 | 574 | if($hasLoader===true){ |
569 | 575 | $this->addLoading($retour, $responseElement,$ajaxLoader); |
570 | - }elseif($hasLoader==="internal"){ |
|
576 | + } elseif($hasLoader==="internal"){ |
|
571 | 577 | $retour.="\n$(this).addClass('loading');"; |
572 | 578 | } |
573 | 579 | $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
@@ -585,8 +591,9 @@ discard block |
||
585 | 591 | $retour.="$('#".$form."').submit();\n"; |
586 | 592 | } |
587 | 593 | $retour=$this->_addJsCondition($jsCondition, $retour); |
588 | - if ($immediatly) |
|
589 | - $this->jquery_code_for_compile[]=$retour; |
|
594 | + if ($immediatly) { |
|
595 | + $this->jquery_code_for_compile[]=$retour; |
|
596 | + } |
|
590 | 597 | return $retour; |
591 | 598 | } |
592 | 599 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @param int $colCount |
23 | 23 | * @return HtmlTable |
24 | 24 | */ |
25 | - public function htmlTable($identifier, $rowCount, $colCount){ |
|
25 | + public function htmlTable($identifier, $rowCount, $colCount) { |
|
26 | 26 | return $this->addHtmlComponent(new HtmlTable($identifier, $rowCount, $colCount)); |
27 | 27 | } |
28 | 28 | |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | * @param $styles string|array|NULL |
34 | 34 | * @return HtmlMessage |
35 | 35 | */ |
36 | - public function htmlMessage($identifier, $content="",$styles=NULL) { |
|
37 | - $msg= $this->addHtmlComponent(new HtmlMessage($identifier, $content)); |
|
38 | - if(isset($msg) && $styles!==null) |
|
36 | + public function htmlMessage($identifier, $content="", $styles=NULL) { |
|
37 | + $msg=$this->addHtmlComponent(new HtmlMessage($identifier, $content)); |
|
38 | + if (isset($msg) && $styles!==null) |
|
39 | 39 | $msg->setStyle($styles); |
40 | 40 | return $msg; |
41 | 41 | } |
@@ -35,8 +35,9 @@ |
||
35 | 35 | */ |
36 | 36 | public function htmlMessage($identifier, $content="",$styles=NULL) { |
37 | 37 | $msg= $this->addHtmlComponent(new HtmlMessage($identifier, $content)); |
38 | - if(isset($msg) && $styles!==null) |
|
39 | - $msg->setStyle($styles); |
|
38 | + if(isset($msg) && $styles!==null) { |
|
39 | + $msg->setStyle($styles); |
|
40 | + } |
|
40 | 41 | return $msg; |
41 | 42 | } |
42 | 43 |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | * @param string $action one of "select","auto","activate","combo","nothing","hide" |
17 | 17 | * @return \Ajax\semantic\components\Dropdown |
18 | 18 | */ |
19 | - public function setAction($action){ |
|
20 | - return $this->setParamCtrl("action", $action,array("select","auto","activate","combo","nothing","hide")); |
|
19 | + public function setAction($action) { |
|
20 | + return $this->setParamCtrl("action", $action, array("select", "auto", "activate", "combo", "nothing", "hide")); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -25,23 +25,23 @@ discard block |
||
25 | 25 | * @param string $event Event used to trigger dropdown (Hover, Click, Custom Event) |
26 | 26 | * @return \Ajax\semantic\components\Dropdown |
27 | 27 | */ |
28 | - public function setOn($event){ |
|
28 | + public function setOn($event) { |
|
29 | 29 | return $this->setParam("on", $event); |
30 | 30 | } |
31 | 31 | |
32 | - public function setFullTextSearch($value){ |
|
32 | + public function setFullTextSearch($value) { |
|
33 | 33 | return $this->setParam("fullTextSearch", $value); |
34 | 34 | } |
35 | 35 | |
36 | - public function setShowOnFocus($value){ |
|
36 | + public function setShowOnFocus($value) { |
|
37 | 37 | return $this->setParam("showOnFocus", $value); |
38 | 38 | } |
39 | 39 | |
40 | - public function setAllowAdditions($value){ |
|
40 | + public function setAllowAdditions($value) { |
|
41 | 41 | return $this->setParam("allowAdditions", $value); |
42 | 42 | } |
43 | 43 | |
44 | - public function setClearable($value){ |
|
44 | + public function setClearable($value) { |
|
45 | 45 | return $this->setParam("clearable", $value); |
46 | 46 | } |
47 | 47 | } |