From cdbcd7795288d7f02b1c3df101923bff30eb2454 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 23 Mar 2016 00:40:40 +0100 Subject: [PATCH] IcingaHostForm: simplify form --- application/forms/IcingaHostForm.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index 0f1354e6..fa40d64b 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -38,7 +38,19 @@ class IcingaHostForm extends DirectorObjectForm ->addAddressElements() ->addDisabledElement() ->groupMainProperties() - ->addZoneElement(); + ->addClusteringElements() + ->addCheckCommandElements() + ->addCheckExecutionElements() + ->setButtons(); + } + + protected function addClusteringElements() + { + if (!$this->isTemplate() && !$this->hasClusterProperties()) { + return $this; + } + + $this->addZoneElement(); $this->addBoolean('has_agent', array( 'label' => $this->translate('Icinga2 Agent'), @@ -79,9 +91,16 @@ class IcingaHostForm extends DirectorObjectForm 'legend' => $this->translate('Icinga Agent and zone settings') )); - $this->addCheckCommandElements() - ->addCheckExecutionElements() - ->setButtons(); + return $this; + } + + protected function hasClusterProperties() + { + if (!$object = $this->object) { + return false; + } + + return $object->zone_id || $object->has_agent; } protected function beforeSuccessfulRedirect()