48 abstract protected function _buttonAsSubmit(
BaseHtml &$button, $event, $url, $responseElement = NULL, $parameters = NULL);
58 if (isset($attributes[
"jsCallback"])) {
59 $callback = $attributes[
"jsCallback"];
60 if (\is_callable($callback)) {
64 unset($attributes[
"rules"]);
65 unset($attributes[
"ajax"]);
66 unset($attributes[
"visibleHover"]);
76 if (isset($attributes[
"rules"])) {
77 $this->_hasRules =
true;
78 $rules = $attributes[
"rules"];
79 if (\is_array($rules)) {
84 unset($attributes[
"rules"]);
94 protected function _fieldAs($elementCallback, &$index, $attributes = NULL, $prefix =
null) {
95 $this->
setValueFunction($index,
function ($value, $instance, $index, $rowIndex) use (&$attributes, $elementCallback, $prefix) {
99 if (isset($attributes[
"name"])) {
100 $name = $attributes[
"name"];
101 unset($attributes[
"name"]);
103 $element = $elementCallback($id, $name, $value, $caption);
104 if (isset($this->_speProperties[$index])) {
106 $attributes += $this->_speProperties[$index];
108 if (\is_array($attributes)) {
111 $element->setDisabled(! $this->_edition);
126 foreach ($indexValues as $index => $value) {
127 $ind = $this->_getIndex($index);
128 $this->_speProperties[$ind][$property] = $value;
133 $this->
setValueFunction($index,
function ($value) use ($label, $attributes) {
148 public function fieldAsLabel($index, $icon = NULL, $attributes = NULL) {
149 return $this->
_fieldAs(
function ($id, $name, $value) use ($icon) {
152 $lbl->addIcon($icon);
154 }, $index, $attributes,
"label");
157 public function fieldAsHeader($index, $niveau = 1, $icon = NULL, $attributes = NULL) {
158 return $this->
_fieldAs(
function ($id, $name, $value) use ($niveau, $icon) {
159 $header =
new HtmlHeader($id, $niveau, $value);
161 $header->asIcon($icon, $value);
163 }, $index, $attributes,
"header");
166 public function fieldAsImage($index, $size = Size::MINI, $circular =
false) {
169 $image->setSize($size);
171 $image->setCircular();
194 return $this->
_fieldAs(
function ($id, $name, $value) {
198 }, $index, $attributes,
"avatar");
202 return $this->
_fieldAs(
function ($id, $name, $value) use ($attributes) {
205 }, $index, $attributes,
"radio");
209 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($elements) {
210 return HtmlFormFields::radios($name, $elements, $caption, $value);
211 }, $index, $attributes,
"radios");
214 public function fieldAsList($index, $classNames =
"", $attributes = NULL) {
215 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($classNames) {
216 $result =
new HtmlList($name, $value);
217 $result->addClass($classNames);
219 }, $index, $attributes,
"list");
223 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($attributes) {
226 }, $index, $attributes,
"input");
230 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($attributes) {
231 $input =
new HtmlFormInput($id,
'',
'text', $value, $caption);
233 if (isset($attributes[
'rules'])) {
234 $rules = json_encode($attributes[
'rules']);
235 if (strpos($rules,
'empty') !==
false) {
236 $required =
'required';
241 ->setTagName(
'label')
242 ->addClass($required);
244 }, $index, $attributes,
'input');
248 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($attributes, $items) {
251 ->addDataList($items);
253 }, $index, $attributes,
"input");
257 if (isset($this->_form)) {
258 $this->_form->setProperty(
'enctype',
'multipart/form-data');
260 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($attributes) {
264 }, $index, $attributes,
"input");
268 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($attributes) {
271 }, $index, $attributes,
"textarea");
274 public function fieldAsElement($index, $tagName =
"div", $baseClass =
"", $attributes = NULL) {
275 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($attributes, $tagName, $baseClass) {
277 $div->setContent(\htmlentities($value));
278 $textarea =
new HtmlFormField(
"field-" . $id, $div, $caption);
280 }, $index, $attributes,
"element");
284 if (! \is_array($attributes)) {
287 $attributes[
"inputType"] =
"hidden";
288 $attributes[
"style"] =
"display:none;";
293 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($attributes) {
294 if ($caption ===
null || $caption ===
"")
296 $input =
new HtmlFormCheckbox($id, $caption, $this->_instanceViewer->getIdentifier());
297 $input->setChecked(JString::isBooleanTrue($value));
299 }, $index, $attributes,
"ck");
302 public function fieldAsDropDown($index, $elements = [], $multiple =
false, $attributes = NULL) {
303 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($elements, $multiple, $attributes) {
305 $dd->asSelect($name, $multiple);
307 }, $index, $attributes,
"dd");
311 return $this->
_fieldAs(
function ($id, $name, $value, $caption) {
312 $mess =
new HtmlMessage(
"message-" . $id, $caption);
313 $mess->addHeader($value);
315 }, $index, $attributes,
"message");
319 return $this->
_fieldAs(
function ($id, $name, $value, $caption) {
320 $lnk =
new HtmlLink(
"message-" . $id,
"#", $caption);
322 }, $index, $attributes,
"link");
333 if (JArray::isAssociative($types)) {
334 foreach ($types as $type => $attributes) {
336 $this->
fieldAs($i ++, $attributes, []);
338 $type = preg_replace(
'/\d/',
'', $type);
339 $this->
fieldAs($i ++, $type, $attributes);
343 foreach ($types as $type) {
349 public function fieldAs($index, $type, $attributes = NULL) {
350 $method =
"fieldAs" . \ucfirst($type);
351 if (\method_exists($this, $method)) {
352 if (! \is_array($attributes)) {
357 \array_unshift($attributes, $index);
359 \call_user_func_array([
366 public function fieldAsSubmit($index, $cssStyle = NULL, $url = NULL, $responseElement = NULL, $attributes = NULL) {
367 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $attributes) {
368 $button =
new HtmlButton($id, $caption, $cssStyle);
369 $this->
_buttonAsSubmit($button,
"click", $url, $responseElement, $attributes[
"ajax"] ?? []);
371 }, $index, $attributes,
"submit");
374 public function fieldAsButton($index, $cssStyle = NULL, $attributes = NULL) {
375 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($cssStyle) {
376 $button =
new HtmlButton($id, $value, $cssStyle);
378 }, $index, $attributes,
"button");
381 public function fieldAsDataTable($index, $model, $instances =
null, $fields = [], $attributes = NULL) {
382 return $this->
_fieldAs(
function ($id, $name, $value, $caption) use ($model, $instances, $fields, $index) {
383 $dt =
new DataTable($id, $model, $instances);
384 $dt->setNamePrefix($index);
385 $dt->setFields($fields);
386 $dt->setEdition(
true);
387 $dt->addDeleteButton(
false, [],
function ($bt) use ($index) {
388 $bt->addClass(
'mini circular')
389 ->wrap(
'<input value="" class="_status" type="hidden" name="' . $index .
'._status[]">');
391 if ($caption !=
null) {
392 $dt->setFormCaption($caption);
394 $dt->onPreCompile(
function () use (&$dt) {
395 $dt->getHtmlComponent()
396 ->colRightFromRight(0);
398 $dt->wrap(
'<input type="hidden" name="' . $index .
'">');
400 }, $index, $attributes,
"dataTable");
BaseHtml for HTML components.
Base class for Semantic double elements.
Semantic Message component.
Semantic Image component.
Semantic Label component.