1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
documentbutton.php
См. документацию.
1<?php
2
3namespace Bitrix\UI\Buttons;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Text;
8use Bitrix\Main\Web\Json;
9
11{
12 private array $documentButtonConfig = [];
13
17 protected function getDefaultParameters(): array
18 {
19 return [
20 'tag' => Tag::BUTTON,
21 'color' => Color::LIGHT_BORDER,
22 'dropdown' => true,
23 'domId' => $this->getUniqId(),
24 'text' => Loc::getMessage('UI_BUTTON_DOCUMENT_TEXT'),
25 'dataset' => [
26 'toolbar-collapsed-icon' => Icon::LIST,
27 ],
28 ];
29 }
30
31 protected function buildFromArray($params): void
32 {
33 if (isset($params['documentButtonConfig']) && is_array($params['documentButtonConfig']))
34 {
35 $this->setDocumentButtonConfig($params['documentButtonConfig']);
36 unset($params['documentButtonConfig']);
37 }
38 parent::buildFromArray($params);
39 if (!empty($params['domId']) && is_string($params['domId']))
40 {
41 $this->setDomId($params['domId']);
42 }
43 }
44
45 public function setDocumentButtonConfig(array $config): void
46 {
47 $this->documentButtonConfig = $config;
48 }
49
50 private function getDocumentButtonConfig(): array
51 {
52 return $this->documentButtonConfig;
53 }
54
55 protected function listExtensions(): array
56 {
57 return [
58 'documentpreview',
59 ];
60 }
61
62 protected function renderJavascript(): string
63 {
64 $id = $this->getDomId();
65 $config = $this->getDocumentButtonConfig();
66 if ($id === '' || empty($config))
67 {
68 return '';
69 }
70
72 $params = Json::encode($config);
73
74 return
75 <<<JS
76 if (BX.DocumentGenerator && BX.DocumentGenerator.Button)
77 {
78 const button = new BX.DocumentGenerator.Button('$id', $params);
79 button.init();
80 }
81 else
82 {
83 console.warn('BX.DocumentGenerator.Button is not found');
84 }
85 JS
86 ;
87 }
88
89 public function render($jsInit = true): string
90 {
91 if (!Loader::includeModule('documentgenerator'))
92 {
93 return '';
94 }
95
96 return parent::render(true);
97 }
98
99 private function setDomId(string $id): void
100 {
101 $this->getAttributeCollection()['id'] = $id;
102 }
103
104 private function getDomId(): string
105 {
106 return (string)($this->getAttributeCollection()['id'] ?? '');
107 }
108}
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения htmlfilter.php:12
render($jsInit=true)
Определения basebutton.php:176
getAttributeCollection()
Определения basebutton.php:472
const LIGHT_BORDER
Определения color.php:17
buildFromArray($params)
Определения documentbutton.php:31
setDocumentButtonConfig(array $config)
Определения documentbutton.php:45
const LIST
Определения icon.php:22
const BUTTON
Определения tag.php:6
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$config
Определения quickway.php:69
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799