IcingaServiceForm: improve apply handling

This commit is contained in:
Thomas Gelf 2016-05-25 08:14:00 +02:00
parent d1af897114
commit 2f60385555
2 changed files with 19 additions and 16 deletions

View File

@ -67,15 +67,6 @@ class ServiceController extends ObjectController
$this->translate('Apply "%s"'), $this->translate('Apply "%s"'),
$this->apply->object_name $this->apply->object_name
); );
$form = $this->view->form;
if (!$form->hasBeenSent()) {
$form->populate(array(
'imports' => $this->apply->object_name,
'object_name' => $this->apply->object_name,
'object_type' => 'apply',
));
}
} }
} }
@ -83,12 +74,7 @@ class ServiceController extends ObjectController
{ {
if ($this->apply) { if ($this->apply) {
if (!$form->hasBeenSent()) { if (!$form->hasBeenSent()) {
$form->populate(array( $form->createApplyRuleFor($this->apply);
'imports' => $this->apply->object_name,
'object_name' => $this->apply->object_name,
'object_type' => 'apply',
));
$form->getObject()->object_type = 'apply';
} }
} }
} }

View File

@ -4,11 +4,14 @@ namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm; use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
class IcingaServiceForm extends DirectorObjectForm class IcingaServiceForm extends DirectorObjectForm
{ {
private $host; private $host;
private $apply;
public function setup() public function setup()
{ {
if (!$this->isNew() && $this->host === null) { if (!$this->isNew() && $this->host === null) {
@ -22,9 +25,23 @@ class IcingaServiceForm extends DirectorObjectForm
} }
} }
public function createApplyRuleFor(IcingaService $service)
{
$this->apply = $service;
$object = $this->object();
$object->imports = $service->object_name;
$object->object_type = 'apply';
$object->object_name = $service->object_name;
return $this;
}
protected function setupServiceElements() protected function setupServiceElements()
{ {
if ($this->object) {
$this->addHidden('object_type', $this->object->object_type);
} else {
$this->addHidden('object_type', 'template'); $this->addHidden('object_type', 'template');
}
$this->addNameElement() $this->addNameElement()
->addHostObjectElement() ->addHostObjectElement()