2016-10-13 11:13:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
2016-10-20 06:29:23 +02:00
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
2016-10-13 11:13:21 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|
|
|
|
|
|
|
class IcingaServiceSetForm extends DirectorObjectForm
|
|
|
|
{
|
|
|
|
protected $host;
|
|
|
|
|
2016-11-08 22:11:53 +01:00
|
|
|
protected $listUrl = 'director/services/sets';
|
|
|
|
|
2016-10-13 11:13:21 +02:00
|
|
|
public function setup()
|
|
|
|
{
|
2016-10-20 09:22:56 +02:00
|
|
|
if ($this->host === null) {
|
|
|
|
$this->setupTemplate();
|
|
|
|
} else {
|
|
|
|
$this->setupHost();
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:51:58 +02:00
|
|
|
$this->setButtons();
|
2016-10-20 09:22:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function setupTemplate()
|
|
|
|
{
|
2017-12-12 15:49:22 +01:00
|
|
|
$this->addElement('text', 'object_name', [
|
2016-10-13 11:13:21 +02:00
|
|
|
'label' => $this->translate('Service set name'),
|
|
|
|
'description' => $this->translate(
|
2016-10-20 04:56:19 +02:00
|
|
|
'A short name identifying this set of services'
|
2016-10-13 11:13:21 +02:00
|
|
|
),
|
|
|
|
'required' => true,
|
2017-12-12 15:49:22 +01:00
|
|
|
])
|
|
|
|
->eventuallyAddNameRestriction('director/service_set/filter-by-name')
|
|
|
|
->addHidden('object_type', 'template')
|
|
|
|
->addDescriptionElement()
|
|
|
|
->addAssignmentElements();
|
2016-10-20 09:22:56 +02:00
|
|
|
}
|
2016-10-13 11:13:21 +02:00
|
|
|
|
2017-02-17 16:35:13 +01:00
|
|
|
protected function setObjectSuccessUrl()
|
|
|
|
{
|
|
|
|
if ($this->host) {
|
|
|
|
$this->setSuccessUrl(
|
|
|
|
'director/host/services',
|
|
|
|
array('name' => $this->host->getObjectName())
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
parent::setObjectSuccessUrl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 09:22:56 +02:00
|
|
|
protected function setupHost()
|
|
|
|
{
|
2017-01-13 19:47:54 +01:00
|
|
|
$object = $this->object();
|
2016-10-20 09:22:56 +02:00
|
|
|
if ($this->hasBeenSent()) {
|
2016-12-16 13:33:54 +01:00
|
|
|
$object->set('object_name', $this->getSentValue('imports'));
|
|
|
|
$object->set('imports', $object->object_name);
|
2016-10-13 11:13:21 +02:00
|
|
|
}
|
|
|
|
|
2016-10-20 09:22:56 +02:00
|
|
|
if (! $object->hasBeenLoadedFromDb()) {
|
|
|
|
$this->addSingleImportsElement();
|
2016-10-20 06:29:23 +02:00
|
|
|
}
|
|
|
|
|
2016-12-16 13:33:54 +01:00
|
|
|
if (count($object->get('imports'))) {
|
2018-05-04 08:43:15 +02:00
|
|
|
$description = $object->getResolvedProperty('description');
|
|
|
|
if ($description) {
|
|
|
|
$this->addHtmlHint($description);
|
|
|
|
}
|
2016-10-20 06:29:23 +02:00
|
|
|
}
|
|
|
|
|
2016-10-20 09:22:56 +02:00
|
|
|
$this->addHidden('object_type', 'object');
|
|
|
|
$this->addHidden('host_id', $this->host->id);
|
2016-10-13 11:13:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setHost(IcingaHost $host)
|
|
|
|
{
|
|
|
|
$this->host = $host;
|
|
|
|
return $this;
|
|
|
|
}
|
2016-10-20 09:22:56 +02:00
|
|
|
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;
|
|
|
|
}
|
2016-10-13 11:13:21 +02:00
|
|
|
|
2016-10-26 01:01:18 +02:00
|
|
|
protected function addAssignmentElements()
|
2016-10-13 11:13:21 +02:00
|
|
|
{
|
2017-10-12 16:26:50 +02:00
|
|
|
if (! $this->hasPermission('director/service_set/apply')) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-10-12 14:56:13 +02:00
|
|
|
$this->addAssignFilter([
|
|
|
|
'suggestionContext' => 'HostFilterColumns',
|
2016-10-26 01:01:18 +02:00
|
|
|
'description' => $this->translate(
|
|
|
|
'This allows you to configure an assignment filter. Please feel'
|
|
|
|
. ' free to combine as many nested operators as you want. You'
|
|
|
|
. ' might also want to skip this, define it later and/or just'
|
2019-07-08 14:11:53 +02:00
|
|
|
. ' add this set of services to single hosts. The "contains"'
|
|
|
|
. ' operator is valid for arrays only. Please use wildcards and'
|
|
|
|
. ' the = (equals) operator when searching for partial string'
|
|
|
|
. ' matches, like in *.example.com'
|
2016-10-26 01:01:18 +02:00
|
|
|
)
|
2017-10-12 14:56:13 +02:00
|
|
|
]);
|
2016-10-26 01:01:18 +02:00
|
|
|
|
|
|
|
return $this;
|
2016-10-13 11:13:21 +02:00
|
|
|
}
|
|
|
|
}
|