1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
button.php
См. документацию.
1<?php
2
3namespace Bitrix\UI\Buttons;
4
5class Button extends BaseButton
6{
8 protected $properties = [];
9
10 protected function init(array $params = [])
11 {
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['style']))
92 {
93 $this->setStyle($params['style']);
94 }
95
96 if (isset($params['icon']))
97 {
98 $this->setIcon($params['icon']);
99 }
100
101 if (isset($params['collapsedIcon']))
102 {
103 $this->setCollapsedIcon($params['collapsedIcon']);
104 }
105
106 if (isset($params['state']))
107 {
108 $this->setState($params['state']);
109 }
110
111 if (isset($params['size']))
112 {
113 $this->setSize($params['size']);
114 }
115
116 if (isset($params['menu']))
117 {
118 $this->setMenu($params['menu']);
119 }
120
121 if (isset($params['noCaps']))
122 {
123 $this->setNoCaps($params['noCaps']);
124 }
125 elseif ($this->hasAirDesign())
126 {
127 $this->setNoCaps();
128 }
129
130 if (isset($params['round']))
131 {
132 $this->setRound($params['round']);
133 }
134
135 if (isset($params['collapsed']) && $params['collapsed'] === true)
136 {
137 $this->setCollapsed();
138 }
139
140 $isDropdown = $params['dropdown'] ?? null;
141 if ($isDropdown || (isset($params['menu']) && $isDropdown !== false))
142 {
143 $this->setDropdown();
144 }
145 elseif ($isDropdown === false)
146 {
147 $this->getAttributeCollection()->addJsonOption('dropdown', false);
148 }
149 }
150
151 public function setIcon($icon)
152 {
153 if (isset($icon))
154 {
155 $this->addClass('ui-icon-set__scope');
156 }
157 else
158 {
159 $this->removeClass('ui-icon-set__scope');
160 }
161
162 if ($this->hasAirDesign())
163 {
164 $this->addClass('--with-left-icon');
165 }
166 else
167 {
168 $this->removeClass('--with-left-icon');
169 }
170
171 return $this->setProperty('icon', $icon, Icon::class);
172 }
173
174 public function setCollapsedIcon($icon): Button
175 {
176 if (isset($icon))
177 {
178 $this->addClass('ui-icon-set__scope');
179 $this->addClass('--with-collapsed-icon');
180 }
181 else
182 {
183 $this->removeClass('ui-icon-set__scope');
184 $this->removeClass('--with-collapsed-icon');
185 }
186
187 return $this->setProperty('icon', $icon, Icon::class);
188 }
189
190 public function hasCollapsedIcon(): bool
191 {
192 return $this->hasClass('--with-collapsed-icon');
193 }
194
195 public function getIcon()
196 {
197 return $this->getProperty('icon');
198 }
199
206 public function setColor($color)
207 {
208 return $this->setProperty('color', $color, Color::class);
209 }
210
214 public function getColor()
215 {
216 return $this->getProperty('color');
217 }
218
223 public function setStyle($style): self
224 {
225 $this->setProperty('style', $style, AirButtonStyle::class);
226
227 return $this;
228 }
229
233 public function getStyle(): ?string
234 {
235 return $this->getProperty('style');
236 }
237
245 public function setSize($size)
246 {
247 return $this->setProperty('size', $size, Size::class);
248 }
249
253 public function getSize()
254 {
255 return $this->getProperty('size');
256 }
257
264 public function setState($state)
265 {
266 return $this->setProperty('state', $state, State::class);
267 }
268
272 public function getState()
273 {
274 return $this->getProperty('state');
275 }
276
282 public function setActive($flag = true)
283 {
284 if ($flag)
285 {
286 $this->setState(State::ACTIVE);
287 }
288 else
289 {
290 $this->setState(null);
291 }
292
293 return $this;
294 }
295
299 public function isActive()
300 {
301 return $this->getState() === State::ACTIVE;
302 }
303
309 public function setHovered($flag = true)
310 {
311 if ($flag)
312 {
313 $this->setState(State::HOVER);
314 }
315 else
316 {
317 $this->setState(null);
318 }
319
320 return $this;
321 }
322
326 public function isHover()
327 {
328 return $this->getState() === State::HOVER;
329 }
330
336 public function setDisabled($flag = true)
337 {
338 if ($flag)
339 {
341 }
342 else
343 {
344 $this->setState(null);
345 }
346
347 return parent::setDisabled($flag);
348 }
349
353 public function isDisabled()
354 {
355 return $this->getState() === State::DISABLED;
356 }
357
363 public function setWaiting($flag = true)
364 {
365 if ($flag)
366 {
367 $this->setState(State::WAITING);
368 parent::setDisabled(true);
369 }
370 else
371 {
372 $this->setState(null);
373 parent::setDisabled(false);
374 }
375
376 return $this;
377 }
378
382 public function isWaiting()
383 {
384 return $this->getState() === State::WAITING;
385 }
386
392 public function setClocking($flag = true)
393 {
394 if ($flag)
395 {
397 parent::setDisabled(true);
398 }
399 else
400 {
401 $this->setState(null);
402 parent::setDisabled(false);
403 }
404
405 return $this;
406 }
407
411 public function isClocking()
412 {
413 return $this->getState() === State::CLOCKING;
414 }
415
420 public function setNoCaps($flag = true)
421 {
422 if ($flag === false)
423 {
425 }
426 else
427 {
428 $this->addClass(Style::NO_CAPS);
429 }
430
431 return $this;
432 }
433
437 public function isNoCaps()
438 {
439 return $this->hasClass(Style::NO_CAPS);
440 }
441
446 public function setRound($flag = true)
447 {
448 if ($flag === false)
449 {
451 }
452 else
453 {
454 $this->addClass(Style::ROUND);
455 }
456
457 return $this;
458 }
459
463 public function isRound()
464 {
465 return $this->hasClass(Style::ROUND);
466 }
467
472 public function setDropdown($flag = true)
473 {
474 if ($flag === false)
475 {
477 }
478 else
479 {
481 }
482
483 return $this;
484 }
485
489 public function isDropdown()
490 {
491 return $this->hasClass(Style::DROPDOWN);
492 }
493
498 public function setCollapsed($flag = true)
499 {
500 if ($flag === false)
501 {
503 }
504 else
505 {
507 }
508
509 return $this;
510 }
511
515 public function isCollapsed()
516 {
517 return $this->hasClass(Style::COLLAPSED);
518 }
519
525 public function setMenu($options)
526 {
527 $this->getAttributeCollection()->addJsonOption('menu', $options);
528
529 return $this;
530 }
531}
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения options.php:32
hasClass($className)
Определения basebutton.php:396
removeClass($className)
Определения basebutton.php:391
getAttributeCollection()
Определения basebutton.php:472
addClass($className)
Определения basebutton.php:377
isRound()
Определения button.php:463
setStyle($style)
Определения button.php:223
buildFromArray($params)
Определения button.php:82
setActive($flag=true)
Определения button.php:282
getStyle()
Определения button.php:233
setCollapsed($flag=true)
Определения button.php:498
getIcon()
Определения button.php:195
setIcon($icon)
Определения button.php:151
setRound($flag=true)
Определения button.php:446
setClocking($flag=true)
Определения button.php:392
isClocking()
Определения button.php:411
getProperty($name, $defaultValue=null)
Определения button.php:72
getSize()
Определения button.php:253
setHovered($flag=true)
Определения button.php:309
$properties
Определения button.php:8
isHover()
Определения button.php:326
setNoCaps($flag=true)
Определения button.php:420
isDropdown()
Определения button.php:489
setState($state)
Определения button.php:264
setMenu($options)
Определения button.php:525
setSize($size)
Определения button.php:245
isActive()
Определения button.php:299
getColor()
Определения button.php:214
setProperty($propertyName, $value, $enum)
Определения button.php:47
setDisabled($flag=true)
Определения button.php:336
setDropdown($flag=true)
Определения button.php:472
isDisabled()
Определения button.php:353
isEnumValue($value, $enum)
Определения button.php:28
setWaiting($flag=true)
Определения button.php:363
isCollapsed()
Определения button.php:515
setColor($color)
Определения button.php:206
hasCollapsedIcon()
Определения button.php:190
init(array $params=[])
Определения button.php:10
setCollapsedIcon($icon)
Определения button.php:174
isNoCaps()
Определения button.php:437
isWaiting()
Определения button.php:382
getState()
Определения button.php:272
const SUCCESS
Определения color.php:10
const WAITING
Определения state.php:11
const DISABLED
Определения state.php:9
const HOVER
Определения state.php:7
const ACTIVE
Определения state.php:8
const CLOCKING
Определения state.php:10
const NO_CAPS
Определения style.php:7
const ROUND
Определения style.php:8
const DROPDOWN
Определения style.php:9
const COLLAPSED
Определения style.php:10
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799