mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
Adjust createresource-action to suit the updated resource form interface
refs #5525
This commit is contained in:
parent
936f65eb27
commit
fd912daa3d
@ -27,13 +27,6 @@ use Icinga\Config\PreservingIniWriter;
|
|||||||
*/
|
*/
|
||||||
class ConfigController extends BaseConfigController
|
class ConfigController extends BaseConfigController
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The resource types that are available.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $resourceTypes = array('livestatus', 'ido', 'statusdat', 'ldap');
|
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->view->tabs = Widget::create('tabs')->add('index', array(
|
$this->view->tabs = Widget::create('tabs')->add('index', array(
|
||||||
@ -386,28 +379,30 @@ class ConfigController extends BaseConfigController
|
|||||||
$this->view->resources = IcingaConfig::app('resources', true)->toArray();
|
$this->view->resources = IcingaConfig::app('resources', true)->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a form to create a new resource
|
||||||
|
*/
|
||||||
public function createresourceAction()
|
public function createresourceAction()
|
||||||
{
|
{
|
||||||
$this->view->resourceTypes = $this->resourceTypes;
|
$this->view->messageBox = new AlertMessageBox(true);
|
||||||
$resources = IcingaConfig::app('resources', true);
|
|
||||||
$form = new ResourceForm();
|
$form = new ResourceForm();
|
||||||
$form->setRequest($this->_request);
|
$request = $this->getRequest();
|
||||||
if ($form->isSubmittedAndValid()) {
|
if ($request->isPost() && $form->isValid($request->getPost())) {
|
||||||
$name = $form->getName();
|
list($name, $config) = $form->getResourceConfig();
|
||||||
if (isset($resources->{$name})) {
|
$resources = IcingaConfig::app('resources')->toArray();
|
||||||
$this->addErrorMessage('Resource name "' . $name .'" already in use.');
|
if (array_key_exists($name, $resources)) {
|
||||||
|
$this->addErrorMessage(sprintf($this->translate('Resource name "%s" already in use.'), $name));
|
||||||
} else {
|
} else {
|
||||||
$resources->{$name} = $form->getConfig();
|
$resources[$name] = $config;
|
||||||
if ($this->writeConfigFile($resources, 'resources')) {
|
if ($this->writeConfigFile($resources, 'resources')) {
|
||||||
$this->addSuccessMessage('Resource "' . $name . '" created.');
|
$this->addSuccessMessage(sprintf($this->translate('Resource "%s" successfully created.'), $name));
|
||||||
$this->redirectNow("config/resource");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->messageBox = new AlertMessageBox(true);
|
|
||||||
$this->view->messageBox->addForm($form);
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
|
$this->view->messageBox->addForm($form);
|
||||||
$this->render('resource/create');
|
$this->render('resource/create');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
<h4>
|
<?= $messageBox; ?>
|
||||||
<i class="icinga-icon-create"></i>
|
<h4><?= $this->translate('Create a new resource'); ?></h4>
|
||||||
Create New Resource
|
<p><?= $this->translate('Resources are entities that provide data to Icingaweb.'); ?></p>
|
||||||
</h4>
|
<?= $form; ?>
|
||||||
|
|
||||||
<?php if (isset($this->messageBox)): ?>
|
|
||||||
<?= $this->messageBox->render() ?>
|
|
||||||
<?php endif ?>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Resources are entities that provide data to Icingaweb.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<?= $this->form ?>
|
|
Loading…
x
Reference in New Issue
Block a user