mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-26 03:09:11 +02:00
TemplateChoice: work without form loader
This commit is contained in:
parent
0ec5ec8197
commit
ceebe08ecd
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Controllers;
|
namespace Icinga\Module\Director\Controllers;
|
||||||
|
|
||||||
use Icinga\Module\Director\Objects\IcingaTemplateChoiceHost;
|
use Icinga\Module\Director\Forms\IcingaTemplateChoiceForm;
|
||||||
use Icinga\Module\Director\Objects\IcingaTemplateChoiceService;
|
use Icinga\Module\Director\Objects\IcingaTemplateChoiceService;
|
||||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||||
|
|
||||||
@ -15,31 +15,21 @@ class TemplatechoiceController extends ActionController
|
|||||||
|
|
||||||
public function hostAction()
|
public function hostAction()
|
||||||
{
|
{
|
||||||
|
$form = IcingaTemplateChoiceForm::create('host', $this->db())
|
||||||
|
->optionallyLoad($this->params->get('name'))
|
||||||
|
->handleRequest();
|
||||||
$this->addSingleTab('Choice')
|
$this->addSingleTab('Choice')
|
||||||
->addTitle($this->translate('Host template choice'));
|
->addTitle($this->translate('Host template choice'))
|
||||||
$this->content()->add(
|
->content()->add($form);
|
||||||
$form = $this->loadForm('IcingaTemplateChoice')
|
|
||||||
->setDb($this->db())
|
|
||||||
->setChoiceType('host')
|
|
||||||
);
|
|
||||||
if ($name = $this->params->get('name')) {
|
|
||||||
$form->setObject(IcingaTemplateChoiceHost::load($name, $this->db()));
|
|
||||||
}
|
|
||||||
$form->handleRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serviceAction()
|
public function serviceAction()
|
||||||
{
|
{
|
||||||
|
$form = IcingaTemplateChoiceForm::create('service', $this->db())
|
||||||
|
->optionallyLoad($this->params->get('name'))
|
||||||
|
->handleRequest();
|
||||||
$this->addSingleTab('Choice')
|
$this->addSingleTab('Choice')
|
||||||
->addTitle($this->translate('Service template choice'));
|
->addTitle($this->translate('Service template choice'))
|
||||||
$this->content()->add(
|
->content()->add($form);
|
||||||
$form = $this->loadForm('IcingaTemplateChoice')
|
|
||||||
->setDb($this->db())
|
|
||||||
->setChoiceType('service')
|
|
||||||
);
|
|
||||||
if ($name = $this->params->get('name')) {
|
|
||||||
$form->setObject(IcingaTemplateChoiceService::load($name, $this->db()));
|
|
||||||
}
|
|
||||||
$form->handleRequest();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Forms;
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Objects\IcingaTemplateChoice;
|
use Icinga\Module\Director\Objects\IcingaTemplateChoice;
|
||||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||||
|
|
||||||
@ -9,6 +10,22 @@ class IcingaTemplateChoiceForm extends DirectorObjectForm
|
|||||||
{
|
{
|
||||||
private $choiceType;
|
private $choiceType;
|
||||||
|
|
||||||
|
public static function create($type, Db $db)
|
||||||
|
{
|
||||||
|
return static::load()->setDb($db)->setChoiceType($type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function optionallyLoad($name)
|
||||||
|
{
|
||||||
|
if ($name !== null) {
|
||||||
|
/** @var IcingaTemplateChoice $class - cheating IDE */
|
||||||
|
$class = $this->getObjectClassName();
|
||||||
|
$this->setObject($class::load($name, $this->getDb()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getObjectClassname()
|
protected function getObjectClassname()
|
||||||
{
|
{
|
||||||
if ($this->className === null) {
|
if ($this->className === null) {
|
||||||
@ -27,9 +44,6 @@ class IcingaTemplateChoiceForm extends DirectorObjectForm
|
|||||||
|
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
/** @var IcingaTemplateChoice $object */
|
|
||||||
$object = $this->object();
|
|
||||||
|
|
||||||
$this->addElement('text', 'object_name', array(
|
$this->addElement('text', 'object_name', array(
|
||||||
'label' => $this->translate('Choice name'),
|
'label' => $this->translate('Choice name'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
@ -17,6 +17,7 @@ use Icinga\Module\Director\Web\Table\QuickTable;
|
|||||||
use Icinga\Module\Director\Web\Table\TableLoader;
|
use Icinga\Module\Director\Web\Table\TableLoader;
|
||||||
use Icinga\Security\SecurityException;
|
use Icinga\Security\SecurityException;
|
||||||
use Icinga\Web\Controller;
|
use Icinga\Web\Controller;
|
||||||
|
use Icinga\Web\UrlParams;
|
||||||
use Icinga\Web\Widget;
|
use Icinga\Web\Widget;
|
||||||
use ipl\Web\Component\ControlsAndContent;
|
use ipl\Web\Component\ControlsAndContent;
|
||||||
use ipl\Web\Controller\Extension\ControlsAndContentHelper;
|
use ipl\Web\Controller\Extension\ControlsAndContentHelper;
|
||||||
@ -31,6 +32,9 @@ abstract class ActionController extends Controller implements ControlsAndContent
|
|||||||
|
|
||||||
protected $isApified = false;
|
protected $isApified = false;
|
||||||
|
|
||||||
|
/** @var UrlParams Hint for IDE, somehow does not work in web */
|
||||||
|
protected $params;
|
||||||
|
|
||||||
/** @var Monitoring */
|
/** @var Monitoring */
|
||||||
private $monitoring;
|
private $monitoring;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Icinga\Module\Director\Web\Form;
|
namespace Icinga\Module\Director\Web\Form;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Authentication\Auth;
|
use Icinga\Authentication\Auth;
|
||||||
use Icinga\Module\Director\Core\CoreApi;
|
use Icinga\Module\Director\Core\CoreApi;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
@ -13,7 +14,6 @@ use Icinga\Module\Director\IcingaConfig\StateFilterSet;
|
|||||||
use Icinga\Module\Director\IcingaConfig\TypeFilterSet;
|
use Icinga\Module\Director\IcingaConfig\TypeFilterSet;
|
||||||
use Icinga\Module\Director\Objects\IcingaTemplateChoiceHost;
|
use Icinga\Module\Director\Objects\IcingaTemplateChoiceHost;
|
||||||
use Icinga\Module\Director\Objects\IcingaObject;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
use Icinga\Module\Director\Restriction\ObjectRestriction;
|
|
||||||
use Icinga\Module\Director\Util;
|
use Icinga\Module\Director\Util;
|
||||||
use Zend_Form_Element as ZfElement;
|
use Zend_Form_Element as ZfElement;
|
||||||
use Zend_Form_Element_Select as ZfSelect;
|
use Zend_Form_Element_Select as ZfSelect;
|
||||||
@ -70,6 +70,16 @@ abstract class DirectorObjectForm extends QuickForm
|
|||||||
'event_command_id',
|
'event_command_id',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function load()
|
||||||
|
{
|
||||||
|
return new static([
|
||||||
|
'icingaModule' => Icinga::App()->getModuleManager()->getModule('director')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function setPreferredObjectType($type)
|
public function setPreferredObjectType($type)
|
||||||
{
|
{
|
||||||
$this->preferredObjectType = $type;
|
$this->preferredObjectType = $type;
|
||||||
|
@ -197,7 +197,7 @@ abstract class QuickForm extends QuickBaseForm
|
|||||||
|
|
||||||
public function isApiRequest()
|
public function isApiRequest()
|
||||||
{
|
{
|
||||||
return $this->isApiRequest;
|
return $this->isApiRequest || $this->getRequest()->isApiRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function regenerateCsrfToken()
|
public function regenerateCsrfToken()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user