Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
widgetform.php
1<?php
5
10class WidgetForm extends Form
11{
12 private $view;
13 private $widget;
14 private $reportsInWidgetCount;
15 private $boarId;
16
22 public function __construct(View $view, Widget $widget)
23 {
24 $this->setView($view);
25 $this->setWidget($widget);
26 }
27
31 public function render()
32 {
33 $view = $this->getView();
34 $view->prepareWidgetFormBeforeRender($this);
35 parent::render();
36 }
37
46 public static function build(View $view, Widget $widget, $params)
47 {
48 $boardId = $params['boardId'];
49 $action = $params['action'];
50 $saveButtonTitle = $params['saveButtonTitle'];
51
52 $form = new static($view, $widget);
53 $form->setId('report_widget_configuration_form_' . $widget->getGId());
54 $form->setAction($action);
55 $form->setBoarId($boardId);
56 $form->addDataAttribute('widget-id', $widget->getGId());
57 $form->addWidgetConfigurationFormFullContent();
58
59
60 $footerContainer = new Fields\Div();
61 $footerContainer->setKey('footer_container');
62 $footerContainer->addClass('report-widget-configuration-form-footer-container');
63 $footerContainer->addDataAttribute('role', 'footer-container');
64
65
66 $buttonsContainer = new Fields\Div();
67 $buttonsContainer->addClass('report-widget-configuration-form-action-buttons-container');
68 $saveButton = new Fields\Button('widgetSaveConfigurations_' . $widget->getGId());
69 $saveButton->addDataAttribute('type', 'save-button');
70 $saveButton->addClass('ui-btn');
71 $saveButton->addClass('ui-btn-md');
72 $saveButton->addClass('ui-btn-success');
73 $saveButton->setLabel($saveButtonTitle);
74
75
76 $cancelButton = new Fields\Button('widgetCancelConfigurations_' . $widget->getGId());
77 $cancelButton->addDataAttribute('type', 'cancel-button');
78 $cancelButton->addClass('ui-btn');
79 $cancelButton->addClass('ui-btn-md');
80 $cancelButton->addClass('ui-btn-link');
81 $cancelButton->setLabel(Loc::getMessage('SAVE_WIDGET_CONFIG_CANCEL_BUTTON'));
82
83 $checkBoxContainer = new Fields\Div();
84 $checkBoxContainer->addClass('report-configuration-footer-right-container');
85
86 $isPatternCheckBox = new Fields\Valuable\CheckBox('isPattern');
87 $isPatternCheckBox->setLabel(Loc::getMessage('SAVE_WIDGET_AS_PATTERN'));
88
89 $form->add($footerContainer->start());
90 $form->add($buttonsContainer->start());
91 $form->add($saveButton);
92 $form->add($cancelButton);
93 $form->add($buttonsContainer->end());
94 $form->add($checkBoxContainer->start());
95 $form->add($isPatternCheckBox);
96 $form->add($checkBoxContainer->end());
97 $form->add($footerContainer->end());
98
99
100
101 return $form;
102 }
103
104
105 private function addWidgetConfigurationFormFullContent()
106 {
107 $view = $this->getView();
108 $formContentContainer = new Fields\Div();
109 $formContentContainer->addClass('report-widget-configuration-form-content');
110 $formContentContainer->setKey('form_content_container');
111 $this->add($formContentContainer->start());
112 $this->addWidgetConfigurationsBlock();
113
114 $reportsConfigurationsContainerWrapper = new Fields\Div();
115 $reportsConfigurationsContainerWrapper->addClass('reports-configurations-container-wrapper');
116 $this->add($reportsConfigurationsContainerWrapper->start());
117 $this->addReportsConfigurationsBlock();
118 $this->addReportAddButtonBlock();
119 $this->add($reportsConfigurationsContainerWrapper->end());
120
121 $maxReportCountField = new Fields\Valuable\Hidden('maxReportCount');
122 $maxReportCountField->addDataAttribute('hidden-field', 'maxRenderReportCount');
123 $maxReportCountField->setValue($view::MAX_RENDER_REPORT_COUNT);
124 $this->add($maxReportCountField);
125
126 $boardIdField = new Fields\Valuable\Hidden('boardId');
127 $boardIdField->setValue($this->getBoarId());
128 $this->add($boardIdField);
129
130 $widgetIdField = new Fields\Valuable\Hidden('widgetId');
131 $widgetIdField->setValue($this->getWidget()->getGId());
132 $this->add($widgetIdField);
133
134 $categoryKeyField = new Fields\Valuable\Hidden('categoryKey');
135 $categoryKeyField->setValue($this->getWidget()->getCategoryKey());
136 $this->add($categoryKeyField);
137
138 $this->add($formContentContainer->end());
139 }
140
141 private function addWidgetConfigurationsBlock()
142 {
143 $widgetConfigurationFields = $this->getWidgetConfigurationFields();
144 $widgetConfigurationsContainer = new Fields\Div();
145 $widgetConfigurationsContainer->addClass('widgets-configurations-container');
146
147 $this->add($widgetConfigurationsContainer->start());
148 foreach ($widgetConfigurationFields as $configurationField)
149 {
150 $this->add($configurationField);
151 }
152 $this->add($widgetConfigurationsContainer->end());
153 }
154
155 private function addReportsConfigurationsBlock()
156 {
157 $reportsConfigurationFields = $this->getReportConfigurationFields();
158 $reportsConfigurationsContainer = new Fields\Div();
159 $reportsConfigurationsContainer->addClass('reports-configurations-container');
160 $reportsConfigurationsContainer->addDataAttribute('role', 'reports-configurations-container');
161 $reportsConfigurationsContainer->addDataAttribute('widget-id', $this->getWidget()->getGId());
162 $this->add($reportsConfigurationsContainer->start());
163 $this->reportsInWidgetCount = count($reportsConfigurationFields);
164 if($reportsConfigurationFields)
165 {
166 $reportConfigurationsContainer = new Fields\Div();
167 $reportConfigurationsContainer->addClass('report-configuration-container');
168 $reportConfigurationsContainer->addDataAttribute('role', 'report-configuration-container');
169 $reportConfigurationsContainer->addDataAttribute('is-pseudo', '0');
170 $reportConfigurationsContainer->addClass('report-configuration-container-visible');
171
172 $num = 0;
173 foreach ($reportsConfigurationFields as $reportGId => $reportConfiguration)
174 {
175 $num++;
176 $reportConfigurationsContainer->addDataAttribute('report-id', $reportGId);
177 $container = new Fields\Container();
178 $container->setKey('report_configurations_container_' . $num);
179 $container->addDataAttribute('role', 'report-configuration-container');
180
181
182
183 $container->addElement($reportConfigurationsContainer->start());
185 foreach ($reportConfiguration['FIELDS'] as $configurationField)
186 {
187 $container->addElement($configurationField);
188
189 }
190
191 $container->addElement($reportConfigurationsContainer->end());
192 $this->add($container);
193 }
194 }
195
196 $this->add($reportsConfigurationsContainer->end());
197 }
198
199 private function addReportAddButtonBlock()
200 {
201 $addButtonContainer = new Fields\Div();
202 $addButtonContainer->addClass('report-configuration-add-report-button-container');
203 $addButton = new Fields\Button('widgetAddReportButton_' . $this->getWidget()->getGId());
204 $addButton->addClass('add-report-to-widget-button');
205 $view = $this->getView();
206 if ($view::MAX_RENDER_REPORT_COUNT <= $this->reportsInWidgetCount)
207 {
208 $addButtonContainer->addClass('report-configuration-add-report-button-container-invisible');
209 }
210 $addButton->setLabel(Loc::getMessage('ADD_REPORT_BUTTON'));
211 $this->add($addButtonContainer->start());
212 $this->add('&#43;');
213 $this->add($addButton);
214 $this->add($addButtonContainer->end());
215 }
216
220 private function getWidgetConfigurationFields()
221 {
222 return $this->getWidget()->getWidgetHandler()->getFormElements();
223 }
224
228 private function getReportConfigurationFields()
229 {
230 $reports = $this->getWidget()->getReports();
231 $configurations = array();
232 foreach ($reports as $report)
233 {
234 $reportHandler = $report->getReportHandler();
235 $reportHandler->setView($this->view);
236 $configurations[$report->getGId()]['FIELDS'] = $reportHandler->getFormElements();
237 }
238 return $configurations;
239 }
240
244 public function getView()
245 {
246 return $this->view;
247 }
248
253 public function setView(View $view)
254 {
255 $this->view = $view;
256 }
257
261 public function getWidget()
262 {
263 return $this->widget;
264 }
265
270 public function setWidget(Widget $widget)
271 {
272 $this->widget = $widget;
273 }
274
278 public function getBoarId()
279 {
280 return $this->boarId;
281 }
282
287 public function setBoarId($boarId)
288 {
289 $this->boarId = $boarId;
290 }
291}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static build(View $view, Widget $widget, $params)
__construct(View $view, Widget $widget)