Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/controllers/CControllerDashboardWidgetCheck.php')
-rw-r--r--ui/app/controllers/CControllerDashboardWidgetCheck.php34
1 files changed, 23 insertions, 11 deletions
diff --git a/ui/app/controllers/CControllerDashboardWidgetCheck.php b/ui/app/controllers/CControllerDashboardWidgetCheck.php
index 5c1c159bddc..6c9d3208dbf 100644
--- a/ui/app/controllers/CControllerDashboardWidgetCheck.php
+++ b/ui/app/controllers/CControllerDashboardWidgetCheck.php
@@ -19,9 +19,14 @@
**/
+use Zabbix\Core\{
+ CModule,
+ CWidget
+};
+
class CControllerDashboardWidgetCheck extends CController {
- private $context;
+ private ?CWidget $widget = null;
protected function init() {
$this->setPostContentType(self::POST_CONTENT_TYPE_JSON);
@@ -29,26 +34,33 @@ class CControllerDashboardWidgetCheck extends CController {
protected function checkInput() {
$fields = [
- 'templateid' => 'db dashboard.templateid',
'type' => 'required|string',
- 'name' => 'required|string',
- 'fields' => 'json'
+ 'fields' => 'array',
+ 'templateid' => 'db dashboard.templateid',
+ 'name' => 'required|string'
];
$ret = $this->validateInput($fields);
if ($ret) {
- $this->context = $this->hasInput('templateid')
- ? CWidgetConfig::CONTEXT_TEMPLATE_DASHBOARD
- : CWidgetConfig::CONTEXT_DASHBOARD;
+ $widget = APP::ModuleManager()->getModule($this->getInput('type'));
- if (!CWidgetConfig::isWidgetTypeSupportedInContext($this->getInput('type'), $this->context)) {
- error(_('Widget type is not supported in this context.'));
+ if ($widget !== null && $widget->getType() === CModule::TYPE_WIDGET) {
+ $this->widget = $widget;
+ }
+ else {
+ error(_('Inaccessible widget type.'));
$ret = false;
}
}
+ if ($ret && $this->hasInput('templateid') && !$this->widget->hasTemplateSupport()) {
+ error(_('Widget type is not supported in this context.'));
+
+ $ret = false;
+ }
+
if (!$ret) {
$this->setResponse(
new CControllerResponseData(['main_block' => json_encode([
@@ -67,8 +79,8 @@ class CControllerDashboardWidgetCheck extends CController {
}
protected function doAction() {
- $form = CWidgetConfig::getForm($this->getInput('type'), $this->getInput('fields', '{}'),
- ($this->context === CWidgetConfig::CONTEXT_TEMPLATE_DASHBOARD) ? $this->getInput('templateid') : null
+ $form = $this->widget->getForm($this->getInput('fields', []),
+ $this->hasInput('templateid') ? $this->getInput('templateid') : null
);
$output = [];