parent
657d6a958f
commit
3ffacc70b6
|
@ -3,7 +3,6 @@
|
||||||
namespace Icinga\Module\Director\Forms;
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
use dipl\Html\Icon;
|
use dipl\Html\Icon;
|
||||||
use dipl\Web\Url;
|
|
||||||
use Icinga\Module\Director\Web\Form\DirectorForm;
|
use Icinga\Module\Director\Web\Form\DirectorForm;
|
||||||
|
|
||||||
class RemoveLinkForm extends DirectorForm
|
class RemoveLinkForm extends DirectorForm
|
||||||
|
@ -12,10 +11,13 @@ class RemoveLinkForm extends DirectorForm
|
||||||
|
|
||||||
private $title;
|
private $title;
|
||||||
|
|
||||||
|
private $onSuccessAction;
|
||||||
|
|
||||||
public function __construct($label, $title, $action, $params = [])
|
public function __construct($label, $title, $action, $params = [])
|
||||||
{
|
{
|
||||||
parent::__construct([
|
parent::__construct([
|
||||||
'style' => 'float: right'
|
'style' => 'float: right',
|
||||||
|
'data-base-target' => '_self'
|
||||||
]);
|
]);
|
||||||
$this->label = $label;
|
$this->label = $label;
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
|
@ -25,24 +27,31 @@ class RemoveLinkForm extends DirectorForm
|
||||||
$this->setAction($action);
|
$this->setAction($action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function runOnSuccess($action)
|
||||||
|
{
|
||||||
|
$this->onSuccessAction = $action;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
$this->setAttrib('class', 'inline');
|
$this->setAttrib('class', 'inline');
|
||||||
//$this->setDecorators(['Form', 'FormElements']);
|
|
||||||
// 'class' => 'icon-cancel',
|
|
||||||
// 'style' => 'float: right; font-weight: normal',
|
|
||||||
// 'title' => $this->translate('Remove this set from this host')
|
|
||||||
|
|
||||||
$this->addHtml(Icon::create('cancel'));
|
$this->addHtml(Icon::create('cancel'));
|
||||||
$this->addSubmitButton($this->label, [
|
$this->addSubmitButton($this->label, [
|
||||||
'class' => 'link-button',
|
'class' => 'link-button',
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'data-base-target' => '_next'
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
// nothing.
|
if ($this->onSuccessAction !== null) {
|
||||||
|
$func = $this->onSuccessAction;
|
||||||
|
$func();
|
||||||
|
$this->redirectOnSuccess(
|
||||||
|
$this->translate('Service Set has been removed')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,30 @@ class IcingaServiceSet extends IcingaObject
|
||||||
return $services;
|
return $services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onDelete()
|
||||||
|
{
|
||||||
|
$hostId = $this->get('host_id');
|
||||||
|
if ($hostId) {
|
||||||
|
$deleteIds = [];
|
||||||
|
foreach ($this->getServiceObjects() as $service) {
|
||||||
|
$deleteIds[] = (int) $service->get('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($deleteIds)) {
|
||||||
|
$db = $this->getDb();
|
||||||
|
$db->delete(
|
||||||
|
'icinga_host_service_blacklist',
|
||||||
|
$db->quoteInto(
|
||||||
|
sprintf('host_id = %s AND service_id IN (?)', $hostId),
|
||||||
|
$deleteIds
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::onDelete();
|
||||||
|
}
|
||||||
|
|
||||||
public function renderToConfig(IcingaConfig $config)
|
public function renderToConfig(IcingaConfig $config)
|
||||||
{
|
{
|
||||||
if ($this->get('assign_filter') === null && $this->isTemplate()) {
|
if ($this->get('assign_filter') === null && $this->isTemplate()) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Icinga\Module\Director\Objects\IcingaServiceSet;
|
||||||
use dipl\Html\HtmlElement;
|
use dipl\Html\HtmlElement;
|
||||||
use dipl\Html\Link;
|
use dipl\Html\Link;
|
||||||
use dipl\Web\Table\ZfQueryBasedTable;
|
use dipl\Web\Table\ZfQueryBasedTable;
|
||||||
|
use dipl\Web\Url;
|
||||||
|
|
||||||
class IcingaServiceSetServiceTable extends ZfQueryBasedTable
|
class IcingaServiceSetServiceTable extends ZfQueryBasedTable
|
||||||
{
|
{
|
||||||
|
@ -157,29 +158,22 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// !!!
|
|
||||||
$deleteLink = Link::create(
|
|
||||||
$this->translate('Remove'),
|
|
||||||
'director/host/removeset',
|
|
||||||
[
|
|
||||||
'name' => $this->host->getObjectName(),
|
|
||||||
'setId' => $this->set->get('id')
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'class' => 'icon-cancel',
|
|
||||||
'style' => 'float: right; font-weight: normal',
|
|
||||||
'title' => $this->translate('Remove this set from this host')
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$deleteLink = new RemoveLinkForm(
|
$deleteLink = new RemoveLinkForm(
|
||||||
$this->translate('Remove'),
|
$this->translate('Remove'),
|
||||||
$this->translate('Remove this set from this host'),
|
$this->translate('Remove this set from this host'),
|
||||||
'director/host/removeset',
|
Url::fromPath('director/host/services', [
|
||||||
[
|
'name' => $this->host->getObjectName()
|
||||||
'name' => $this->host->getObjectName(),
|
])
|
||||||
'setId' => $this->set->get('id')
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
$hostId = $this->host->get('id');
|
||||||
|
$setName = $this->set->getObjectName();
|
||||||
|
$db = $this->set->getConnection();
|
||||||
|
$deleteLink->runOnSuccess(function () use ($db, $hostId, $setName) {
|
||||||
|
IcingaServiceSet::load([
|
||||||
|
'host_id' => $hostId,
|
||||||
|
'object_name' => $setName
|
||||||
|
], $db)->delete();
|
||||||
|
});
|
||||||
$deleteLink->handleRequest();
|
$deleteLink->handleRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue