From a42be2a6e83a80836efd63fb1863f3ecfe55bc6d Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 7 Mar 2016 18:39:19 +0100 Subject: [PATCH] IcingaServiceForm: cleanup, no details without type --- application/forms/IcingaServiceForm.php | 69 ++++++++++++++----------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index 7b763d19..28ecb105 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -10,6 +10,7 @@ class IcingaServiceForm extends DirectorObjectForm { $this->addObjectTypeElement(); if (! $this->hasObjectType()) { + $this->groupObjectDefinition(); return; } @@ -29,39 +30,24 @@ class IcingaServiceForm extends DirectorObjectForm )); } - $this->addElement('extensibleSet', 'groups', array( - 'label' => $this->translate('Groups'), - 'multiOptions' => $this->optionallyAddFromEnum($this->enumServicegroups()), - 'positional' => false, - 'description' => $this->translate( - 'Service groups that should be directly assigned to this service. Servicegroups can be useful' - . ' for various reasons. They are helpful to provided service-type specific view in Icinga Web 2,' - . ' either for custom dashboards or as an instrument to enforce restrictior. Service groups' - . ' can be directly assigned to single services or to service templates.' - ) - )); + $groups = $this->enumServicegroups(); + if (! empty($groups)) { + $this->addElement('extensibleSet', 'groups', array( + 'label' => $this->translate('Groups'), + 'multiOptions' => $this->optionallyAddFromEnum($groups), + 'positional' => false, + 'description' => $this->translate( + 'Service groups that should be directly assigned to this service. Servicegroups can be useful' + . ' for various reasons. They are helpful to provided service-type specific view in Icinga Web 2,' + . ' either for custom dashboards or as an instrument to enforce restrictior. Service groups' + . ' can be directly assigned to single services or to service templates.' + ) + )); + } $this->addImportsElement(); $this->addDisabledElement(); - - $elements = array( - 'object_type', - 'object_name', - 'display_name', - 'imports', - 'host_id', - 'groups', - 'disabled', - ); - $this->addDisplayGroup($elements, 'object_definition', array( - 'decorators' => array( - 'FormElements', - array('HtmlTag', array('tag' => 'dl')), - 'Fieldset', - ), - 'order' => 20, - 'legend' => $this->translate('Service properties') - )); + $this->groupObjectDefinition(); $this->addCheckCommandElements(); @@ -96,6 +82,29 @@ class IcingaServiceForm extends DirectorObjectForm $this->setButtons(); } + + protected function groupObjectDefinition() + { + $elements = array( + 'object_type', + 'object_name', + 'display_name', + 'imports', + 'host_id', + 'groups', + 'disabled', + ); + $this->addDisplayGroup($elements, 'object_definition', array( + 'decorators' => array( + 'FormElements', + array('HtmlTag', array('tag' => 'dl')), + 'Fieldset', + ), + 'order' => 20, + 'legend' => $this->translate('Service properties') + )); + } + protected function enumHostsAndTemplates() { return array(