Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
button.php
1
<?php
2
3
namespace
Bitrix\UI\Buttons
;
4
5
class
Button
extends
BaseButton
6
{
8
protected
$properties
= [];
9
10
protected
function
init
(array $params = [])
11
{
12
$this->
setColor
(
Color::SUCCESS
);
13
14
if
(isset($params[
'baseClassName'
]))
15
{
16
$this->baseClass = $params[
'baseClassName'
];
17
}
18
19
parent::init($params);
20
}
21
28
protected
function
isEnumValue
($value, $enum)
29
{
30
try
31
{
32
return
in_array($value, (
new
\ReflectionClass($enum))->getConstants(),
true
);
33
}
34
catch
(\ReflectionException $e)
35
{}
36
37
return
false
;
38
}
39
47
protected
function
setProperty
($propertyName, $value, $enum)
48
{
49
if
($this->
isEnumValue
($value, $enum))
50
{
51
$this
52
->removeClass($this->
getProperty
($propertyName))
53
->addClass($value)
54
;
55
$this->properties[$propertyName] = $value;
56
}
57
elseif ($value ===
null
)
58
{
59
$this->
removeClass
($this->
getProperty
($propertyName));
60
$this->properties[$propertyName] = $value;
61
}
62
63
return
$this;
64
}
65
72
protected
function
getProperty
($name, $defaultValue =
null
)
73
{
74
if
(isset($this->properties[$name]))
75
{
76
return
$this->properties[$name];
77
}
78
79
return
$defaultValue;
80
}
81
82
protected
function
buildFromArray
($params)
83
{
84
parent::buildFromArray($params);
85
86
if
(isset($params[
'color'
]))
87
{
88
$this->
setColor
($params[
'color'
]);
89
}
90
91
if
(isset($params[
'icon'
]))
92
{
93
$this->
setIcon
($params[
'icon'
]);
94
}
95
96
if
(isset($params[
'state'
]))
97
{
98
$this->
setState
($params[
'state'
]);
99
}
100
101
if
(isset($params[
'size'
]))
102
{
103
$this->
setSize
($params[
'size'
]);
104
}
105
106
if
(isset($params[
'menu'
]))
107
{
108
$this->
setMenu
($params[
'menu'
]);
109
}
110
111
if
(isset($params[
'noCaps'
]))
112
{
113
$this->
setNoCaps
($params[
'noCaps'
]);
114
}
115
116
if
(isset($params[
'round'
]))
117
{
118
$this->
setRound
($params[
'round'
]);
119
}
120
121
$isDropdown = $params[
'dropdown'
] ??
null
;
122
if
($isDropdown || (isset($params[
'menu'
]) && $isDropdown !==
false
))
123
{
124
$this->
setDropdown
();
125
}
126
elseif ($isDropdown ===
false
)
127
{
128
$this->
getAttributeCollection
()->addJsonOption(
'dropdown'
,
false
);
129
}
130
}
131
132
public
function
setIcon
($icon)
133
{
134
return
$this->
setProperty
(
'icon'
, $icon, Icon::class);
135
}
136
137
public
function
getIcon
()
138
{
139
return
$this->
getProperty
(
'icon'
);
140
}
141
148
public
function
setColor
($color)
149
{
150
return
$this->
setProperty
(
'color'
, $color, Color::class);
151
}
152
156
public
function
getColor
()
157
{
158
return
$this->
getProperty
(
'color'
);
159
}
160
168
public
function
setSize
($size)
169
{
170
return
$this->
setProperty
(
'size'
, $size, Size::class);
171
}
172
176
public
function
getSize
()
177
{
178
return
$this->
getProperty
(
'size'
);
179
}
180
187
public
function
setState
($state)
188
{
189
return
$this->
setProperty
(
'state'
, $state, State::class);
190
}
191
195
public
function
getState
()
196
{
197
return
$this->
getProperty
(
'state'
);
198
}
199
205
public
function
setActive
($flag =
true
)
206
{
207
if
($flag)
208
{
209
$this->
setState
(
State::ACTIVE
);
210
}
211
else
212
{
213
$this->
setState
(
null
);
214
}
215
216
return
$this;
217
}
218
222
public
function
isActive
()
223
{
224
return
$this->
getState
() ===
State::ACTIVE
;
225
}
226
232
public
function
setHovered
($flag =
true
)
233
{
234
if
($flag)
235
{
236
$this->
setState
(
State::HOVER
);
237
}
238
else
239
{
240
$this->
setState
(
null
);
241
}
242
243
return
$this;
244
}
245
249
public
function
isHover
()
250
{
251
return
$this->
getState
() ===
State::HOVER
;
252
}
253
259
public
function
setDisabled
($flag =
true
)
260
{
261
if
($flag)
262
{
263
$this->
setState
(
State::DISABLED
);
264
}
265
else
266
{
267
$this->
setState
(
null
);
268
}
269
270
return
parent::setDisabled($flag);
271
}
272
276
public
function
isDisabled
()
277
{
278
return
$this->
getState
() ===
State::DISABLED
;
279
}
280
286
public
function
setWaiting
($flag =
true
)
287
{
288
if
($flag)
289
{
290
$this->
setState
(
State::WAITING
);
291
parent::setDisabled(
true
);
292
}
293
else
294
{
295
$this->
setState
(
null
);
296
parent::setDisabled(
false
);
297
}
298
299
return
$this;
300
}
301
305
public
function
isWaiting
()
306
{
307
return
$this->
getState
() ===
State::WAITING
;
308
}
309
315
public
function
setClocking
($flag =
true
)
316
{
317
if
($flag)
318
{
319
$this->
setState
(
State::CLOCKING
);
320
parent::setDisabled(
true
);
321
}
322
else
323
{
324
$this->
setState
(
null
);
325
parent::setDisabled(
false
);
326
}
327
328
return
$this;
329
}
330
334
public
function
isClocking
()
335
{
336
return
$this->
getState
() ===
State::CLOCKING
;
337
}
338
343
public
function
setNoCaps
($flag =
true
)
344
{
345
if
($flag ===
false
)
346
{
347
$this->
removeClass
(
Style::NO_CAPS
);
348
}
349
else
350
{
351
$this->
addClass
(
Style::NO_CAPS
);
352
}
353
354
return
$this;
355
}
356
360
public
function
isNoCaps
()
361
{
362
return
$this->
hasClass
(
Style::NO_CAPS
);
363
}
364
369
public
function
setRound
($flag =
true
)
370
{
371
if
($flag ===
false
)
372
{
373
$this->
removeClass
(
Style::ROUND
);
374
}
375
else
376
{
377
$this->
addClass
(
Style::ROUND
);
378
}
379
380
return
$this;
381
}
382
386
public
function
isRound
()
387
{
388
return
$this->
hasClass
(
Style::ROUND
);
389
}
390
395
public
function
setDropdown
($flag =
true
)
396
{
397
if
($flag ===
false
)
398
{
399
$this->
removeClass
(
Style::DROPDOWN
);
400
}
401
else
402
{
403
$this->
addClass
(
Style::DROPDOWN
);
404
}
405
406
return
$this;
407
}
408
412
public
function
isDropdown
()
413
{
414
return
$this->
hasClass
(
Style::DROPDOWN
);
415
}
416
421
public
function
setCollapsed
($flag =
true
)
422
{
423
if
($flag ===
false
)
424
{
425
$this->
removeClass
(
Style::COLLAPSED
);
426
}
427
else
428
{
429
$this->
addClass
(
Style::COLLAPSED
);
430
}
431
432
return
$this;
433
}
434
438
public
function
isCollapsed
()
439
{
440
return
$this->
hasClass
(
Style::COLLAPSED
);
441
}
442
448
public
function
setMenu
($options)
449
{
450
$this->
getAttributeCollection
()->addJsonOption(
'menu'
, $options);
451
452
return
$this;
453
}
454
}
Bitrix\UI\Buttons\BaseButton
Definition
basebutton.php:17
Bitrix\UI\Buttons\BaseButton\hasClass
hasClass($className)
Definition
basebutton.php:346
Bitrix\UI\Buttons\BaseButton\removeClass
removeClass($className)
Definition
basebutton.php:341
Bitrix\UI\Buttons\BaseButton\getAttributeCollection
getAttributeCollection()
Definition
basebutton.php:422
Bitrix\UI\Buttons\BaseButton\addClass
addClass($className)
Definition
basebutton.php:327
Bitrix\UI\Buttons\Button
Definition
button.php:6
Bitrix\UI\Buttons\Button\isRound
isRound()
Definition
button.php:386
Bitrix\UI\Buttons\Button\buildFromArray
buildFromArray($params)
Definition
button.php:82
Bitrix\UI\Buttons\Button\setActive
setActive($flag=true)
Definition
button.php:205
Bitrix\UI\Buttons\Button\setCollapsed
setCollapsed($flag=true)
Definition
button.php:421
Bitrix\UI\Buttons\Button\getIcon
getIcon()
Definition
button.php:137
Bitrix\UI\Buttons\Button\setIcon
setIcon($icon)
Definition
button.php:132
Bitrix\UI\Buttons\Button\setRound
setRound($flag=true)
Definition
button.php:369
Bitrix\UI\Buttons\Button\setClocking
setClocking($flag=true)
Definition
button.php:315
Bitrix\UI\Buttons\Button\isClocking
isClocking()
Definition
button.php:334
Bitrix\UI\Buttons\Button\getProperty
getProperty($name, $defaultValue=null)
Definition
button.php:72
Bitrix\UI\Buttons\Button\getSize
getSize()
Definition
button.php:176
Bitrix\UI\Buttons\Button\setHovered
setHovered($flag=true)
Definition
button.php:232
Bitrix\UI\Buttons\Button\$properties
$properties
Definition
button.php:8
Bitrix\UI\Buttons\Button\isHover
isHover()
Definition
button.php:249
Bitrix\UI\Buttons\Button\setNoCaps
setNoCaps($flag=true)
Definition
button.php:343
Bitrix\UI\Buttons\Button\isDropdown
isDropdown()
Definition
button.php:412
Bitrix\UI\Buttons\Button\setState
setState($state)
Definition
button.php:187
Bitrix\UI\Buttons\Button\setMenu
setMenu($options)
Definition
button.php:448
Bitrix\UI\Buttons\Button\setSize
setSize($size)
Definition
button.php:168
Bitrix\UI\Buttons\Button\isActive
isActive()
Definition
button.php:222
Bitrix\UI\Buttons\Button\getColor
getColor()
Definition
button.php:156
Bitrix\UI\Buttons\Button\setProperty
setProperty($propertyName, $value, $enum)
Definition
button.php:47
Bitrix\UI\Buttons\Button\setDisabled
setDisabled($flag=true)
Definition
button.php:259
Bitrix\UI\Buttons\Button\setDropdown
setDropdown($flag=true)
Definition
button.php:395
Bitrix\UI\Buttons\Button\isDisabled
isDisabled()
Definition
button.php:276
Bitrix\UI\Buttons\Button\isEnumValue
isEnumValue($value, $enum)
Definition
button.php:28
Bitrix\UI\Buttons\Button\setWaiting
setWaiting($flag=true)
Definition
button.php:286
Bitrix\UI\Buttons\Button\isCollapsed
isCollapsed()
Definition
button.php:438
Bitrix\UI\Buttons\Button\setColor
setColor($color)
Definition
button.php:148
Bitrix\UI\Buttons\Button\init
init(array $params=[])
Definition
button.php:10
Bitrix\UI\Buttons\Button\isNoCaps
isNoCaps()
Definition
button.php:360
Bitrix\UI\Buttons\Button\isWaiting
isWaiting()
Definition
button.php:305
Bitrix\UI\Buttons\Button\getState
getState()
Definition
button.php:195
Bitrix\UI\Buttons\Color\SUCCESS
const SUCCESS
Definition
color.php:10
Bitrix\UI\Buttons\State\WAITING
const WAITING
Definition
state.php:11
Bitrix\UI\Buttons\State\DISABLED
const DISABLED
Definition
state.php:9
Bitrix\UI\Buttons\State\HOVER
const HOVER
Definition
state.php:7
Bitrix\UI\Buttons\State\ACTIVE
const ACTIVE
Definition
state.php:8
Bitrix\UI\Buttons\State\CLOCKING
const CLOCKING
Definition
state.php:10
Bitrix\UI\Buttons\Style\NO_CAPS
const NO_CAPS
Definition
style.php:7
Bitrix\UI\Buttons\Style\ROUND
const ROUND
Definition
style.php:8
Bitrix\UI\Buttons\Style\DROPDOWN
const DROPDOWN
Definition
style.php:9
Bitrix\UI\Buttons\Style\COLLAPSED
const COLLAPSED
Definition
style.php:10
Bitrix\UI\Buttons
Definition
addbutton.php:3
modules
ui
lib
buttons
button.php
Создано системой
1.10.0