diff --git a/modules/monitoring/application/forms/Config/Backend/CreateBackendForm.php b/modules/monitoring/application/forms/Config/Backend/CreateBackendForm.php deleted file mode 100644 index 513dea238..000000000 --- a/modules/monitoring/application/forms/Config/Backend/CreateBackendForm.php +++ /dev/null @@ -1,45 +0,0 @@ -setBackendConfiguration(new Zend_Config(array('type' => 'ido'))); - $this->addElement( - 'text', - 'backend_name', - array( - 'label' => 'Backend Name', - 'required' => true, - 'helptext' => 'This will be the identifier of this backend' - ) - ); - parent::create(); - } - - /** - * Return the name of the backend that is to be created - * - * @return string The name of the backend as entered in the form - */ - public function getBackendName() - { - return $this->getValue('backend_name'); - } -} diff --git a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php b/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php deleted file mode 100644 index b66383f73..000000000 --- a/modules/monitoring/application/forms/Config/Backend/EditBackendForm.php +++ /dev/null @@ -1,99 +0,0 @@ -getRequest()->getParam('backend_type', $this->backend->type); - - $this->addElement( - 'select', - 'backend_type', - array( - 'label' => 'Backend Type', - 'value' => $this->backend->type, - 'required' => true, - 'helptext' => 'The data source used for retrieving monitoring information', - 'multiOptions' => array( - 'ido' => 'IDO Backend', - 'statusdat' => 'Status.dat', - 'livestatus' => 'Livestatus' - ) - ) - ); - $this->addElement( - 'select', - 'backend_resource', - array( - 'label' => 'Resource', - 'value' => $this->backend->resource, - 'required' => true, - 'multiOptions' => $this->getResourcesByType($backendType === 'ido' ? 'db' : $backendType), - 'helptext' => 'The resource to use' - ) - ); - $this->addElement( - 'checkbox', - 'backend_disable', - array( - 'label' => 'Disable This Backend', - 'required' => true, - 'value' => $this->backend->disabled - ) - ); - - $this->enableAutoSubmit(array('backend_type')); - $this->setSubmitLabel('{{SAVE_ICON}} Save Changes'); - } - - /** - * Return a configuration containing the backend settings entered in this form - * - * @return Zend_Config The updated configuration for this backend - */ - public function getConfig() - { - $values = $this->getValues(); - return new Zend_Config( - array( - 'type' => $values['backend_type'], - 'disabled' => $values['backend_disable'], - 'resource' => $values['backend_resource'] - ) - ); - } - - /** - * Return a list of all resources of the given type ready to be used as content for a select input - * - * @param string $type The type of resources to return - * - * @return array - */ - protected function getResourcesByType($type) - { - $backends = array(); - foreach (array_keys(ResourceFactory::getResourceConfigs($type)->toArray()) as $name) { - $backends[$name] = $name; - } - - return $backends; - } -} diff --git a/modules/monitoring/application/forms/Config/BackendForm.php b/modules/monitoring/application/forms/Config/BackendForm.php new file mode 100644 index 000000000..19f870778 --- /dev/null +++ b/modules/monitoring/application/forms/Config/BackendForm.php @@ -0,0 +1,134 @@ +createElement( + 'text', + 'name', + array( + 'required' => true, + 'label' => t('Backend Name'), + 'helptext' => t('The identifier of this backend') + ) + ), + $this->createElement( + 'select', + 'type', + array( + 'required' => true, + 'class' => 'autosubmit', + 'label' => t('Backend Type'), + 'helptext' => t('The data source used for retrieving monitoring information'), + 'multiOptions' => array( + 'ido' => 'IDO Backend', + 'statusdat' => 'Status.dat', + 'livestatus' => 'Livestatus' + ) + ) + ), + $this->createElement( + 'select', + 'resource', + array( + 'required' => true, + 'label' => t('Resource'), + 'helptext' => t('The resource to use'), + 'multiOptions' => $this->getResourcesByType( + false === isset($formData['type']) || $formData['type'] === 'ido' ? 'db' : $formData['type'] + ) + ) + ), + $this->createElement( + 'checkbox', + 'disabled', + array( + 'required' => true, + 'label' => t('Disable This Backend') + ) + ) + ); + } + + /** + * @see Form::addSubmitButton() + */ + public function addSubmitButton() + { + $this->addElement( + 'submit', + 'btn_submit', + array( + 'label' => t('Save Changes') + ) + ); + + return $this; + } + + /** + * Return the backend configuration values and its name + * + * The first value is the name and the second one the values as array. + * + * @return array + */ + public function getBackendConfig() + { + $values = $this->getValues(); + $name = $values['name']; + + if ($values['disabled'] == '0') { + unset($values['disabled']); + } + + unset($values['name']); + unset($values['btn_submit']); + unset($values[$this->getTokenElementName()]); + return array($name, $values); + } + + /** + * Populate the form with the given configuration values + * + * @param string $name The name of the backend + * @param array $config The configuration values + */ + public function setBackendConfig($name, array $config) + { + $config['name'] = $name; + $this->populate($config); + } + + /** + * Return a list of all resources of the given type ready to be used as content for a select input + * + * @param string $type The type of resources to return + * + * @return array + */ + protected function getResourcesByType($type) + { + $backends = array(); + foreach (array_keys(ResourceFactory::getResourceConfigs($type)->toArray()) as $name) { + $backends[$name] = $name; + } + + return $backends; + } +}