mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
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:
parent
a78d11345b
commit
d7ed6bd249
@ -7,8 +7,8 @@ use \Zend_Config;
|
|||||||
use Icinga\Config\PreservingIniWriter;
|
use Icinga\Config\PreservingIniWriter;
|
||||||
use Icinga\Web\Controller\ModuleActionController;
|
use Icinga\Web\Controller\ModuleActionController;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
use Icinga\Form\Config\ConfirmRemovalForm;
|
||||||
use Icinga\Module\Monitoring\Form\Config\BackendForm;
|
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\EditInstanceForm;
|
||||||
use Icinga\Module\Monitoring\Form\Config\Instance\CreateInstanceForm;
|
use Icinga\Module\Monitoring\Form\Config\Instance\CreateInstanceForm;
|
||||||
use Icinga\Exception\NotReadableError;
|
use Icinga\Exception\NotReadableError;
|
||||||
@ -107,29 +107,26 @@ class Monitoring_ConfigController extends ModuleActionController
|
|||||||
public function removebackendAction()
|
public function removebackendAction()
|
||||||
{
|
{
|
||||||
$backend = $this->getParam('backend');
|
$backend = $this->getParam('backend');
|
||||||
if (!$this->isExistingBackend($backend)) {
|
$backendsConfig = $this->Config('backends')->toArray();
|
||||||
$this->view->error = 'Unknown backend ' . $backend;
|
if (false === array_key_exists($backend, $backendsConfig)) {
|
||||||
return;
|
// 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 = new ConfirmRemovalForm();
|
||||||
$form->setRequest($this->getRequest());
|
$request = $this->getRequest();
|
||||||
$form->setRemoveTarget('backend', $backend);
|
if ($request->isPost() && $form->isValid($request->getPost())) {
|
||||||
|
unset($backendsConfig[$backend]);
|
||||||
if ($form->isSubmittedAndValid()) {
|
if ($this->writeConfiguration($backendsConfig, 'backends')) {
|
||||||
$configArray = $this->Config('backends')->toArray();
|
Notification::success(sprintf($this->translate('Backend "%s" successfully removed.'), $backend));
|
||||||
unset($configArray[$backend]);
|
|
||||||
|
|
||||||
if ($this->writeConfiguration(new Zend_Config($configArray), 'backends')) {
|
|
||||||
Notification::success('Backend "' . $backend . '" Removed');
|
|
||||||
$this->redirectNow('monitoring/config');
|
$this->redirectNow('monitoring/config');
|
||||||
} else {
|
} else {
|
||||||
$this->render('show-configuration');
|
$this->render('show-configuration');
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
$this->view->name = $backend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,2 @@
|
|||||||
|
<h4><?= $this->translate('Remove Existing Backend'); ?></h4>
|
||||||
<h4><i class="icinga-icon-remove"></i> Remove Backend "<?= $this->escape($this->name) ?>"</h4>
|
<?= $form; ?>
|
||||||
|
|
||||||
<p>
|
|
||||||
Are you sure you want to remove the backend <?= $this->escape($this->name) ?>?
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<?= $this->form; ?>
|
|
Loading…
x
Reference in New Issue
Block a user