Add config tab to the module to manage the db resource

resolves #9486
This commit is contained in:
Alexander Fuhr 2015-06-29 15:40:24 +02:00
parent 321f9d9503
commit 18b201d824
3 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,50 @@
<?php
use Icinga\Module\Director\ActionController;
use Icinga\Forms\ConfigForm;
use Icinga\Data\ResourceFactory;
class Director_SettingsController extends ActionController
{
public function indexAction()
{
$this->view->tabs = $this->Module()->getConfigTabs()->activate('config');
$resource = $this->Config()->get('db', 'resource');
$form = new ConfigForm();
$form->setIniConfig($this->Config('config'));
$form->addElement('select', 'resource', array(
'required' => true,
'label' => $this->translate('DB Resource'),
'multiOptions' => $this->getResources(),
'value' => $resource
));
$form->setSubmitLabel($this->translate('Save'));
$form->setOnSuccess(function($form) {
/** @var $form ConfigForm */
$this->Config('config')->setSection('db', array(
'resource' => $form->getValue('resource')
));
$form->save();
});
$form->handleRequest();
$this->view->form = $form;
}
public function getResources()
{
$resources = array();
foreach (ResourceFactory::getResourceConfigs() as $name => $resource) {
if ($resource->type === 'db') {
$resources['ido'][$name] = $name;
}
}
return $resources;
}
}

View file

@ -0,0 +1,7 @@
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content" data-base-target="_next">
<?= $form; ?>
</div>

View file

@ -3,6 +3,11 @@
// Sample permission:
$this->providePermission('director/templates', 'Allow to modify templates');
$this->provideConfigTab('config', array(
'title' => 'Configuration',
'url' => 'settings'
));
$section = $this->menuSection(
$this->translate('Icinga Director')
)->setIcon('cubes');