mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-23 22:04:27 +02:00
IcingaServiceForm: show reduced form when host...
...object is passed to the form. Makes work with forms easier
This commit is contained in:
parent
d71585ad59
commit
da175ff3cd
@ -3,25 +3,35 @@
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
|
||||
class IcingaServiceForm extends DirectorObjectForm
|
||||
{
|
||||
private $host;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
if (!$this->isNew() && $this->host === null) {
|
||||
$this->host = $this->object->getResolvedRelated('host');
|
||||
}
|
||||
|
||||
if ($this->host === null) {
|
||||
$this->setupServiceElements();
|
||||
} else {
|
||||
$this->setupHostRelatedElements();
|
||||
}
|
||||
}
|
||||
|
||||
protected function setupServiceElements()
|
||||
{
|
||||
$this->addObjectTypeElement();
|
||||
if (! $this->hasObjectType()) {
|
||||
return $this->groupMainProperties();
|
||||
}
|
||||
|
||||
$this->addElement('text', 'object_name', array(
|
||||
'label' => $this->translate('Name'),
|
||||
'required' => true,
|
||||
'description' => $this->translate(
|
||||
'Name for the Icinga object you are going to create'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addHostObjectElement()
|
||||
$this->addNameElement()
|
||||
->addHostObjectElement()
|
||||
->addImportsElement()
|
||||
->addGroupsElement()
|
||||
->addDisabledElement()
|
||||
@ -32,6 +42,51 @@ class IcingaServiceForm extends DirectorObjectForm
|
||||
->setButtons();
|
||||
}
|
||||
|
||||
protected function setupHostRelatedElements()
|
||||
{
|
||||
$this->addHidden('host_id', $this->host->id);
|
||||
$this->addHidden('object_type', 'object');
|
||||
$this->addImportsElement();
|
||||
$imports = $this->getSentOrObjectValue('imports');
|
||||
if (empty($imports)) {
|
||||
return $this->groupMainProperties();
|
||||
}
|
||||
|
||||
$this->addNameElement()
|
||||
->addDisabledElement()
|
||||
->groupMainProperties()
|
||||
->addCheckCommandElements()
|
||||
->setButtons();
|
||||
|
||||
if ($this->hasBeenSent()) {
|
||||
$name = $this->getValue('object_name');
|
||||
if (!strlen($name)) {
|
||||
$this->setElementValue('object_name', end($imports));
|
||||
$this->object->object_name = end($imports);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setHost(IcingaHost $host)
|
||||
{
|
||||
$this->host = $host;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function addNameElement()
|
||||
{
|
||||
$this->addElement('text', 'object_name', array(
|
||||
'label' => $this->translate('Name'),
|
||||
'required' => true,
|
||||
'description' => $this->translate(
|
||||
'Name for the Icinga service you are going to create'
|
||||
)
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
protected function addHostObjectElement()
|
||||
{
|
||||
if ($this->isObject()) {
|
||||
@ -73,7 +128,7 @@ class IcingaServiceForm extends DirectorObjectForm
|
||||
|
||||
protected function addAgentAndZoneElements()
|
||||
{
|
||||
if ($this->isTemplate()) {
|
||||
if (!$this->isTemplate()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user