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