Adjust editresource-action to suit the new resource form interface
refs #5525
This commit is contained in:
parent
9c434fe8bf
commit
0964316df4
|
@ -406,41 +406,44 @@ class ConfigController extends BaseConfigController
|
|||
$this->render('resource/create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a form to edit a existing resource
|
||||
*/
|
||||
public function editresourceAction()
|
||||
{
|
||||
$this->view->messageBox = new AlertMessageBox(true);
|
||||
|
||||
$resources = ResourceFactory::getResourceConfigs();
|
||||
$name = $this->getParam('resource');
|
||||
if ($resources->get($name) === null) {
|
||||
$this->addErrorMessage('Can\'t edit: Unknown Resource Provided');
|
||||
$this->render('resource/modify');
|
||||
return;
|
||||
}
|
||||
$form = new ResourceForm();
|
||||
if ($this->_request->isPost() === false) {
|
||||
$form->setOldName($name);
|
||||
$form->setName($name);
|
||||
}
|
||||
$form->setRequest($this->_request);
|
||||
$form->setResource($resources->get($name));
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
$oldName = $form->getOldName();
|
||||
$name = $form->getName();
|
||||
if ($oldName !== $name) {
|
||||
unset($resources->{$oldName});
|
||||
}
|
||||
$resources->{$name} = $form->getConfig();
|
||||
if ($this->writeConfigFile($resources, 'resources')) {
|
||||
$this->addSuccessMessage('Resource "' . $name . '" edited.');
|
||||
$this->redirectNow("config/resource");
|
||||
}
|
||||
return;
|
||||
// Fetch the resource to be edited
|
||||
$resources = IcingaConfig::app('resources')->toArray();
|
||||
$name = $this->getParam('resource');
|
||||
if (false === array_key_exists($name, $resources)) {
|
||||
$this->addErrorMessage(sprintf($this->translate('Cannot edit "%s". Resource not found.'), $name));
|
||||
$this->redirectNow('config/configurationerror');
|
||||
}
|
||||
|
||||
$form = new ResourceForm();
|
||||
$request = $this->getRequest();
|
||||
if ($request->isPost()) {
|
||||
if ($form->isValid($request->getPost())) {
|
||||
list($newName, $config) = $form->getResourceConfig();
|
||||
|
||||
if ($newName !== $name) {
|
||||
// Resource name has changed
|
||||
unset($resources[$name]); // We can safely use unset as all values are part of the form
|
||||
}
|
||||
|
||||
$resources[$newName] = $config;
|
||||
if ($this->writeConfigFile($resources, 'resources')) {
|
||||
$this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully edited.'), $name));
|
||||
$this->redirectNow('config/resource');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$form->setResourceConfig($name, $resources[$name]);
|
||||
}
|
||||
|
||||
$this->view->messageBox->addForm($form);
|
||||
$this->view->form = $form;
|
||||
$this->view->name = $name;
|
||||
$this->view->messageBox->addForm($form);
|
||||
$this->render('resource/modify');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,3 @@
|
|||
<h4>
|
||||
<i class="icinga-icon-edit"></i>
|
||||
Edit Resource "<?= $this->escape($this->name); ?>"
|
||||
</h4>
|
||||
|
||||
<?php if (isset($this->messageBox)): ?>
|
||||
<?= $this->messageBox->render() ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($this->form->getErrorMessages()): ?>
|
||||
<div>
|
||||
<?php foreach ($this->form->getErrorMessages() as $error): ?>
|
||||
<?= $this->escape($error); ?><br/>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $this->form ?>
|
||||
<h4><?= $this->translate('Edit Existing Resource'); ?></h4>
|
||||
<?= $messageBox; ?>
|
||||
<?= $form; ?>
|
Loading…
Reference in New Issue