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