|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\base; |
|
4
|
|
|
|
|
5
|
|
|
use Ajax\common\html\HtmlDoubleElement; |
|
6
|
|
|
use Ajax\semantic\html\content\InternalPopup; |
|
7
|
|
|
|
|
8
|
|
|
use Ajax\semantic\html\base\traits\BaseTrait; |
|
9
|
|
|
use Ajax\semantic\html\modules\HtmlDimmer; |
|
10
|
|
|
use Ajax\semantic\html\elements\HtmlLabel; |
|
11
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
|
12
|
|
|
use Ajax\JsUtils; |
|
13
|
|
|
use Ajax\semantic\html\base\constants\Side; |
|
14
|
|
|
use Ajax\common\html\html5\HtmlList; |
|
15
|
|
|
use Ajax\common\html\BaseHtml; |
|
16
|
|
|
use Ajax\semantic\components\Toast; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Base class for Semantic double elements |
|
20
|
|
|
* @author jc |
|
21
|
|
|
* @version 1.0.2 |
|
22
|
|
|
*/ |
|
23
|
|
|
class HtmlSemDoubleElement extends HtmlDoubleElement { |
|
24
|
|
|
use BaseTrait; |
|
25
|
|
|
protected $_popup=NULL; |
|
26
|
|
|
protected $_dimmer=NULL; |
|
27
|
|
|
protected $_toast=NULL; |
|
28
|
|
|
protected $_params=array (); |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public function __construct($identifier, $tagName="p", $baseClass="ui", $content=NULL) { |
|
32
|
|
|
parent::__construct($identifier, $tagName); |
|
33
|
|
|
$this->_baseClass=$baseClass; |
|
34
|
|
|
$this->setClass($baseClass); |
|
35
|
|
|
if (isset($content)) { |
|
36
|
|
|
$this->content=$content; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Defines the popup attributes |
|
42
|
|
|
* @param string $variation |
|
43
|
|
|
* @param string $popupEvent |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setPopupAttributes($variation=NULL, $popupEvent=NULL) { |
|
46
|
|
|
if (isset($this->_popup)) |
|
47
|
|
|
$this->_popup->setAttributes($variation, $popupEvent); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Adds a popup to the element |
|
52
|
|
|
* @param string $title |
|
53
|
|
|
* @param string $content |
|
54
|
|
|
* @param string $variation |
|
55
|
|
|
* @param array $params |
|
56
|
|
|
* @return HtmlSemDoubleElement |
|
57
|
|
|
*/ |
|
58
|
|
|
public function addPopup($title="", $content="", $variation=NULL, $params=array()) { |
|
59
|
|
|
$this->_popup=new InternalPopup($this, $title, $content, $variation, $params); |
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Adds an html popup to the element |
|
65
|
|
|
* @param string $html |
|
66
|
|
|
* @param string $variation |
|
67
|
|
|
* @param array $params |
|
68
|
|
|
* @return HtmlSemDoubleElement |
|
69
|
|
|
*/ |
|
70
|
|
|
public function addPopupHtml($html="", $variation=NULL, $params=array()) { |
|
71
|
|
|
$this->_popup=new InternalPopup($this); |
|
72
|
|
|
$this->_popup->setHtml($html); |
|
73
|
|
|
$this->_popup->setAttributes($variation, $params); |
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Adds a Dimmer to the element |
|
79
|
|
|
* @param array $params |
|
80
|
|
|
* @param mixed $content |
|
81
|
|
|
* @return HtmlDimmer |
|
82
|
|
|
*/ |
|
83
|
|
|
public function addDimmer($params=array(), $content=NULL) { |
|
84
|
|
|
$dimmer=new HtmlDimmer("dimmer-" . $this->identifier, $content); |
|
85
|
|
|
$dimmer->setParams($params); |
|
86
|
|
|
$dimmer->setContainer($this); |
|
87
|
|
|
$this->addContent($dimmer); |
|
88
|
|
|
return $dimmer; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Adds a label to the element |
|
93
|
|
|
* @param mixed $label |
|
94
|
|
|
* @param boolean $before |
|
95
|
|
|
* @param string $icon |
|
96
|
|
|
* @return mixed|HtmlLabel |
|
97
|
|
|
*/ |
|
98
|
|
|
public function addLabel($label, $before=false, $icon=NULL) { |
|
99
|
|
|
$labelO=$label; |
|
100
|
|
|
if (\is_object($label) === false) { |
|
101
|
|
|
$labelO=new HtmlLabel("label-" . $this->identifier, $label); |
|
102
|
|
|
if (isset($icon)) |
|
103
|
|
|
$labelO->addIcon($icon); |
|
104
|
|
|
} else { |
|
105
|
|
|
$labelO->addToPropertyCtrl("class", "label", array ("label" )); |
|
106
|
|
|
} |
|
107
|
|
|
$this->addContent($labelO, $before); |
|
108
|
|
|
return $labelO; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Adds an attached label to the element |
|
113
|
|
|
* @param mixed $label |
|
114
|
|
|
* @param string $side |
|
115
|
|
|
* @param string $direction |
|
116
|
|
|
* @param string $icon |
|
117
|
|
|
* @return HtmlSemDoubleElement |
|
118
|
|
|
*/ |
|
119
|
|
|
public function attachLabel($label,$side=Side::TOP,$direction=Direction::NONE,$icon=NULL){ |
|
120
|
|
|
$label=$this->addLabel($label,true,$icon); |
|
121
|
|
|
$label->setAttached($side,$direction); |
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Transforms the element into a link |
|
127
|
|
|
* @return HtmlSemDoubleElement |
|
128
|
|
|
*/ |
|
129
|
|
|
public function asLink($href=NULL,$target=NULL) { |
|
130
|
|
|
if (isset($href)) |
|
131
|
|
|
$this->setProperty("href", $href); |
|
132
|
|
|
if(isset($target)) |
|
133
|
|
|
$this->setProperty("target", $target); |
|
134
|
|
|
return $this->setTagName("a"); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Returns the script displaying the dimmer |
|
139
|
|
|
* @param boolean $show |
|
140
|
|
|
* @return string |
|
141
|
|
|
*/ |
|
142
|
|
|
public function jsShowDimmer($show=true) { |
|
143
|
|
|
$status="hide"; |
|
144
|
|
|
if ($show === true) |
|
145
|
|
|
$status="show"; |
|
146
|
|
|
return '$("#.' . $this->identifier . ').dimmer("' . $status . '");'; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* {@inheritDoc} |
|
151
|
|
|
* @see BaseHtml::compile() |
|
152
|
|
|
*/ |
|
153
|
|
|
public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
154
|
|
|
if (isset($this->_popup)){ |
|
155
|
|
|
$this->_popup->compile($js); |
|
156
|
|
|
} |
|
157
|
|
|
return parent::compile($js, $view); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* {@inheritDoc} |
|
162
|
|
|
* @see HtmlDoubleElement::run() |
|
163
|
|
|
*/ |
|
164
|
|
|
public function run(JsUtils $js) { |
|
165
|
|
|
$this->_bsComponent=$js->semantic()->generic("#" . $this->identifier); |
|
166
|
|
|
parent::run($js); |
|
167
|
|
|
$this->addEventsOnRun($js); |
|
168
|
|
|
if (isset($this->_popup)) { |
|
169
|
|
|
$this->_popup->run($js); |
|
170
|
|
|
} |
|
171
|
|
|
if (isset($this->_toast)) { |
|
172
|
|
|
$this->_toast->run($js); |
|
173
|
|
|
} |
|
174
|
|
|
return $this->_bsComponent; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param array $items |
|
179
|
|
|
* @param boolean $ordered |
|
180
|
|
|
* @return \Ajax\common\html\html5\HtmlList |
|
181
|
|
|
*/ |
|
182
|
|
|
public function addList($items,$ordered=false){ |
|
183
|
|
|
$list=new HtmlList("list-".$this->identifier,$items); |
|
184
|
|
|
$list->setOrdered($ordered); |
|
185
|
|
|
$list->setClass("ui list"); |
|
186
|
|
|
$this->addContent($list); |
|
187
|
|
|
return $list; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @param ?array $params |
|
192
|
|
|
* @return \Ajax\semantic\components\Toast |
|
193
|
|
|
*/ |
|
194
|
|
|
public function asToast($params=NULL){ |
|
195
|
|
|
$this->_toast=new Toast(null); |
|
|
|
|
|
|
196
|
|
|
if(isset($params)){ |
|
197
|
|
|
$this->_toast->setParams($params); |
|
198
|
|
|
} |
|
199
|
|
|
return $this->_toast; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/* |
|
203
|
|
|
* public function __call($name, $arguments){ |
|
204
|
|
|
* $type=\substr($name, 0,3); |
|
205
|
|
|
* $name=\strtolower(\substr($name, 3)); |
|
206
|
|
|
* $names=\array_merge($this->_variations,$this->_states); |
|
207
|
|
|
* $argument=@$arguments[0]; |
|
208
|
|
|
* if(\array_search($name, $names)!==FALSE){ |
|
209
|
|
|
* switch ($type){ |
|
210
|
|
|
* case "set": |
|
211
|
|
|
* if($argument===false){ |
|
212
|
|
|
* $this->removePropertyValue("class", $name); |
|
213
|
|
|
* }else { |
|
214
|
|
|
* $this->setProperty("class", $this->_baseClass." ".$name); |
|
215
|
|
|
* } |
|
216
|
|
|
* break; |
|
217
|
|
|
* case "add": |
|
218
|
|
|
* $this->addToPropertyCtrl("class", $name,array($name)); |
|
219
|
|
|
* break; |
|
220
|
|
|
* default: |
|
221
|
|
|
* throw new \Exception("Méthode ".$type.$name." inexistante."); |
|
222
|
|
|
* } |
|
223
|
|
|
* }else{ |
|
224
|
|
|
* throw new \Exception("Propriété ".$name." inexistante."); |
|
225
|
|
|
* } |
|
226
|
|
|
* return $this; |
|
227
|
|
|
* } |
|
228
|
|
|
*/ |
|
229
|
|
|
} |
|
230
|
|
|
|