1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
toolbar.php
См. документацию.
1<?php
2
3namespace Bitrix\UI\Toolbar;
4
5use Bitrix\Main\ArgumentTypeException;
6use Bitrix\Main\UI\Filter\Theme;
7use Bitrix\UI\Buttons\AirButtonStyle;
8use Bitrix\UI\Buttons\BaseButton;
9use Bitrix\UI\Buttons\Button;
10use Bitrix\UI\Buttons\Color;
11use Bitrix\UI\Buttons\Size;
12use Bitrix\UI\Buttons\Icon;
13
15{
16 private $id;
17 private $filter;
18 private ?string $title = null;
19 private bool $isMultiLineTitleEnabled = false;
20 private ?string $beforeTitleBoxHtml = null;
21 private $beforeTitleHtml;
22 private $afterTitleHtml;
23 private $underTitleHtml;
24 private string $rightCustomHtml;
25 private array $rightCustomHtmlOptions = [];
26 private $titleMinWidth;
27 private $titleMaxWidth;
28 private bool $isTitleNoShrink = false;
29 private $titleVisibility = true;
30 private $favoriteStar = true;
31 private bool $editableTitle = false;
32 private string $defaultEditableTitle;
33// private string $editableTitleSelector;
34 private ?array $copyLinkButtonParams = null;
35 private $enabled = true;
36
40 private $afterTitleButtons = [];
44 private $buttons = [];
45 private $filterButtons = [];
46 private $options;
47
54 public function __construct($id, $options)
55 {
56 $this->id = $id;
57 $this->options = $options;
58
59 if (isset($this->options['filter']))
60 {
61 $this->addFilter($this->options['filter']);
62 }
63 }
64
65 public function isEnabled(): bool
66 {
67 return $this->enabled;
68 }
69
70 public function enable(): void
71 {
72 $this->enabled = true;
73 }
74
75 public function disable(): void
76 {
77 $this->enabled = false;
78 }
79
80 public function setTitle(string $title): void
81 {
82 $this->title = $title;
83 }
84
85 public function getTitle($propertyName = false, $stripTags = false): string
86 {
87 if ($this->title !== null)
88 {
89 return $stripTags ? strip_tags($this->title) : $this->title;
90 }
91
92 $title = $GLOBALS['APPLICATION']->getTitle($propertyName, $stripTags);
93
94 return is_string($title) ? $title : '';
95 }
96
97 public function hideTitle(): void
98 {
99 $this->titleVisibility = false;
100 }
101
102 public function hasTitle(): bool
103 {
104 return $this->titleVisibility;
105 }
106
107 public function addEditableTitle(string $defaultTitle = null): void
108 {
109 $this->defaultEditableTitle = $defaultTitle ?? '';
110 $this->editableTitle = true;
111 }
112
113 public function getDefaultEditableTitle(): ?string
114 {
115 return $this->hasEditableTitle()
116 ? $this->defaultEditableTitle
117 : null
118 ;
119 }
120
121// public function getEditableTitleSelector(): ?string
122// {
123// return $this->hasEditableTitle()
124// ? $this->editableTitleSelector
125// : null
126// ;
127// }
128
129 public function hasEditableTitle(): bool
130 {
131 return $this->editableTitle;
132 }
133
137 public function getId()
138 {
139 return $this->id;
140 }
141
149 public function addButton($button, $location = ButtonLocation::RIGHT)
150 {
151 if (is_array($button))
152 {
153 $button = new Button($button);
154 }
155
156 if ($this->hasAirDesign())
157 {
158 $button->setAirDesign(true);
159 $button->setNoCaps(true);
160 if ($button->getIcon() && $button->hasCollapsedIcon() === false)
161 {
162 // Set classname modifiers for air buttons
163 $button->setIcon($button->getIcon());
164 }
165
166 if ($button->getStyle() === null && $button->getColor() !== null)
167 {
168 $button->setStyle($this->convertColorToAirButtonStyle($button->getColor()));
169 }
170 if ($location === ButtonLocation::RIGHT && $button->getSize() === null)
171 {
172 $button->setSize(Size::SMALL);
173 }
174
175 if (
177 && $button->getStyle() === AirButtonStyle::FILLED_SUCCESS
178 && $button->getIcon() === null
179 )
180 {
181 $button->setIcon(Icon::ADD_M);
182 }
183 }
184
185 if (!($button instanceof Button))
186 {
187 throw new ArgumentTypeException("button", Button::class);
188 }
189
191 {
192 $this->filterButtons[] = $button;
193 }
195 {
196 $this->afterTitleButtons[] = $button;
197 }
198 else
199 {
200 $this->buttons[] = $button;
201 }
202 }
203
204 public function deleteButtons(\Closure $closure)
205 {
206 foreach ($this->buttons as $i => $button)
207 {
208 if ($closure($button, ButtonLocation::RIGHT) === true)
209 {
210 unset($this->buttons[$i]);
211 }
212 }
213
214 foreach ($this->filterButtons as $i => $button)
215 {
216 if ($closure($button, ButtonLocation::AFTER_FILTER) === true)
217 {
218 unset($this->filterButtons[$i]);
219 }
220 }
221
222 foreach ($this->afterTitleButtons as $i => $button)
223 {
224 if ($closure($button, ButtonLocation::AFTER_TITLE) === true)
225 {
226 unset($this->afterTitleButtons[$i]);
227 }
228 }
229 }
230
231 public function shuffleButtons(\Closure $closure, $buttonLocation)
232 {
233 $buttonList = null;
234 switch ($buttonLocation)
235 {
237 $buttonList = $this->buttons;
238 break;
240 $buttonList = $this->filterButtons;
241 break;
242 }
243
244 if ($buttonList)
245 {
246 $buttonList = $closure($buttonList);
247 if (!is_array($buttonList))
248 {
249 throw new ArgumentTypeException('buttonList', 'array');
250 }
251
252 switch ($buttonLocation)
253 {
255 $this->buttons = $buttonList;
256 break;
258 $this->filterButtons = $buttonList;
259 break;
260 }
261 }
262 }
263
264 public function hasFavoriteStar()
265 {
266 return (bool)$this->favoriteStar;
267 }
268
269 public function addFavoriteStar()
270 {
271 $this->favoriteStar = true;
272
273 return $this;
274 }
275
276 public function deleteFavoriteStar()
277 {
278 $this->favoriteStar = false;
279
280 return $this;
281 }
282
283 public function addFilter(array $filterOptions = [])
284 {
285 ob_start();
286
287 if ($this->hasAirDesign())
288 {
289 $updatedFilterOptions = [
290 ...$filterOptions,
291 'THEME' => Theme::AIR,
292 ];
293
294 if (isset($updatedFilterOptions['CONFIG']) === false)
295 {
296 $updatedFilterOptions['CONFIG'] = [];
297 }
298
299 $updatedFilterOptions['CONFIG']['AUTOFOCUS'] = false;
300
301 $GLOBALS['APPLICATION']->includeComponent('bitrix:main.ui.filter', '', $updatedFilterOptions);
302 }
303 else
304 {
305 $GLOBALS['APPLICATION']->includeComponent('bitrix:main.ui.filter', '', $filterOptions);
306 }
307
308 $this->filter = ob_get_clean();
309 }
310
311 public function setFilter(string $filter)
312 {
313 $this->filter = $filter;
314 }
315
316 public function getFilter()
317 {
318 return $this->filter;
319 }
320
321 public function addBeforeTitleBoxHtml(string $html): void
322 {
323 $this->beforeTitleBoxHtml = $html;
324 }
325
326 public function getBeforeTitleBoxHtml(): ?string
327 {
328 return $this->beforeTitleBoxHtml;
329 }
330
331 public function addBeforeTitleHtml(string $html)
332 {
333 $this->beforeTitleHtml = $html;
334 }
335
336 public function getBeforeTitleHtml(): ?string
337 {
338 return $this->beforeTitleHtml;
339 }
340
341 public function addAfterTitleHtml(string $html)
342 {
343 $this->afterTitleHtml = $html;
344 }
345
346 public function getAfterTitleHtml(): ?string
347 {
348 return $this->afterTitleHtml;
349 }
350
351 public function addUnderTitleHtml(string $html)
352 {
353 $this->underTitleHtml = $html;
354 }
355
356 public function getUnderTitleHtml(): ?string
357 {
358 return $this->underTitleHtml;
359 }
360
361 public function addRightCustomHtml(string $html, array $options = []): void
362 {
363 $this->rightCustomHtml = $html;
364 $this->rightCustomHtmlOptions = $options;
365 }
366
367 public function getRightCustomHtml(): string
368 {
369 return $this->rightCustomHtml ?? '';
370 }
371
373 {
374 return $this->rightCustomHtmlOptions ?? [];
375 }
376
382 public function setCopyLinkButton(?array $params = []): void
383 {
384 if (is_array($params))
385 {
386 $this->copyLinkButtonParams = $params;
387 $this->copyLinkButtonParams['active'] = true;
388 }
389 else
390 {
391 $this->copyLinkButtonParams = null;
392 }
393 }
394
398 public function getCopyLinkButton(): ?array
399 {
400 return $this->copyLinkButtonParams;
401 }
402
406 public function getButtons()
407 {
408 return array_merge($this->afterTitleButtons, $this->filterButtons, $this->buttons);
409 }
410
411 public function renderAfterTitleButtons()
412 {
413 return implode(array_map(function(Button $button) {
414 return self::processButtonRender($button);
415 }, $this->afterTitleButtons));
416 }
417
418 public function renderRightButtons()
419 {
420 return implode(array_map(function(Button $button) {
421 return self::processButtonRender($button);
422 }, $this->buttons));
423 }
424
425 public function renderAfterFilterButtons()
426 {
427 return implode(array_map(function(Button $button) {
428 return self::processButtonRender($button);
429 }, $this->filterButtons));
430 }
431
436 public function renderFilterRightButtons()
437 {
438 return $this->renderAfterFilterButtons();
439 }
440
441 protected function processButtonRender(Button $button)
442 {
443 $shouldAddThemeModifier = (bool)array_intersect($button->getClassList(), [
444 'ui-btn-light-border',
445 'ui-btn-light',
446 'ui-btn-link',
447 ]) && $button->hasAirDesign() === false;
448
449 if ($shouldAddThemeModifier)
450 {
451 $button->addClass('ui-btn-themes');
452 }
453
454 return $button->render(false);
455 }
456
457 public function setTitleMinWidth($width)
458 {
459 if (is_int($width) && $width > 0)
460 {
461 $this->titleMinWidth = $width;
462 }
463 }
464
465 public function getTitleMinWidth()
466 {
467 return $this->titleMinWidth;
468 }
469
470 public function setTitleMaxWidth($width)
471 {
472 if (is_int($width) && $width > 0)
473 {
474 $this->titleMaxWidth = $width;
475 }
476 }
477
478 public function setTitleNoShrink(bool $flag = true): void
479 {
480 $this->isTitleNoShrink = $flag;
481 }
482
483 public function isTitleNoShrink(): bool
484 {
485 return $this->isTitleNoShrink;
486 }
487
488 public function getTitleMaxWidth()
489 {
490 return $this->titleMaxWidth;
491 }
492
493 public function enableMultiLineTitle(): void
494 {
495 $this->isMultiLineTitleEnabled = true;
496 }
497
498 public function disableMultiLineTitle(): void
499 {
500 $this->isMultiLineTitleEnabled = false;
501 }
502
503 public function isMultiLineTitleEnabled(): bool
504 {
505 return $this->isMultiLineTitleEnabled;
506 }
507
512 protected function convertColorToAirButtonStyle(string $color = null): ?string
513 {
514 $map = [
515 Color::DANGER => AirButtonStyle::FILLED_ALERT,
516 Color::DANGER_LIGHT => AirButtonStyle::FILLED_ALERT,
517 Color::DANGER_DARK => AirButtonStyle::FILLED_ALERT,
518 Color::SUCCESS => AirButtonStyle::FILLED_SUCCESS,
519 Color::SUCCESS_LIGHT => AirButtonStyle::FILLED_SUCCESS,
520 Color::PRIMARY => AirButtonStyle::FILLED_SUCCESS,
521 Color::PRIMARY_DARK => AirButtonStyle::FILLED_SUCCESS,
522 Color::LIGHT_BORDER => AirButtonStyle::OUTLINE,
523 Color::LINK => AirButtonStyle::OUTLINE,
524 Color::SECONDARY => AirButtonStyle::TINTED,
525 Color::LIGHT => AirButtonStyle::PLAIN_ACCENT,
526 ];
527
528 return $map[$color] ?? null;
529 }
530
531 public function hasAirDesign(): bool
532 {
533 return defined('AIR_SITE_TEMPLATE');
534 }
535}
render($jsInit=true)
Определения basebutton.php:176
addClass($className)
Определения basebutton.php:377
const ADD_M
Определения icon.php:10
disableMultiLineTitle()
Определения toolbar.php:498
addFavoriteStar()
Определения toolbar.php:269
renderFilterRightButtons()
Определения toolbar.php:436
setTitleMinWidth($width)
Определения toolbar.php:457
convertColorToAirButtonStyle(string $color=null)
Определения toolbar.php:512
getRightCustomHtmlOptions()
Определения toolbar.php:372
hasAirDesign()
Определения toolbar.php:531
getCopyLinkButton()
Определения toolbar.php:398
getFilter()
Определения toolbar.php:316
isTitleNoShrink()
Определения toolbar.php:483
renderRightButtons()
Определения toolbar.php:418
setTitleNoShrink(bool $flag=true)
Определения toolbar.php:478
hasFavoriteStar()
Определения toolbar.php:264
__construct($id, $options)
Определения toolbar.php:54
addButton($button, $location=ButtonLocation::RIGHT)
Определения toolbar.php:149
getTitleMaxWidth()
Определения toolbar.php:488
renderAfterFilterButtons()
Определения toolbar.php:425
getRightCustomHtml()
Определения toolbar.php:367
disable()
Определения toolbar.php:75
getTitleMinWidth()
Определения toolbar.php:465
addFilter(array $filterOptions=[])
Определения toolbar.php:283
hasEditableTitle()
Определения toolbar.php:129
addAfterTitleHtml(string $html)
Определения toolbar.php:341
hasTitle()
Определения toolbar.php:102
setTitle(string $title)
Определения toolbar.php:80
setFilter(string $filter)
Определения toolbar.php:311
getBeforeTitleHtml()
Определения toolbar.php:336
enable()
Определения toolbar.php:70
hideTitle()
Определения toolbar.php:97
deleteFavoriteStar()
Определения toolbar.php:276
addBeforeTitleHtml(string $html)
Определения toolbar.php:331
shuffleButtons(\Closure $closure, $buttonLocation)
Определения toolbar.php:231
deleteButtons(\Closure $closure)
Определения toolbar.php:204
addEditableTitle(string $defaultTitle=null)
Определения toolbar.php:107
getBeforeTitleBoxHtml()
Определения toolbar.php:326
enableMultiLineTitle()
Определения toolbar.php:493
isMultiLineTitleEnabled()
Определения toolbar.php:503
getAfterTitleHtml()
Определения toolbar.php:346
addUnderTitleHtml(string $html)
Определения toolbar.php:351
renderAfterTitleButtons()
Определения toolbar.php:411
isEnabled()
Определения toolbar.php:65
getDefaultEditableTitle()
Определения toolbar.php:113
setTitleMaxWidth($width)
Определения toolbar.php:470
setCopyLinkButton(?array $params=[])
Определения toolbar.php:382
getTitle($propertyName=false, $stripTags=false)
Определения toolbar.php:85
getUnderTitleHtml()
Определения toolbar.php:356
addBeforeTitleBoxHtml(string $html)
Определения toolbar.php:321
processButtonRender(Button $button)
Определения toolbar.php:441
addRightCustomHtml(string $html, array $options=[])
Определения toolbar.php:361
getButtons()
Определения toolbar.php:406
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$filter
Определения iblock_catalog_list.php:54
$map
Определения config.php:5
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
<? endif;?> window document title
Определения prolog_main_admin.php:76
$filterOptions
Определения options.php:63
$i
Определения factura.php:643
$width
Определения html.php:68
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$title
Определения pdf.php:123
$location
Определения options.php:2729
$GLOBALS['_____370096793']
Определения update_client.php:1