diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index d120f523..1d06b683 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -11,7 +11,7 @@ class IcingaHostForm extends DirectorObjectForm { $this->addObjectTypeElement(); if (! $this->hasObjectType()) { - return; + return $this->groupMainProperties(); } $this->addElement('text', 'object_name', array( @@ -25,53 +25,13 @@ class IcingaHostForm extends DirectorObjectForm ) )); - $this->addGroupsElement(); - $this->addImportsElement(); - - $this->addElement('text', 'display_name', array( - 'label' => $this->translate('Display name'), - 'description' => $this->translate( - 'Alternative name for this host. Might be a host alias or and kind' - . ' of string helping your users to identify this host' - ) - )); - - $this->addElement('text', 'address', array( - 'label' => $this->translate('Host address'), - 'description' => $this->translate( - 'Host address. Usually an IPv4 address, but may be any kind of address' - . ' your check plugin is able to deal with' - ) - )); - - $this->addElement('text', 'address6', array( - 'label' => $this->translate('IPv6 address'), - 'description' => $this->translate('Usually your hosts main IPv6 address') - )); - - $this->addDisabledElement(); - - $elements = array( - 'object_type', - 'object_name', - 'display_name', - 'address', - 'address6', - 'imports', - 'groups', - 'disabled', - ); - $this->addDisplayGroup($elements, 'object_definition', array( - 'decorators' => array( - 'FormElements', - array('HtmlTag', array('tag' => 'dl')), - 'Fieldset', - ), - 'order' => 20, - 'legend' => $this->translate('Host properties') - )); - - $this->addZoneElement(); + $this->addGroupsElement() + ->addImportsElement() + ->addDisplayNameElement() + ->addAddressElements() + ->addDisabledElement() + ->groupMainProperties() + ->addZoneElement(); $this->addBoolean('has_agent', array( 'label' => $this->translate('Icinga2 Agent'), @@ -112,14 +72,9 @@ class IcingaHostForm extends DirectorObjectForm 'legend' => $this->translate('Icinga Agent and zone settings') )); - if ($this->isTemplate()) { - $this->addCheckCommandElements(); - $this->addCheckExecutionElements(); - } else { - $this->getElement('imports')->setRequired(); - } - - $this->setButtons(); + $this->addCheckCommandElements() + ->addCheckExecutionElements() + ->setButtons(); } protected function addGroupsElement() @@ -145,6 +100,45 @@ class IcingaHostForm extends DirectorObjectForm return $this; } + protected function addAddressElements() + { + if ($this->isTemplate()) { + return $this; + } + + $this->addElement('text', 'address', array( + 'label' => $this->translate('Host address'), + 'description' => $this->translate( + 'Host address. Usually an IPv4 address, but may be any kind of address' + . ' your check plugin is able to deal with' + ) + )); + + $this->addElement('text', 'address6', array( + 'label' => $this->translate('IPv6 address'), + 'description' => $this->translate('Usually your hosts main IPv6 address') + )); + + return $this; + } + + protected function addDisplayNameElement() + { + if ($this->isTemplate()) { + return $this; + } + + $this->addElement('text', 'display_name', array( + 'label' => $this->translate('Display name'), + 'description' => $this->translate( + 'Alternative name for this host. Might be a host alias or and kind' + . ' of string helping your users to identify this host' + ) + )); + + return $this; + } + protected function enumHostgroups() { $db = $this->db->getDbAdapter(); diff --git a/application/forms/IcingaNotificationForm.php b/application/forms/IcingaNotificationForm.php index 1b7bbd57..81ba200b 100644 --- a/application/forms/IcingaNotificationForm.php +++ b/application/forms/IcingaNotificationForm.php @@ -10,6 +10,7 @@ class IcingaNotificationForm extends DirectorObjectForm { $this->addObjectTypeElement(); if (! $this->hasObjectType()) { + $this->groupMainProperties(); return; } @@ -19,8 +20,11 @@ class IcingaNotificationForm extends DirectorObjectForm 'description' => $this->translate('Icinga object name for this notification') )); - - $this->addDisabledElement(); - $this->setButtons(); + $this->addDisabledElement() + ->addImportsElement() + ->addDisabledElement() + ->addEventFilterElements() + ->groupMainProperties() + ->setButtons(); } } diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index 28ecb105..e04f2666 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -10,99 +10,98 @@ class IcingaServiceForm extends DirectorObjectForm { $this->addObjectTypeElement(); if (! $this->hasObjectType()) { - $this->groupObjectDefinition(); - return; + return $this->groupMainProperties(); } $this->addElement('text', 'object_name', array( 'label' => $this->translate('Name'), 'required' => true, - 'description' => $this->translate('Name for the Icinga object you are going to create') + 'description' => $this->translate( + 'Name for the Icinga object you are going to create' + ) )); - // TODO: Should not be 'object' on new empty form: + $this->addHostObjectElement() + ->addImportsElement() + ->addGroupsElement() + ->addDisabledElement() + ->groupMainProperties() + ->addCheckCommandElements() + ->addCheckExecutionElements() + ->addAgentAndZoneElements() + ->setButtons(); + } + + protected function addHostObjectElement() + { if ($this->isObject()) { $this->addElement('select', 'host_id', array( 'label' => $this->translate('Host'), 'required' => true, 'multiOptions' => $this->optionalEnum($this->enumHostsAndTemplates()), - 'description' => $this->translate('Choose the host this single service should be assigned to') + 'description' => $this->translate( + 'Choose the host this single service should be assigned to' + ) )); } + return $this; + } + + protected function addGroupsElement() + { $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.' + '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' + . ' restrictions. Service groups can be directly assigned to' + . ' single services or to service templates.' ) )); } - $this->addImportsElement(); - $this->addDisabledElement(); - $this->groupObjectDefinition(); - - $this->addCheckCommandElements(); - - if ($this->isTemplate()) { - $this->addCheckExecutionElements(); - } - - if ($this->isTemplate()) { - $this->optionalBoolean( - 'use_agent', - $this->translate('Run on agent'), - $this->translate('Whether the check commmand for this service should be executed on the Icinga agent') - ); - $this->addZoneElement(); - - $elements = array( - 'use_agent', - 'zone_id', - ); - $this->addDisplayGroup($elements, 'clustering', array( - 'decorators' => array( - 'FormElements', - array('HtmlTag', array('tag' => 'dl')), - 'Fieldset', - ), - 'order' => 40, - 'legend' => $this->translate('Icinga Agent and zone settings') - )); - - } - - $this->setButtons(); + return $this; } - - protected function groupObjectDefinition() + protected function addAgentAndZoneElements() { - $elements = array( - 'object_type', - 'object_name', - 'display_name', - 'imports', - 'host_id', - 'groups', - 'disabled', + if ($this->isTemplate()) { + return $this; + } + + $this->optionalBoolean( + 'use_agent', + $this->translate('Run on agent'), + $this->translate( + 'Whether the check commmand for this service should be executed' + . ' on the Icinga agent' + ) ); - $this->addDisplayGroup($elements, 'object_definition', array( + $this->addZoneElement(); + + $elements = array( + 'use_agent', + 'zone_id', + ); + $this->addDisplayGroup($elements, 'clustering', array( 'decorators' => array( 'FormElements', array('HtmlTag', array('tag' => 'dl')), 'Fieldset', ), - 'order' => 20, - 'legend' => $this->translate('Service properties') + 'order' => 40, + 'legend' => $this->translate('Icinga Agent and zone settings') )); + + return $this; } protected function enumHostsAndTemplates() diff --git a/application/forms/IcingaUserForm.php b/application/forms/IcingaUserForm.php index 219a82ef..b8d0749c 100644 --- a/application/forms/IcingaUserForm.php +++ b/application/forms/IcingaUserForm.php @@ -10,8 +10,7 @@ class IcingaUserForm extends DirectorObjectForm { $this->addObjectTypeElement(); if (! $this->hasObjectType()) { - $this->groupObjectDefinition(); - return; + return $this->groupMainProperties(); } if ($this->isTemplate()) { @@ -38,20 +37,24 @@ class IcingaUserForm extends DirectorObjectForm 'description' => $this->translate('The pager address of the user.') )); - $this->addGroupsElement(); - $this->addImportsElement(); + $this->addGroupsElement() + ->addImportsElement() + ->addEnableNotificationsElement() + ->addDisabledElement() + ->addEventFilterElements() + ->groupMainProperties() + ->setButtons(); + } + + protected function addEnableNotificationsElement() + { $this->optionalBoolean( 'enable_notifications', $this->translate('Send notifications'), $this->translate('Whether to send notifications for this user') ); - $this->addDisabledElement(); - $this->groupObjectDefinition(); - - $this->addEventFilterElements(); - - $this->setButtons(); + return $this; } protected function addGroupsElement() diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 1f3a8ab3..912a4417 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -404,6 +404,36 @@ abstract class DirectorObjectForm extends QuickForm } } + protected function groupMainProperties() + { + $elements = array( + 'object_type', + 'object_name', + 'display_name', + 'imports', + 'host_id', + 'address', + 'address6', + 'groups', + 'email', + 'pager', + 'enable_notifications', + 'disabled', + ); + + $this->addDisplayGroup($elements, 'object_definition', array( + 'decorators' => array( + 'FormElements', + array('HtmlTag', array('tag' => 'dl')), + 'Fieldset', + ), + 'order' => 20, + 'legend' => $this->translate('Main properties') + )); + + return $this; + } + protected function addField($field, $value = null, $inherited = null, $inheritedFrom = null) { $datafield = DirectorDatafield::load($field->datafield_id, $this->getDb()); @@ -972,6 +1002,10 @@ print_r($object); protected function addDisabledElement() { + if ($this->isTemplate()) { + return $this; + } + $this->addBoolean( 'disabled', array( @@ -999,6 +1033,10 @@ print_r($object); protected function addCheckCommandElements() { + if ($this->isTemplate()) { + return $this; + } + $this->addElement('select', 'check_command_id', array( 'label' => $this->translate('Check command'), 'description' => $this->translate('Check command definition'), @@ -1006,10 +1044,15 @@ print_r($object); 'class' => 'autosubmit', // This influences fields )); $this->addToCheckExecutionDisplayGroup('check_command_id'); + + return $this; } protected function addCheckExecutionElements() { + if ($this->isTemplate()) { + return $this; + } $this->addElement( 'text', @@ -1130,6 +1173,8 @@ print_r($object); 'order' =>70, 'legend' => $this->translate('State and transition type filters') )); + + return $this; } protected function enumStates()