Adjust removebackend-action to suit the new backend form interface

Drops additionally the ConfirmRemovalForm of the monitoring module
as there is already one in icingaweb2's form-set.

refs #5525
This commit is contained in:
Johannes Meyer 2014-07-25 16:00:38 +02:00
parent a78d11345b
commit d7ed6bd249
3 changed files with 14 additions and 91 deletions

View File

@ -7,8 +7,8 @@ use \Zend_Config;
use Icinga\Config\PreservingIniWriter;
use Icinga\Web\Controller\ModuleActionController;
use Icinga\Web\Notification;
use Icinga\Form\Config\ConfirmRemovalForm;
use Icinga\Module\Monitoring\Form\Config\BackendForm;
use Icinga\Module\Monitoring\Form\Config\ConfirmRemovalForm;
use Icinga\Module\Monitoring\Form\Config\Instance\EditInstanceForm;
use Icinga\Module\Monitoring\Form\Config\Instance\CreateInstanceForm;
use Icinga\Exception\NotReadableError;
@ -107,29 +107,26 @@ class Monitoring_ConfigController extends ModuleActionController
public function removebackendAction()
{
$backend = $this->getParam('backend');
if (!$this->isExistingBackend($backend)) {
$this->view->error = 'Unknown backend ' . $backend;
return;
$backendsConfig = $this->Config('backends')->toArray();
if (false === array_key_exists($backend, $backendsConfig)) {
// TODO: Should behave as in the app's config controller (Specific redirect to an error action)
Notification::error(sprintf($this->translate('Cannot remove "%s". Backend not found.'), $backend));
$this->redirectNow('monitoring/config');
}
$form = new ConfirmRemovalForm();
$form->setRequest($this->getRequest());
$form->setRemoveTarget('backend', $backend);
if ($form->isSubmittedAndValid()) {
$configArray = $this->Config('backends')->toArray();
unset($configArray[$backend]);
if ($this->writeConfiguration(new Zend_Config($configArray), 'backends')) {
Notification::success('Backend "' . $backend . '" Removed');
$request = $this->getRequest();
if ($request->isPost() && $form->isValid($request->getPost())) {
unset($backendsConfig[$backend]);
if ($this->writeConfiguration($backendsConfig, 'backends')) {
Notification::success(sprintf($this->translate('Backend "%s" successfully removed.'), $backend));
$this->redirectNow('monitoring/config');
} else {
$this->render('show-configuration');
}
return;
}
$this->view->form = $form;
$this->view->name = $backend;
}
/**

View File

@ -1,68 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Config;
use Icinga\Web\Form;
/**
* Form for confirming removal of an object
*/
class ConfirmRemovalForm extends Form
{
/**
* The value of the target to remove
*
* @var string
*/
private $removeTarget;
/**
* The name of the target parameter to remove
*
* @var string
*/
private $targetName;
/**
* Set the remove target in this field to be a hidden field with $name and value $target
*
* @param string $name The name to be set in the hidden field
* @param string $target The value to be set in the hidden field
*/
public function setRemoveTarget($name, $target)
{
$this->targetName = $name;
$this->removeTarget = $target;
}
/**
* Create the confirmation form
*
* @see Form::create()
*/
public function create()
{
$this->addElement(
'hidden',
$this->targetName,
array(
'value' => $this->removeTarget,
'required' => true
)
);
$this->addElement(
'button',
'btn_submit',
array(
'type' => 'submit',
'escape' => false,
'value' => '1',
'class' => 'btn btn-cta btn-common',
'label' => $this->getView()->icon('remove.png') . ' Confirm Removal'
)
);
}
}

View File

@ -1,8 +1,2 @@
<h4><i class="icinga-icon-remove"></i> Remove Backend "<?= $this->escape($this->name) ?>"</h4>
<p>
Are you sure you want to remove the backend <?= $this->escape($this->name) ?>?
</p>
<?= $this->form; ?>
<h4><?= $this->translate('Remove Existing Backend'); ?></h4>
<?= $form; ?>