From da29da00659ba5e25ae0491162b5037cc5ffa343 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 7 Mar 2016 14:20:58 +0100 Subject: [PATCH] forms/Icinga*: choose type first, then go on --- application/forms/IcingaCommandForm.php | 3 +++ application/forms/IcingaEndpointForm.php | 3 +++ application/forms/IcingaHostForm.php | 3 +++ application/forms/IcingaNotificationForm.php | 3 +++ application/forms/IcingaServiceForm.php | 3 +++ library/Director/Web/Form/DirectorObjectForm.php | 11 ++++++++++- 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/application/forms/IcingaCommandForm.php b/application/forms/IcingaCommandForm.php index 4eda2036..9059c011 100644 --- a/application/forms/IcingaCommandForm.php +++ b/application/forms/IcingaCommandForm.php @@ -9,6 +9,9 @@ class IcingaCommandForm extends DirectorObjectForm public function setup() { $this->addObjectTypeElement(); + if (! $this->hasObjectType()) { + return; + } $this->addElement('select', 'methods_execute', array( 'label' => $this->translate('Command type'), diff --git a/application/forms/IcingaEndpointForm.php b/application/forms/IcingaEndpointForm.php index 03c6c29a..a20b4a9e 100644 --- a/application/forms/IcingaEndpointForm.php +++ b/application/forms/IcingaEndpointForm.php @@ -9,6 +9,9 @@ class IcingaEndpointForm extends DirectorObjectForm public function setup() { $this->addObjectTypeElement(); + if (! $this->hasObjectType()) { + return; + } if ($this->isTemplate()) { $this->addElement('text', 'object_name', array( diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index 693d6fc4..2105c251 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -10,6 +10,9 @@ class IcingaHostForm extends DirectorObjectForm public function setup() { $this->addObjectTypeElement(); + if (! $this->hasObjectType()) { + return; + } $this->addElement('text', 'object_name', array( 'label' => $this->translate('Hostname'), diff --git a/application/forms/IcingaNotificationForm.php b/application/forms/IcingaNotificationForm.php index c3ca8b86..1b7bbd57 100644 --- a/application/forms/IcingaNotificationForm.php +++ b/application/forms/IcingaNotificationForm.php @@ -9,6 +9,9 @@ class IcingaNotificationForm extends DirectorObjectForm public function setup() { $this->addObjectTypeElement(); + if (! $this->hasObjectType()) { + return; + } $this->addElement('text', 'object_name', array( 'label' => $this->translate('Notification'), diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index d4d2b2ab..7b763d19 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -9,6 +9,9 @@ class IcingaServiceForm extends DirectorObjectForm public function setup() { $this->addObjectTypeElement(); + if (! $this->hasObjectType()) { + return; + } $this->addElement('text', 'object_name', array( 'label' => $this->translate('Name'), diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 4e24bbbd..18fc004c 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -893,13 +893,22 @@ print_r($object); . ' to assign services, notifications and groups to other objects.' ), 'multiOptions' => $this->optionalEnum($types), - 'value' => $default, 'class' => 'autosubmit' )); return $this; } + protected function hasObjectType() + { + return ! $this->valueIsEmpty($this->getSentOrObjectValue('object_type')); + } + + protected function valueIsEmpty($value) + { + return strlen($value) === 0; + } + protected function addZoneElement() { if ($this->isTemplate()) {