IcingaServiceSetForm: restructure the form
This commit is contained in:
parent
7f34e4bdf3
commit
5de24c6ec4
|
@ -12,8 +12,36 @@ class IcingaServiceSetForm extends DirectorObjectForm
|
||||||
|
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
$this->addImportsElement();
|
if ($this->host === null) {
|
||||||
|
$this->setupTemplate();
|
||||||
|
} else {
|
||||||
|
$this->setupHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setupFields()
|
||||||
|
->setButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setupFields()
|
||||||
|
{
|
||||||
|
$object = $this->object();
|
||||||
|
|
||||||
|
$this->assertResolvedImports();
|
||||||
|
|
||||||
|
if ($this->hasBeenSent() && $services = $this->getSentValue('service')) {
|
||||||
|
$object->service = $services;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->assertResolvedImports()) {
|
||||||
|
$this->fieldLoader($object)
|
||||||
|
->loadFieldsForMultipleObjects($object->getServiceObjects());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setupTemplate()
|
||||||
|
{
|
||||||
$this->addElement('text', 'object_name', array(
|
$this->addElement('text', 'object_name', array(
|
||||||
'label' => $this->translate('Service set name'),
|
'label' => $this->translate('Service set name'),
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
|
@ -22,19 +50,8 @@ class IcingaServiceSetForm extends DirectorObjectForm
|
||||||
'required' => true,
|
'required' => true,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->addElement('textarea', 'description', array(
|
$this->addHidden('object_type', 'template');
|
||||||
'label' => $this->translate('Description'),
|
$this->addDescriptionElement();
|
||||||
'description' => $this->translate(
|
|
||||||
'A meaningful description explaining your users what to expect'
|
|
||||||
. ' when assigning this set of services'
|
|
||||||
),
|
|
||||||
'rows' => '3',
|
|
||||||
'required' => ! $this->isTemplate(),
|
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
if ($this->host === null) {
|
|
||||||
$this->addHidden('object_type', 'object');
|
|
||||||
|
|
||||||
$this->addElement('multiselect', 'service', array(
|
$this->addElement('multiselect', 'service', array(
|
||||||
'label' => $this->translate('Services'),
|
'label' => $this->translate('Services'),
|
||||||
|
@ -46,32 +63,67 @@ class IcingaServiceSetForm extends DirectorObjectForm
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'class' => 'autosubmit',
|
'class' => 'autosubmit',
|
||||||
));
|
));
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
protected function setupHost()
|
||||||
|
{
|
||||||
|
$object = $this->object();
|
||||||
|
if ($this->hasBeenSent()) {
|
||||||
|
$object->object_name = $object->imports = $this->getSentValue('imports');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $object->hasBeenLoadedFromDb()) {
|
||||||
|
$this->addSingleImportsElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($object->imports)) {
|
||||||
|
$this->addHtmlHint(
|
||||||
|
$this->getView()->escape(
|
||||||
|
$object->getResolvedProperty('description')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$this->addHidden('object_type', 'object');
|
$this->addHidden('object_type', 'object');
|
||||||
$this->addHidden('host_id', $this->host->id);
|
$this->addHidden('host_id', $this->host->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$services = array();
|
|
||||||
foreach ($this->getSentOrObjectValue('service') as $name) {
|
|
||||||
$services[] = IcingaService::load(array(
|
|
||||||
'object_name' => $name,
|
|
||||||
'object_type' => 'template'
|
|
||||||
), $this->db);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->assertResolvedImports()) {
|
|
||||||
$loader = $this->fieldLoader($this->object);
|
|
||||||
$loader->loadFieldsForMultipleObjects($services);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHost(IcingaHost $host)
|
public function setHost(IcingaHost $host)
|
||||||
{
|
{
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
protected function addSingleImportsElement()
|
||||||
|
{
|
||||||
|
$enum = $this->enumAllowedTemplates();
|
||||||
|
|
||||||
|
$this->addElement('select', 'imports', array(
|
||||||
|
'label' => $this->translate('Service set'),
|
||||||
|
'description' => $this->translate(
|
||||||
|
'The service set that should be assigned to this host'
|
||||||
|
),
|
||||||
|
'required' => true,
|
||||||
|
'multiOptions' => $this->optionallyAddFromEnum($enum),
|
||||||
|
'class' => 'autosubmit'
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addDescriptionElement()
|
||||||
|
{
|
||||||
|
$this->addElement('textarea', 'description', array(
|
||||||
|
'label' => $this->translate('Description'),
|
||||||
|
'description' => $this->translate(
|
||||||
|
'A meaningful description explaining your users what to expect'
|
||||||
|
. ' when assigning this set of services'
|
||||||
|
),
|
||||||
|
'rows' => '3',
|
||||||
|
'required' => ! $this->isTemplate(),
|
||||||
|
));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function enumServices()
|
protected function enumServices()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue