@@ -7,6 +7,11 @@ |
||
7 | 7 | use Ajax\common\html\HtmlDoubleElement; |
8 | 8 | |
9 | 9 | trait AttachedTrait { |
10 | + |
|
11 | + /** |
|
12 | + * @param string $name |
|
13 | + * @param string $value |
|
14 | + */ |
|
10 | 15 | abstract public function addToPropertyCtrl($name, $value, $typeCtrl); |
11 | 16 | /** |
12 | 17 | * @param HtmlSemDoubleElement $toElement |
@@ -17,6 +17,6 @@ |
||
17 | 17 | if (isset($toElement) && \method_exists($toElement, "setAttached")) { |
18 | 18 | $toElement->setAttached(true); |
19 | 19 | } |
20 | - return $this->addToPropertyCtrl("class", $side . " attached", Side::getConstantValues("attached")); |
|
20 | + return $this->addToPropertyCtrl("class", $side." attached", Side::getConstantValues("attached")); |
|
21 | 21 | } |
22 | 22 | } |
@@ -2,7 +2,6 @@ |
||
2 | 2 | namespace Ajax\semantic\widgets\base; |
3 | 3 | use Ajax\service\JString; |
4 | 4 | use Ajax\semantic\html\elements\HtmlImage; |
5 | -use Ajax\semantic\html\modules\checkbox\HtmlRadio; |
|
6 | 5 | use Ajax\semantic\html\base\constants\Size; |
7 | 6 | use Ajax\semantic\html\elements\HtmlLabel; |
8 | 7 | use Ajax\semantic\html\modules\HtmlProgress; |
@@ -29,23 +29,23 @@ discard block |
||
29 | 29 | * @property boolean $_edition |
30 | 30 | * @property mixed _modelInstance |
31 | 31 | */ |
32 | -trait FieldAsTrait{ |
|
32 | +trait FieldAsTrait { |
|
33 | 33 | |
34 | - abstract protected function _getFieldIdentifier($prefix,$name=""); |
|
35 | - abstract public function setValueFunction($index,$callback); |
|
34 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
35 | + abstract public function setValueFunction($index, $callback); |
|
36 | 36 | abstract protected function _getFieldName($index); |
37 | 37 | abstract protected function _getFieldCaption($index); |
38 | - abstract protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL); |
|
38 | + abstract protected function _buttonAsSubmit(BaseHtml&$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @param HtmlFormField $element |
42 | 42 | * @param array $attributes |
43 | 43 | */ |
44 | - protected function _applyAttributes(BaseHtml $element,&$attributes,$index){ |
|
45 | - if(isset($attributes["jsCallback"])){ |
|
44 | + protected function _applyAttributes(BaseHtml $element, &$attributes, $index) { |
|
45 | + if (isset($attributes["jsCallback"])) { |
|
46 | 46 | $callback=$attributes["jsCallback"]; |
47 | - if(\is_callable($callback)){ |
|
48 | - $callback($element,$this->_modelInstance,$index); |
|
47 | + if (\is_callable($callback)) { |
|
48 | + $callback($element, $this->_modelInstance, $index); |
|
49 | 49 | unset($attributes["jsCallback"]); |
50 | 50 | } |
51 | 51 | } |
@@ -55,43 +55,43 @@ discard block |
||
55 | 55 | $element->fromArray($attributes); |
56 | 56 | } |
57 | 57 | |
58 | - private function _getLabelField($caption,$icon=NULL){ |
|
59 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
58 | + private function _getLabelField($caption, $icon=NULL) { |
|
59 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
60 | 60 | return $label; |
61 | 61 | } |
62 | 62 | |
63 | 63 | |
64 | - protected function _addRules(HtmlFormField $element,&$attributes){ |
|
65 | - if(isset($attributes["rules"])){ |
|
64 | + protected function _addRules(HtmlFormField $element, &$attributes) { |
|
65 | + if (isset($attributes["rules"])) { |
|
66 | 66 | $rules=$attributes["rules"]; |
67 | - if(\is_array($rules)){ |
|
67 | + if (\is_array($rules)) { |
|
68 | 68 | $element->addRules($rules); |
69 | 69 | } |
70 | - else{ |
|
70 | + else { |
|
71 | 71 | $element->addRule($rules); |
72 | 72 | } |
73 | 73 | unset($attributes["rules"]); |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - protected function _prepareFormFields(HtmlFormField &$field,$name,&$attributes){ |
|
77 | + protected function _prepareFormFields(HtmlFormField&$field, $name, &$attributes) { |
|
78 | 78 | $field->setName($name); |
79 | 79 | $this->_addRules($field, $attributes); |
80 | 80 | return $field; |
81 | 81 | } |
82 | 82 | |
83 | - protected function _fieldAs($elementCallback,&$index,$attributes=NULL,$prefix=null){ |
|
84 | - $this->setValueFunction($index,function($value,$instance,$index) use (&$attributes,$elementCallback,$prefix){ |
|
83 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
84 | + $this->setValueFunction($index, function($value, $instance, $index) use (&$attributes, $elementCallback, $prefix){ |
|
85 | 85 | $caption=$this->_getFieldCaption($index); |
86 | 86 | $name=$this->_getFieldName($index); |
87 | - $id=$this->_getFieldIdentifier($prefix,$name); |
|
88 | - if(isset($attributes["name"])){ |
|
87 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
88 | + if (isset($attributes["name"])) { |
|
89 | 89 | $name=$attributes["name"]; |
90 | 90 | unset($attributes["name"]); |
91 | 91 | } |
92 | - $element=$elementCallback($id,$name,$value,$caption); |
|
93 | - if(\is_array($attributes)){ |
|
94 | - $this->_applyAttributes($element, $attributes,$index); |
|
92 | + $element=$elementCallback($id, $name, $value, $caption); |
|
93 | + if (\is_array($attributes)) { |
|
94 | + $this->_applyAttributes($element, $attributes, $index); |
|
95 | 95 | } |
96 | 96 | $element->setDisabled(!$this->_edition); |
97 | 97 | return $element; |
@@ -100,178 +100,178 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | |
103 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
104 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
105 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
103 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
104 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
105 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
106 | 106 | return $pb; |
107 | 107 | }); |
108 | 108 | return $this; |
109 | 109 | } |
110 | 110 | |
111 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
112 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
113 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
111 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
112 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
113 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
114 | 114 | return $rating; |
115 | 115 | }); |
116 | 116 | return $this; |
117 | 117 | } |
118 | 118 | |
119 | - public function fieldAsLabel($index,$icon=NULL,$attributes=NULL){ |
|
120 | - return $this->_fieldAs(function($id,$name,$value) use($icon){ |
|
121 | - $lbl=new HtmlLabel($id,$value); |
|
122 | - if(isset($icon)) |
|
119 | + public function fieldAsLabel($index, $icon=NULL, $attributes=NULL) { |
|
120 | + return $this->_fieldAs(function($id, $name, $value) use($icon){ |
|
121 | + $lbl=new HtmlLabel($id, $value); |
|
122 | + if (isset($icon)) |
|
123 | 123 | $lbl->addIcon($icon); |
124 | 124 | return $lbl; |
125 | - }, $index,$attributes,"label"); |
|
125 | + }, $index, $attributes, "label"); |
|
126 | 126 | } |
127 | 127 | |
128 | - public function fieldAsHeader($index,$niveau=1,$icon=NULL,$attributes=NULL){ |
|
129 | - return $this->_fieldAs(function($id,$name,$value) use($niveau,$icon){ |
|
130 | - $header=new HtmlHeader($id,$niveau,$value); |
|
131 | - if(isset($icon)) |
|
128 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
129 | + return $this->_fieldAs(function($id, $name, $value) use($niveau, $icon){ |
|
130 | + $header=new HtmlHeader($id, $niveau, $value); |
|
131 | + if (isset($icon)) |
|
132 | 132 | $header->asIcon($icon, $value); |
133 | 133 | return $header; |
134 | - }, $index,$attributes,"header"); |
|
134 | + }, $index, $attributes, "header"); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | |
138 | - public function fieldAsImage($index,$size=Size::MINI,$circular=false){ |
|
139 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
140 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
138 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
139 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
140 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
141 | 141 | return $image; |
142 | 142 | }); |
143 | 143 | return $this; |
144 | 144 | } |
145 | 145 | |
146 | - public function fieldAsFlag($index){ |
|
147 | - $this->setValueFunction($index,function($flag){ |
|
148 | - $flag=new HtmlFlag($this->_getFieldIdentifier("flag"),$flag); |
|
146 | + public function fieldAsFlag($index) { |
|
147 | + $this->setValueFunction($index, function($flag) { |
|
148 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
149 | 149 | return $flag; |
150 | 150 | }); |
151 | 151 | return $this; |
152 | 152 | } |
153 | 153 | |
154 | - public function fieldAsAvatar($index,$attributes=NULL){ |
|
155 | - return $this->_fieldAs(function($id,$name,$value){ |
|
156 | - $img=new HtmlImage($id,$value); |
|
154 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
155 | + return $this->_fieldAs(function($id, $name, $value) { |
|
156 | + $img=new HtmlImage($id, $value); |
|
157 | 157 | $img->asAvatar(); |
158 | 158 | return $img; |
159 | - }, $index,$attributes,"avatar"); |
|
159 | + }, $index, $attributes, "avatar"); |
|
160 | 160 | } |
161 | 161 | |
162 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
163 | - return $this->_fieldAs(function($id,$name,$value) use($attributes){ |
|
164 | - $input= new HtmlFormRadio($id,$name,$value,$value); |
|
162 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
163 | + return $this->_fieldAs(function($id, $name, $value) use($attributes){ |
|
164 | + $input=new HtmlFormRadio($id, $name, $value, $value); |
|
165 | 165 | return $this->_prepareFormFields($input, $name, $attributes); |
166 | - }, $index,$attributes,"radio"); |
|
166 | + }, $index, $attributes, "radio"); |
|
167 | 167 | } |
168 | 168 | |
169 | - public function fieldAsRadios($index,$elements=[],$attributes=NULL){ |
|
170 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($elements){ |
|
171 | - return HtmlFormFields::radios($name,$elements,$caption,$value); |
|
172 | - }, $index,$attributes,"radios"); |
|
169 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
170 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements){ |
|
171 | + return HtmlFormFields::radios($name, $elements, $caption, $value); |
|
172 | + }, $index, $attributes, "radios"); |
|
173 | 173 | } |
174 | 174 | |
175 | - public function fieldAsInput($index,$attributes=NULL){ |
|
176 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
177 | - $input= new HtmlFormInput($id,$caption,"text",$value); |
|
175 | + public function fieldAsInput($index, $attributes=NULL) { |
|
176 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
177 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
178 | 178 | return $this->_prepareFormFields($input, $name, $attributes); |
179 | - }, $index,$attributes,"input"); |
|
179 | + }, $index, $attributes, "input"); |
|
180 | 180 | } |
181 | 181 | |
182 | - public function fieldAsTextarea($index,$attributes=NULL){ |
|
183 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes){ |
|
184 | - $textarea=new HtmlFormTextarea($id,$caption,$value); |
|
182 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
183 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes){ |
|
184 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
185 | 185 | return $this->_prepareFormFields($textarea, $name, $attributes); |
186 | - }, $index,$attributes,"textarea"); |
|
186 | + }, $index, $attributes, "textarea"); |
|
187 | 187 | } |
188 | 188 | |
189 | - public function fieldAsHidden($index,$attributes=NULL){ |
|
190 | - if(!\is_array($attributes)){ |
|
189 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
190 | + if (!\is_array($attributes)) { |
|
191 | 191 | $attributes=[]; |
192 | 192 | } |
193 | 193 | $attributes["inputType"]="hidden"; |
194 | - return $this->fieldAsInput($index,$attributes); |
|
194 | + return $this->fieldAsInput($index, $attributes); |
|
195 | 195 | } |
196 | 196 | |
197 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
198 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($attributes){ |
|
199 | - if($caption===null || $caption==="") |
|
197 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
198 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($attributes){ |
|
199 | + if ($caption===null || $caption==="") |
|
200 | 200 | $caption=""; |
201 | - $input=new HtmlFormCheckbox($id,$caption,$this->_instanceViewer->getIdentifier()); |
|
201 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
202 | 202 | $input->setChecked(JString::isBooleanTrue($value)); |
203 | 203 | return $this->_prepareFormFields($input, $name, $attributes); |
204 | - }, $index,$attributes,"ck"); |
|
204 | + }, $index, $attributes, "ck"); |
|
205 | 205 | } |
206 | 206 | |
207 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
208 | - return $this->_fieldAs(function($id,$name,$value,$caption) use($elements,$multiple,$attributes){ |
|
209 | - $dd=new HtmlFormDropdown($id,$elements,$caption,$value); |
|
210 | - $dd->asSelect($name,$multiple); |
|
207 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
208 | + return $this->_fieldAs(function($id, $name, $value, $caption) use($elements, $multiple, $attributes){ |
|
209 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value); |
|
210 | + $dd->asSelect($name, $multiple); |
|
211 | 211 | return $this->_prepareFormFields($dd, $name, $attributes); |
212 | - }, $index,$attributes,"dd"); |
|
212 | + }, $index, $attributes, "dd"); |
|
213 | 213 | } |
214 | 214 | |
215 | - public function fieldAsMessage($index,$attributes=NULL){ |
|
216 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
217 | - $mess= new HtmlMessage("message-".$id,$caption); |
|
215 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
216 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
217 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
218 | 218 | $mess->addHeader($value); |
219 | 219 | return $mess; |
220 | - }, $index,$attributes,"message"); |
|
220 | + }, $index, $attributes, "message"); |
|
221 | 221 | } |
222 | 222 | |
223 | - public function fieldAsLink($index,$attributes=NULL){ |
|
224 | - return $this->_fieldAs(function($id,$name,$value,$caption){ |
|
225 | - $lnk= new HtmlLink("message-".$id,"#",$caption); |
|
223 | + public function fieldAsLink($index, $attributes=NULL) { |
|
224 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
225 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
226 | 226 | return $lnk; |
227 | - }, $index,$attributes,"link"); |
|
227 | + }, $index, $attributes, "link"); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /**Change fields type |
231 | 231 | * @param array $types an array or associative array $type=>$attributes |
232 | 232 | */ |
233 | - public function fieldsAs(array $types){ |
|
233 | + public function fieldsAs(array $types) { |
|
234 | 234 | $i=0; |
235 | - if(JArray::isAssociative($types)){ |
|
236 | - foreach ($types as $type=>$attributes){ |
|
237 | - if(\is_int($type)) |
|
238 | - $this->fieldAs($i++,$attributes,[]); |
|
239 | - else{ |
|
240 | - $type=preg_replace('/\d/', '', $type ); |
|
241 | - $this->fieldAs($i++,$type,$attributes); |
|
235 | + if (JArray::isAssociative($types)) { |
|
236 | + foreach ($types as $type=>$attributes) { |
|
237 | + if (\is_int($type)) |
|
238 | + $this->fieldAs($i++, $attributes, []); |
|
239 | + else { |
|
240 | + $type=preg_replace('/\d/', '', $type); |
|
241 | + $this->fieldAs($i++, $type, $attributes); |
|
242 | 242 | } |
243 | 243 | } |
244 | - }else{ |
|
245 | - foreach ($types as $type){ |
|
246 | - $this->fieldAs($i++,$type); |
|
244 | + } else { |
|
245 | + foreach ($types as $type) { |
|
246 | + $this->fieldAs($i++, $type); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
251 | - public function fieldAs($index,$type,$attributes=NULL){ |
|
251 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
252 | 252 | $method="fieldAs".\ucfirst($type); |
253 | - if(\method_exists($this, $method)){ |
|
254 | - if(!\is_array($attributes)){ |
|
253 | + if (\method_exists($this, $method)) { |
|
254 | + if (!\is_array($attributes)) { |
|
255 | 255 | $attributes=[$index]; |
256 | - }else{ |
|
256 | + } else { |
|
257 | 257 | \array_unshift($attributes, $index); |
258 | 258 | } |
259 | - \call_user_func_array([$this,$method], $attributes); |
|
259 | + \call_user_func_array([$this, $method], $attributes); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
264 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$attributes){ |
|
265 | - $button=new HtmlButton($id,$caption,$cssStyle); |
|
266 | - $this->_buttonAsSubmit($button,"click",$url,$responseElement,@$attributes["ajax"]); |
|
263 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
264 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes){ |
|
265 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
266 | + $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
|
267 | 267 | return $button; |
268 | - }, $index,$attributes,"submit"); |
|
268 | + }, $index, $attributes, "submit"); |
|
269 | 269 | } |
270 | 270 | |
271 | - public function fieldAsButton($index,$cssStyle=NULL,$attributes=NULL){ |
|
272 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($cssStyle){ |
|
273 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
271 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
272 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle){ |
|
273 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
274 | 274 | return $button; |
275 | - }, $index,$attributes,"button"); |
|
275 | + }, $index, $attributes, "button"); |
|
276 | 276 | } |
277 | 277 | } |