1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
button.php
См. документацию.
1<?php
2
3namespace Bitrix\UI\Buttons\Split;
4
5use Bitrix\Main\InvalidOperationException;
6use Bitrix\Main\UI\Extension;
7use Bitrix\UI\Buttons;
8use Bitrix\UI\Buttons\ButtonAttributes;
9
11{
13 protected $mainButton;
15 protected $menuButton;
16 protected $menuTarget = Type::MAIN;
17 protected $baseClass = 'ui-btn-split';
18
22 public static function getJsClass()
23 {
24 return 'BX.UI.SplitButton';
25 }
26
30 protected function buildFromArray($params)
31 {
32 $mainOptions = $menuOptions = [];
33
34 if (!empty($params['mainButton']))
35 {
36 $mainOptions = $params['mainButton'];
37 }
38 if (!empty($params['menuButton']))
39 {
40 $menuOptions = $params['menuButton'];
41 }
42 unset($params['tag']);
43
44 $mainOptions['buttonType'] = Type::MAIN;
45 $menuOptions['buttonType'] = Type::MENU;
46
47 $this->mainButton = new SubButton($mainOptions);
48 $this->menuButton = new SubButton($menuOptions);
49 $this->mainButton->setSplitButton($this);
50 $this->menuButton->setSplitButton($this);
51
52 if (isset($params['menuTarget']) && $params['menuTarget'] === Type::MENU)
53 {
54 $this->menuTarget = Type::MENU;
55 }
56
57 parent::buildFromArray($params);
58 }
59
66 public function render($jsInit = true)
67 {
68 Extension::load($this->listExtensions());
69
70 $attributes = clone $this->getAttributeCollection();
71 $this->appendDefaultJsonOption($attributes);
72
73 $output = "<div {$attributes}>{$this->renderInner()}</div>";
74
75 if ($jsInit)
76 {
77 $js = $this->renderJavascript();
78 if ($js)
79 {
80 $output .= "<script>BX.ready(function(){ {$js} });</script>";
81 }
82 }
83
84 return $output;
85 }
86
87 protected function renderInner()
88 {
89 $mainButtonOutput = $this->getMainButton()->render();
90 $menuButtonOutput = $this->getMenuButton()->render();
91
92 return "{$mainButtonOutput}{$menuButtonOutput}";
93 }
94
95 protected function getQuerySelector()
96 {
97 $tag = 'div';
98 $uniqId = $this->getUniqId();
99 $uniqIdName = "data-" . self::UNIQ_ID_DATA_ATTR;
100
101 return "{$tag}[{$uniqIdName}=\"{$uniqId}\"]";
102 }
103
104 protected function appendDefaultJsonOption(ButtonAttributes $attributes)
105 {
106 $attributes = parent::appendDefaultJsonOption($attributes);
107
108 $mainButton = $this->getMainButton();
109 $menuButton = $this->getMenuButton();
110
111 $mainButtonAttributes = clone $mainButton->getAttributeCollection();
112 $mainButton->appendDefaultJsonOption($mainButtonAttributes);
113
114 $menuButtonAttributes = clone $menuButton->getAttributeCollection();
115 $menuButton->appendDefaultJsonOption($menuButtonAttributes);
116
117 if ($mainButtonAttributes->getJsonOptions())
118 {
119 $attributes->addJsonOption('mainButton', $mainButtonAttributes->getJsonOptions());
120 }
121
122 if ($menuButtonAttributes->getJsonOptions())
123 {
124 $attributes->addJsonOption('menuButton', $menuButtonAttributes->getJsonOptions());
125 }
126 }
127
131 public function getMainButton()
132 {
133 return $this->mainButton;
134 }
135
139 public function getMenuButton()
140 {
141 return $this->menuButton;
142 }
143
147 public function getMenuTarget()
148 {
149 return $this->menuTarget;
150 }
151
155 public function getText()
156 {
157 return $this->getMainButton()->getText();
158 }
159
165 public function setText($text)
166 {
167 $this->getMainButton()->setText($text);
168
169 return $this;
170 }
171
175 public function getCounter()
176 {
177 return $this->getMainButton()->getCounter();
178 }
179
185 public function setCounter($counter)
186 {
187 $this->getMainButton()->setCounter($counter);
188
189 return $this;
190 }
191
197 public function setState($state)
198 {
199 return $this->setProperty('state', $state, State::class);
200 }
201
206 public function setDropdown($flag = true)
207 {
208 return $this;
209 }
210
216 public function setDisabled($flag = true)
217 {
218 if ($flag)
219 {
221 }
222
223 $this->getMainButton()->setDisabled($flag);
224 $this->getMenuButton()->setDisabled($flag);
225
226 return $this;
227 }
228}
appendDefaultJsonOption(ButtonAttributes $attributes)
Определения basebutton.php:166
getAttributeCollection()
Определения basebutton.php:472
setState($state)
Определения button.php:264
setProperty($propertyName, $value, $enum)
Определения button.php:47
buildFromArray($params)
Определения button.php:30
appendDefaultJsonOption(ButtonAttributes $attributes)
Определения button.php:104
setCounter($counter)
Определения button.php:185
static getJsClass()
Определения button.php:22
render($jsInit=true)
Определения button.php:66
setState($state)
Определения button.php:197
setDisabled($flag=true)
Определения button.php:216
setDropdown($flag=true)
Определения button.php:206
getQuerySelector()
Определения button.php:95
setText($text)
Определения button.php:165
const DISABLED
Определения state.php:9
$output
Определения options.php:436
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799