Merge branch 'master' of git.icinga.org:icingaweb2-module-director

This commit is contained in:
Alexander Fuhr 2015-07-02 16:08:15 +02:00
commit dccdd862a3
5 changed files with 82 additions and 2 deletions

View File

@ -24,7 +24,12 @@ class FormLoader
if (file_exists($file)) {
require_once($file);
$class = $ns . $class;
return new $class();
$options = array();
if ($module !== null) {
$options['icingaModule'] = $module;
}
return new $class($options);
}
}
throw new ProgrammingError(sprintf('Cannot load %s (%s), no such form', $name, $file));

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Web\Form;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Web\Notification;
use Icinga\Web\Request;
use Icinga\Web\Url;
@ -48,8 +49,18 @@ abstract class QuickForm extends Zend_Form
protected $submitLabel;
/**
* The Icinga module this form belongs to. Usually only set if the
* form is initialized through the FormLoader
*/
protected $icingaModule;
public function __construct($options = null)
{
if (array_key_exists('icingaModule', $options)) {
$this->icingaModule = $options['icingaModule'];
unset($options['icingaModule']);
}
parent::__construct($options);
$this->setMethod('post');
$this->setAction(Url::fromRequest());
@ -89,6 +100,15 @@ abstract class QuickForm extends Zend_Form
return $this;
}
protected function loadForm($name, Module $module = null)
{
if ($module === null) {
$module = $this->icingaModule;
}
return FormLoader::load($name, $module);
}
public function regenerateCsrfToken()
{
if (! $element = $this->getElement(self::CSRF)) {
@ -137,6 +157,12 @@ abstract class QuickForm extends Zend_Form
return parent::setAction((string) $action);
}
public function setIcingaModule(Module $module)
{
$this->icingaModule = $module;
return $this;
}
public function hasBeenSubmitted()
{
if ($this->hasBeenSubmitted === null) {

View File

@ -0,0 +1,33 @@
<?php
namespace Icinga\Module\Director\Web;
use Icinga\Application\Config;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Monitoring\Web\Hook\HostActionsHook;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Web\Url;
class HostActions extends HostActionsHook
{
public function getActionsForHost(Host $host)
{
$db = $this->db();
if (IcingaHost::exists($host->host_name, $db)) {
return array(
'Modify' => Url::fromPath(
'director/host/edit',
array('name' => $host->host_name)
)
);
} else {
return array();
}
}
protected function db()
{
return Db::fromResourceName(Config::module('director')->get('db', 'resource'));
}
}

View File

@ -3,9 +3,21 @@ form dt label {
width: auto;
}
dd {
form dd {
display: inline;
margin: 0;
}
form dt {
display: inline-block;
min-width: 16em;
}
form dd:after {
display: block;
content: '';
}
/* END of Forms */
table.simple {

4
run.php Normal file
View File

@ -0,0 +1,4 @@
<?php
$this->registerHook('Monitoring\\HostActions', '\\Icinga\\Module\\Director\\Web\\HostActions');