1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\modules; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\content\HtmlDropdownItem; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
use Ajax\semantic\html\elements\HtmlIcon; |
9
|
|
|
use Ajax\common\html\html5\HtmlInput; |
10
|
|
|
use Ajax\service\JArray; |
11
|
|
|
use Ajax\service\JString; |
12
|
|
|
|
13
|
|
|
class HtmlDropdown extends HtmlSemDoubleElement { |
14
|
|
|
protected $mClass="menu"; |
15
|
|
|
protected $mTagName="div"; |
16
|
|
|
protected $items=array (); |
17
|
|
|
protected $params=array("action"=>"select"); |
18
|
|
|
protected $input; |
19
|
|
|
|
20
|
|
|
public function __construct($identifier, $value="", $items=array()) { |
21
|
|
|
parent::__construct($identifier, "div"); |
22
|
|
|
$this->_template=include dirname(__FILE__).'/../templates/tplDropdown.php'; |
23
|
|
|
$this->setProperty("class", "ui dropdown"); |
24
|
|
|
$content=new HtmlSemDoubleElement("","div"); |
25
|
|
|
$content->setClass("text"); |
26
|
|
|
$content->setContent($value); |
27
|
|
|
$content->wrap("",new HtmlIcon("", "dropdown")); |
28
|
|
|
$this->content=array($content); |
29
|
|
|
$this->tagName="div"; |
30
|
|
|
$this->addItems($items); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function addItem($item,$value=NULL,$image=NULL){ |
34
|
|
|
$itemO=$item; |
35
|
|
|
if(\is_object($item)===false){ |
36
|
|
|
$itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items),$item,$value,$image); |
37
|
|
|
}elseif($itemO instanceof HtmlDropdownItem){ |
38
|
|
|
$this->addToProperty("class", "vertical"); |
39
|
|
|
} |
40
|
|
|
$this->items[]=$itemO; |
41
|
|
|
return $itemO; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function addInput($name){ |
45
|
|
|
if(!isset($name)) |
46
|
|
|
$name="input-".$this->identifier; |
47
|
|
|
$this->setAction("activate"); |
48
|
|
|
$this->input=new HtmlInput($name,"hidden"); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function addItems($items){ |
52
|
|
|
if(JArray::isAssociative($items)){ |
53
|
|
|
foreach ($items as $k=>$v){ |
54
|
|
|
$this->addItem($v)->setData($k); |
55
|
|
|
} |
56
|
|
|
}else{ |
57
|
|
|
foreach ($items as $item){ |
58
|
|
|
$this->addItem($item); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param boolean $dropdown |
65
|
|
|
*/ |
66
|
|
|
public function asDropdown($dropdown){ |
67
|
|
|
if($dropdown===false){ |
68
|
|
|
$this->_template=include dirname(__FILE__).'/../templates/tplDropdownMenu.php'; |
69
|
|
|
$dropdown="menu"; |
70
|
|
|
}else{ |
71
|
|
|
$dropdown="dropdown"; |
72
|
|
|
$this->mClass="menu"; |
73
|
|
|
} |
74
|
|
|
return $this->addToPropertyCtrl("class", $dropdown,array("menu","dropdown")); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setVertical(){ |
78
|
|
|
return $this->addToPropertyCtrl("class", "vertical",array("vertical")); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setSimple(){ |
82
|
|
|
return $this->addToPropertyCtrl("class", "simple",array("simple")); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function asButton($floating=false){ |
86
|
|
|
if($floating) |
87
|
|
|
$this->addToProperty("class", "floating"); |
88
|
|
|
return $this->addToProperty("class", "button"); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function asSelect($name=NULL,$multiple=false,$selection=true){ |
92
|
|
|
if(isset($name)) |
93
|
|
|
$this->addInput($name); |
94
|
|
|
if($multiple) |
95
|
|
|
$this->addToProperty("class", "multiple"); |
96
|
|
|
if ($selection) |
97
|
|
|
$this->addToPropertyCtrl("class", "selection",array("selection")); |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function asSearch($name=NULL,$multiple=false,$selection=false){ |
102
|
|
|
$this->asSelect($name,$multiple,$selection); |
103
|
|
|
return $this->addToProperty("class", "search"); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setSelect($name=NULL,$multiple=false){ |
107
|
|
|
if(!isset($name)) |
108
|
|
|
$name="select-".$this->identifier; |
109
|
|
|
$this->input=null; |
110
|
|
|
if($multiple){ |
111
|
|
|
$this->setProperty("multiple", true); |
112
|
|
|
$this->addToProperty("class", "multiple"); |
113
|
|
|
} |
114
|
|
|
$this->setAction("activate"); |
115
|
|
|
$this->tagName="select"; |
116
|
|
|
$this->setProperty("name", $name); |
117
|
|
|
$this->content=null; |
118
|
|
|
foreach ($this->items as $item){ |
119
|
|
|
$item->asOption(); |
120
|
|
|
} |
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function asSubmenu($pointing=false,$sens=""){ |
125
|
|
|
$this->setClass("ui dropdown link item"); |
126
|
|
|
if($pointing===true){ |
127
|
|
|
$this->setPointing($sens); |
128
|
|
|
} |
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function setPointing($sens=""){ |
133
|
|
|
$this->addToProperty("class", "pointing"); |
134
|
|
|
if(JString::isNotNull($sens)) |
135
|
|
|
$this->addToPropertyCtrl("class", $sens, array("left","right")); |
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function setValue($value){ |
140
|
|
|
if(isset($this->input)){ |
141
|
|
|
$this->input->setProperty("value", $value); |
142
|
|
|
}else{ |
143
|
|
|
$this->setProperty("value", $value); |
144
|
|
|
} |
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/* |
149
|
|
|
* (non-PHPdoc) |
150
|
|
|
* @see BaseHtml::run() |
151
|
|
|
*/ |
152
|
|
|
public function run(JsUtils $js) { |
153
|
|
|
if($this->propertyContains("class", "simple")===false){ |
154
|
|
|
$this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier,$this->params); |
155
|
|
|
$this->addEventsOnRun($js); |
156
|
|
|
return $this->_bsComponent; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function setAction($action){ |
161
|
|
|
$this->params["action"]=$action; |
162
|
|
|
} |
163
|
|
|
} |