@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | trait FieldAsTrait { |
38 | 38 | |
39 | - abstract protected function _getFieldIdentifier($prefix, $name = ""); |
|
39 | + abstract protected function _getFieldIdentifier($prefix, $name=""); |
|
40 | 40 | |
41 | 41 | abstract public function setValueFunction($index, $callback); |
42 | 42 | |
@@ -44,16 +44,16 @@ discard block |
||
44 | 44 | |
45 | 45 | abstract protected function _getFieldCaption($index); |
46 | 46 | |
47 | - abstract protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement = NULL, $parameters = NULL); |
|
47 | + abstract protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement=NULL, $parameters=NULL); |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * |
51 | 51 | * @param HtmlFormField $element |
52 | 52 | * @param array $attributes |
53 | 53 | */ |
54 | - protected function _applyAttributes(BaseHtml $element, &$attributes, $index, $instance = null) { |
|
54 | + protected function _applyAttributes(BaseHtml $element, &$attributes, $index, $instance=null) { |
|
55 | 55 | if (isset($attributes["jsCallback"])) { |
56 | - $callback = $attributes["jsCallback"]; |
|
56 | + $callback=$attributes["jsCallback"]; |
|
57 | 57 | if (\is_callable($callback)) { |
58 | 58 | $callback($element, $instance, $index, InstanceViewer::$index); |
59 | 59 | } |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | $element->fromArray($attributes); |
65 | 65 | } |
66 | 66 | |
67 | - private function _getLabelField($caption, $icon = NULL) { |
|
68 | - $label = new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
67 | + private function _getLabelField($caption, $icon=NULL) { |
|
68 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
69 | 69 | return $label; |
70 | 70 | } |
71 | 71 | |
72 | 72 | protected function _addRules(HtmlFormField $element, &$attributes) { |
73 | 73 | if (isset($attributes["rules"])) { |
74 | - $this->_hasRules = true; |
|
75 | - $rules = $attributes["rules"]; |
|
74 | + $this->_hasRules=true; |
|
75 | + $rules=$attributes["rules"]; |
|
76 | 76 | if (\is_array($rules)) { |
77 | 77 | $element->addRules($rules); |
78 | 78 | } else { |
@@ -88,62 +88,62 @@ discard block |
||
88 | 88 | return $field; |
89 | 89 | } |
90 | 90 | |
91 | - protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $prefix = null) { |
|
92 | - $this->setValueFunction($index, function ($value, $instance, $index, $rowIndex) use (&$attributes, $elementCallback, $prefix) { |
|
93 | - $caption = $this->_getFieldCaption($index); |
|
94 | - $name = $this->_getFieldName($index); |
|
95 | - $id = $this->_getFieldIdentifier($prefix, $name); |
|
91 | + protected function _fieldAs($elementCallback, &$index, $attributes=NULL, $prefix=null) { |
|
92 | + $this->setValueFunction($index, function($value, $instance, $index, $rowIndex) use (&$attributes, $elementCallback, $prefix) { |
|
93 | + $caption=$this->_getFieldCaption($index); |
|
94 | + $name=$this->_getFieldName($index); |
|
95 | + $id=$this->_getFieldIdentifier($prefix, $name); |
|
96 | 96 | if (isset($attributes["name"])) { |
97 | - $name = $attributes["name"]; |
|
97 | + $name=$attributes["name"]; |
|
98 | 98 | unset($attributes["name"]); |
99 | 99 | } |
100 | - $element = $elementCallback($id, $name, $value, $caption); |
|
100 | + $element=$elementCallback($id, $name, $value, $caption); |
|
101 | 101 | if (\is_array($attributes)) { |
102 | 102 | $this->_applyAttributes($element, $attributes, $index, $instance); |
103 | 103 | } |
104 | - $element->setDisabled(! $this->_edition); |
|
104 | + $element->setDisabled(!$this->_edition); |
|
105 | 105 | return $element; |
106 | 106 | }); |
107 | 107 | return $this; |
108 | 108 | } |
109 | 109 | |
110 | - public function fieldAsProgress($index, $label = NULL, $attributes = array()) { |
|
111 | - $this->setValueFunction($index, function ($value) use ($label, $attributes) { |
|
112 | - $pb = new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
110 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
111 | + $this->setValueFunction($index, function($value) use ($label, $attributes) { |
|
112 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
113 | 113 | return $pb; |
114 | 114 | }); |
115 | 115 | return $this; |
116 | 116 | } |
117 | 117 | |
118 | - public function fieldAsRating($index, $max = 5, $icon = "") { |
|
119 | - $this->setValueFunction($index, function ($value) use ($max, $icon) { |
|
120 | - $rating = new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
118 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
119 | + $this->setValueFunction($index, function($value) use ($max, $icon) { |
|
120 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
121 | 121 | return $rating; |
122 | 122 | }); |
123 | 123 | return $this; |
124 | 124 | } |
125 | 125 | |
126 | - public function fieldAsLabel($index, $icon = NULL, $attributes = NULL) { |
|
127 | - return $this->_fieldAs(function ($id, $name, $value) use ($icon) { |
|
128 | - $lbl = new HtmlLabel($id, $value); |
|
126 | + public function fieldAsLabel($index, $icon=NULL, $attributes=NULL) { |
|
127 | + return $this->_fieldAs(function($id, $name, $value) use ($icon) { |
|
128 | + $lbl=new HtmlLabel($id, $value); |
|
129 | 129 | if (isset($icon)) |
130 | 130 | $lbl->addIcon($icon); |
131 | 131 | return $lbl; |
132 | 132 | }, $index, $attributes, "label"); |
133 | 133 | } |
134 | 134 | |
135 | - public function fieldAsHeader($index, $niveau = 1, $icon = NULL, $attributes = NULL) { |
|
136 | - return $this->_fieldAs(function ($id, $name, $value) use ($niveau, $icon) { |
|
137 | - $header = new HtmlHeader($id, $niveau, $value); |
|
135 | + public function fieldAsHeader($index, $niveau=1, $icon=NULL, $attributes=NULL) { |
|
136 | + return $this->_fieldAs(function($id, $name, $value) use ($niveau, $icon) { |
|
137 | + $header=new HtmlHeader($id, $niveau, $value); |
|
138 | 138 | if (isset($icon)) |
139 | 139 | $header->asIcon($icon, $value); |
140 | 140 | return $header; |
141 | 141 | }, $index, $attributes, "header"); |
142 | 142 | } |
143 | 143 | |
144 | - public function fieldAsImage($index, $size = Size::MINI, $circular = false) { |
|
145 | - $this->setValueFunction($index, function ($img) use ($size, $circular) { |
|
146 | - $image = new HtmlImage($this->_getFieldIdentifier("image"), $img); |
|
144 | + public function fieldAsImage($index, $size=Size::MINI, $circular=false) { |
|
145 | + $this->setValueFunction($index, function($img) use ($size, $circular) { |
|
146 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); |
|
147 | 147 | $image->setSize($size); |
148 | 148 | if ($circular) |
149 | 149 | $image->setCircular(); |
@@ -153,131 +153,131 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | public function fieldAsFlag($index) { |
156 | - $this->setValueFunction($index, function ($flag) { |
|
157 | - $flag = new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
156 | + $this->setValueFunction($index, function($flag) { |
|
157 | + $flag=new HtmlFlag($this->_getFieldIdentifier("flag"), $flag); |
|
158 | 158 | return $flag; |
159 | 159 | }); |
160 | 160 | return $this; |
161 | 161 | } |
162 | 162 | |
163 | 163 | public function fieldAsIcon($index) { |
164 | - $this->setValueFunction($index, function ($icon) { |
|
165 | - $icon = new HtmlIcon($this->_getFieldIdentifier("icon"), $icon); |
|
164 | + $this->setValueFunction($index, function($icon) { |
|
165 | + $icon=new HtmlIcon($this->_getFieldIdentifier("icon"), $icon); |
|
166 | 166 | return $icon; |
167 | 167 | }); |
168 | 168 | return $this; |
169 | 169 | } |
170 | 170 | |
171 | - public function fieldAsAvatar($index, $attributes = NULL) { |
|
172 | - return $this->_fieldAs(function ($id, $name, $value) { |
|
173 | - $img = new HtmlImage($id, $value); |
|
171 | + public function fieldAsAvatar($index, $attributes=NULL) { |
|
172 | + return $this->_fieldAs(function($id, $name, $value) { |
|
173 | + $img=new HtmlImage($id, $value); |
|
174 | 174 | $img->asAvatar(); |
175 | 175 | return $img; |
176 | 176 | }, $index, $attributes, "avatar"); |
177 | 177 | } |
178 | 178 | |
179 | - public function fieldAsRadio($index, $attributes = NULL) { |
|
180 | - return $this->_fieldAs(function ($id, $name, $value) use ($attributes) { |
|
181 | - $input = new HtmlFormRadio($id, $name, $value, $value); |
|
179 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
180 | + return $this->_fieldAs(function($id, $name, $value) use ($attributes) { |
|
181 | + $input=new HtmlFormRadio($id, $name, $value, $value); |
|
182 | 182 | return $this->_prepareFormFields($input, $name, $attributes); |
183 | 183 | }, $index, $attributes, "radio"); |
184 | 184 | } |
185 | 185 | |
186 | - public function fieldAsRadios($index, $elements = [], $attributes = NULL) { |
|
187 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($elements) { |
|
186 | + public function fieldAsRadios($index, $elements=[], $attributes=NULL) { |
|
187 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements) { |
|
188 | 188 | return HtmlFormFields::radios($name, $elements, $caption, $value); |
189 | 189 | }, $index, $attributes, "radios"); |
190 | 190 | } |
191 | 191 | |
192 | - public function fieldAsList($index, $classNames = "", $attributes = NULL) { |
|
193 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($classNames) { |
|
194 | - $result = new HtmlList($name, $value); |
|
192 | + public function fieldAsList($index, $classNames="", $attributes=NULL) { |
|
193 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($classNames) { |
|
194 | + $result=new HtmlList($name, $value); |
|
195 | 195 | $result->addClass($classNames); |
196 | 196 | return $result; |
197 | 197 | }, $index, $attributes, "list"); |
198 | 198 | } |
199 | 199 | |
200 | - public function fieldAsInput($index, $attributes = NULL) { |
|
201 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
202 | - $input = new HtmlFormInput($id, $caption, "text", $value); |
|
200 | + public function fieldAsInput($index, $attributes=NULL) { |
|
201 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
202 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
203 | 203 | return $this->_prepareFormFields($input, $name, $attributes); |
204 | 204 | }, $index, $attributes, "input"); |
205 | 205 | } |
206 | 206 | |
207 | - public function fieldAsDataList($index, ?array $items = [], $attributes = NULL) { |
|
208 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes, $items) { |
|
209 | - $input = new HtmlFormInput($id, $caption, "text", $value); |
|
207 | + public function fieldAsDataList($index, ?array $items=[], $attributes=NULL) { |
|
208 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes, $items) { |
|
209 | + $input=new HtmlFormInput($id, $caption, "text", $value); |
|
210 | 210 | $input->getField() |
211 | 211 | ->addDataList($items); |
212 | 212 | return $this->_prepareFormFields($input, $name, $attributes); |
213 | 213 | }, $index, $attributes, "input"); |
214 | 214 | } |
215 | 215 | |
216 | - public function fieldAsFile($index, $attributes = NULL) { |
|
216 | + public function fieldAsFile($index, $attributes=NULL) { |
|
217 | 217 | if (isset($this->_form)) { |
218 | 218 | $this->_form->setProperty('enctype', 'multipart/form-data'); |
219 | 219 | } |
220 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
221 | - $input = new HtmlFormInput($id, $caption); |
|
220 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
221 | + $input=new HtmlFormInput($id, $caption); |
|
222 | 222 | $input->asFile(); |
223 | 223 | return $this->_prepareFormFields($input, $name, $attributes); |
224 | 224 | }, $index, $attributes, "input"); |
225 | 225 | } |
226 | 226 | |
227 | - public function fieldAsTextarea($index, $attributes = NULL) { |
|
228 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
229 | - $textarea = new HtmlFormTextarea($id, $caption, $value); |
|
227 | + public function fieldAsTextarea($index, $attributes=NULL) { |
|
228 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
229 | + $textarea=new HtmlFormTextarea($id, $caption, $value); |
|
230 | 230 | return $this->_prepareFormFields($textarea, $name, $attributes); |
231 | 231 | }, $index, $attributes, "textarea"); |
232 | 232 | } |
233 | 233 | |
234 | - public function fieldAsElement($index, $tagName = "div", $baseClass = "", $attributes = NULL) { |
|
235 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass) { |
|
236 | - $div = new HtmlSemDoubleElement($id, $tagName, $baseClass); |
|
234 | + public function fieldAsElement($index, $tagName="div", $baseClass="", $attributes=NULL) { |
|
235 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass) { |
|
236 | + $div=new HtmlSemDoubleElement($id, $tagName, $baseClass); |
|
237 | 237 | $div->setContent(\htmlentities($value)); |
238 | - $textarea = new HtmlFormField("field-" . $id, $div, $caption); |
|
238 | + $textarea=new HtmlFormField("field-".$id, $div, $caption); |
|
239 | 239 | return $this->_prepareFormFields($textarea, $name, $attributes); |
240 | 240 | }, $index, $attributes, "element"); |
241 | 241 | } |
242 | 242 | |
243 | - public function fieldAsHidden($index, $attributes = NULL) { |
|
244 | - if (! \is_array($attributes)) { |
|
245 | - $attributes = []; |
|
243 | + public function fieldAsHidden($index, $attributes=NULL) { |
|
244 | + if (!\is_array($attributes)) { |
|
245 | + $attributes=[]; |
|
246 | 246 | } |
247 | - $attributes["inputType"] = "hidden"; |
|
248 | - $attributes["style"] = "display:none;"; |
|
247 | + $attributes["inputType"]="hidden"; |
|
248 | + $attributes["style"]="display:none;"; |
|
249 | 249 | return $this->fieldAsInput($index, $attributes); |
250 | 250 | } |
251 | 251 | |
252 | - public function fieldAsCheckbox($index, $attributes = NULL) { |
|
253 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($attributes) { |
|
254 | - if ($caption === null || $caption === "") |
|
255 | - $caption = ""; |
|
256 | - $input = new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
252 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
253 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($attributes) { |
|
254 | + if ($caption===null || $caption==="") |
|
255 | + $caption=""; |
|
256 | + $input=new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier()); |
|
257 | 257 | $input->setChecked(JString::isBooleanTrue($value)); |
258 | 258 | return $this->_prepareFormFields($input, $name, $attributes); |
259 | 259 | }, $index, $attributes, "ck"); |
260 | 260 | } |
261 | 261 | |
262 | - public function fieldAsDropDown($index, $elements = [], $multiple = false, $attributes = NULL) { |
|
263 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($elements, $multiple, $attributes) { |
|
264 | - $dd = new HtmlFormDropdown($id, $elements, $caption, $value ?? ''); |
|
262 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
263 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($elements, $multiple, $attributes) { |
|
264 | + $dd=new HtmlFormDropdown($id, $elements, $caption, $value ?? ''); |
|
265 | 265 | $dd->asSelect($name, $multiple); |
266 | 266 | return $this->_prepareFormFields($dd, $name, $attributes); |
267 | 267 | }, $index, $attributes, "dd"); |
268 | 268 | } |
269 | 269 | |
270 | - public function fieldAsMessage($index, $attributes = NULL) { |
|
271 | - return $this->_fieldAs(function ($id, $name, $value, $caption) { |
|
272 | - $mess = new HtmlMessage("message-" . $id, $caption); |
|
270 | + public function fieldAsMessage($index, $attributes=NULL) { |
|
271 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
272 | + $mess=new HtmlMessage("message-".$id, $caption); |
|
273 | 273 | $mess->addHeader($value); |
274 | 274 | return $mess; |
275 | 275 | }, $index, $attributes, "message"); |
276 | 276 | } |
277 | 277 | |
278 | - public function fieldAsLink($index, $attributes = NULL) { |
|
279 | - return $this->_fieldAs(function ($id, $name, $value, $caption) { |
|
280 | - $lnk = new HtmlLink("message-" . $id, "#", $caption); |
|
278 | + public function fieldAsLink($index, $attributes=NULL) { |
|
279 | + return $this->_fieldAs(function($id, $name, $value, $caption) { |
|
280 | + $lnk=new HtmlLink("message-".$id, "#", $caption); |
|
281 | 281 | return $lnk; |
282 | 282 | }, $index, $attributes, "link"); |
283 | 283 | } |
@@ -289,28 +289,28 @@ discard block |
||
289 | 289 | * an array or associative array $type=>$attributes |
290 | 290 | */ |
291 | 291 | public function fieldsAs(array $types) { |
292 | - $i = 0; |
|
292 | + $i=0; |
|
293 | 293 | if (JArray::isAssociative($types)) { |
294 | 294 | foreach ($types as $type => $attributes) { |
295 | 295 | if (\is_int($type)) |
296 | - $this->fieldAs($i ++, $attributes, []); |
|
296 | + $this->fieldAs($i++, $attributes, []); |
|
297 | 297 | else { |
298 | - $type = preg_replace('/\d/', '', $type); |
|
299 | - $this->fieldAs($i ++, $type, $attributes); |
|
298 | + $type=preg_replace('/\d/', '', $type); |
|
299 | + $this->fieldAs($i++, $type, $attributes); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | } else { |
303 | 303 | foreach ($types as $type) { |
304 | - $this->fieldAs($i ++, $type); |
|
304 | + $this->fieldAs($i++, $type); |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | - public function fieldAs($index, $type, $attributes = NULL) { |
|
310 | - $method = "fieldAs" . \ucfirst($type); |
|
309 | + public function fieldAs($index, $type, $attributes=NULL) { |
|
310 | + $method="fieldAs".\ucfirst($type); |
|
311 | 311 | if (\method_exists($this, $method)) { |
312 | - if (! \is_array($attributes)) { |
|
313 | - $attributes = [ |
|
312 | + if (!\is_array($attributes)) { |
|
313 | + $attributes=[ |
|
314 | 314 | $index |
315 | 315 | ]; |
316 | 316 | } else { |
@@ -323,17 +323,17 @@ discard block |
||
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
326 | - public function fieldAsSubmit($index, $cssStyle = NULL, $url = NULL, $responseElement = NULL, $attributes = NULL) { |
|
327 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes) { |
|
328 | - $button = new HtmlButton($id, $caption, $cssStyle); |
|
326 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
327 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes) { |
|
328 | + $button=new HtmlButton($id, $caption, $cssStyle); |
|
329 | 329 | $this->_buttonAsSubmit($button, "click", $url, $responseElement, @$attributes["ajax"]); |
330 | 330 | return $button; |
331 | 331 | }, $index, $attributes, "submit"); |
332 | 332 | } |
333 | 333 | |
334 | - public function fieldAsButton($index, $cssStyle = NULL, $attributes = NULL) { |
|
335 | - return $this->_fieldAs(function ($id, $name, $value, $caption) use ($cssStyle) { |
|
336 | - $button = new HtmlButton($id, $value, $cssStyle); |
|
334 | + public function fieldAsButton($index, $cssStyle=NULL, $attributes=NULL) { |
|
335 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($cssStyle) { |
|
336 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
337 | 337 | return $button; |
338 | 338 | }, $index, $attributes, "button"); |
339 | 339 | } |