|
1
|
|
|
<?php |
|
2
|
|
|
namespace Ajax\semantic\html\collections\form; |
|
3
|
|
|
|
|
4
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
|
5
|
|
|
use Ajax\semantic\html\elements\HtmlButton; |
|
6
|
|
|
use Ajax\semantic\html\modules\HtmlDropdown; |
|
7
|
|
|
|
|
8
|
|
|
class HtmlFormDropdown extends HtmlFormField { |
|
9
|
|
|
|
|
10
|
|
|
public function __construct($identifier, $items = array(), $label = NULL, $value = "", $multiple = false, $associative = true) { |
|
11
|
|
|
parent::__construct("field-" . $identifier, (new HtmlDropdown("dropdown-" . $identifier, $value, $items, $associative))->asSelect($identifier, $multiple), $label); |
|
12
|
|
|
$this->_identifier = $identifier; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function setItems($items) { |
|
16
|
|
|
return $this->getField()->setItems($items); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function addItem($item, $value = NULL, $image = NULL) { |
|
20
|
|
|
return $this->getField()->addItem($item, $value, $image); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public static function multipleDropdown($identifier, $items = array(), $label = NULL, $value = "", $associative = true) { |
|
24
|
|
|
return new HtmlFormDropdown($identifier, $items, $label, $value, true, $associative); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* |
|
29
|
|
|
* @return HtmlDropdown |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getDataField() { |
|
32
|
|
|
return $this->getField()->getInput(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function asSelect($name = NULL, $multiple = false, $selection = true) { |
|
36
|
|
|
$this->getField()->asSelect($name, $multiple, $selection); |
|
37
|
|
|
return $this; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function setClearable($value) { |
|
41
|
|
|
return $this->getField()->setClearable($value); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* |
|
46
|
|
|
* @param boolean $floating |
|
47
|
|
|
* @return HtmlDropdown |
|
48
|
|
|
*/ |
|
49
|
|
|
public function asButton($floating = false) { |
|
50
|
|
|
$field = $this->content["field"]; |
|
51
|
|
|
$label = $this->content["label"]; |
|
52
|
|
|
$field->addContent($label); |
|
53
|
|
|
$this->content = [ |
|
54
|
|
|
"field" => $field |
|
55
|
|
|
]; |
|
56
|
|
|
$this->content["field"]->asButton($floating); |
|
57
|
|
|
return $this->content["field"]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $action |
|
63
|
|
|
* @param string $direction |
|
64
|
|
|
* @param string $icon |
|
65
|
|
|
* @param boolean $labeled |
|
66
|
|
|
* @return mixed|HtmlButton |
|
67
|
|
|
*/ |
|
68
|
|
|
public function addAction($action, $direction = Direction::RIGHT, $icon = NULL, $labeled = false) { |
|
69
|
|
|
$this->getField()->setStyle('display:inline-block; width: auto'); |
|
70
|
|
|
$actionO = $action; |
|
71
|
|
|
if (\is_object($action) === false) { |
|
|
|
|
|
|
72
|
|
|
$actionO = new HtmlButton("action-" . $this->identifier, $action); |
|
|
|
|
|
|
73
|
|
|
if (isset($icon)) |
|
74
|
|
|
$actionO->addIcon($icon, true, $labeled); |
|
75
|
|
|
} |
|
76
|
|
|
$this->addContent($actionO, \strstr($direction, Direction::LEFT) !== false); |
|
77
|
|
|
return $actionO; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|