IcingaHostForm: just a lame form field

This commit is contained in:
Thomas Gelf 2016-03-22 02:02:25 +01:00
parent 4ce7bf3663
commit 5faf7c8612
3 changed files with 55 additions and 2 deletions

View File

@ -25,6 +25,13 @@ class IcingaHostForm extends DirectorObjectForm
)
));
if ($this->isNew() && $this->isObject() && $this->allowsExperimental()) {
$this->addBoolean('create_live', array(
'label' => $this->translate('Create immediately'),
'ignore' => true,
), 'n');
}
$this->addGroupsElement()
->addImportsElement()
->addDisplayNameElement()
@ -77,6 +84,16 @@ class IcingaHostForm extends DirectorObjectForm
->setButtons();
}
protected function beforeSuccessfulRedirect()
{
if ($this->allowsExperimental() && $this->getSentValue('create_live') === 'y') {
$host = $this->getObject();
if ($this->api()->createObjectAtRuntime($host)) {
$this->api()->checkHostNow($host->object_name);
}
}
}
protected function addGroupsElement()
{
$groups = $this->enumHostgroups();

View File

@ -143,7 +143,9 @@ abstract class ObjectController extends ActionController
$type = ucfirst($ltype);
$formName = 'icinga' . $type;
$this->view->form = $form = $this->loadForm($formName)->setDb($this->db());
$this->view->form = $form = $this->loadForm($formName)
->setDb($this->db())
->setApi($this->api());
$form->setObject($object);
$this->view->title = $object->object_name;
@ -172,6 +174,7 @@ abstract class ObjectController extends ActionController
$url = sprintf('director/%ss', $ltype);
$form = $this->view->form = $this->loadForm('icinga' . ucfirst($type))
->setDb($this->db())
->setApi($this->api())
->setSuccessUrl($url);
$this->view->title = sprintf(

View File

@ -27,6 +27,10 @@ abstract class DirectorObjectForm extends QuickForm
protected $resolvedImports = false;
private $allowsExperimental;
private $api;
protected function object($values = array())
{
if ($this->object === null) {
@ -465,6 +469,7 @@ abstract class DirectorObjectForm extends QuickForm
'email',
'pager',
'enable_notifications',
'create_live',
'disabled',
);
@ -603,10 +608,14 @@ abstract class DirectorObjectForm extends QuickForm
$object->getUrlParams()
);
}
$this->beforeSuccessfulRedirect();
$this->redirectOnSuccess($msg);
}
protected function beforeSuccessfulRedirect()
{
}
protected function addBoolean($key, $options, $default = null)
{
$map = array(
@ -1243,6 +1252,19 @@ abstract class DirectorObjectForm extends QuickForm
return $this;
}
protected function allowsExperimental()
{
// NO, it is NOT a good idea to use this. You'll break your monitoring
// and nobody will help you.
if ($this->allowsExperimental === null) {
$this->allowsExperimental = $this->db->getSetting(
'experimental_features'
) === 'allow';
}
return $this->allowsExperimental;
}
protected function enumStates()
{
$set = new StateFilterSet();
@ -1255,6 +1277,17 @@ abstract class DirectorObjectForm extends QuickForm
return $set->enumAllowedValues();
}
public function setApi($api)
{
$this->api = $api;
return $this;
}
protected function api()
{
return $this->api;
}
private function dummyForTranslation()
{
$this->translate('Host');