mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-25 10:57:40 +02:00
Forms: Introduce RemoveDashletForm
class
This commit is contained in:
parent
22450ab88a
commit
dcaf62573c
46
application/forms/Dashboard/RemoveDashletForm.php
Normal file
46
application/forms/Dashboard/RemoveDashletForm.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
|
||||
|
||||
namespace Icinga\Forms\Dashboard;
|
||||
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\Dashboard\Dashboard;
|
||||
use ipl\Html\HtmlElement;
|
||||
use ipl\Web\Compat\CompatForm;
|
||||
use ipl\Web\Url;
|
||||
|
||||
class RemoveDashletForm extends CompatForm
|
||||
{
|
||||
/** @var Dashboard */
|
||||
protected $dashboard;
|
||||
|
||||
public function __construct(Dashboard $dashboard)
|
||||
{
|
||||
$this->dashboard = $dashboard;
|
||||
|
||||
$this->setAction((string) Url::fromRequest());
|
||||
}
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$this->addHtml(HtmlElement::create('h1', null, sprintf(
|
||||
t('Please confirm removal of dashlet "%s"'),
|
||||
Url::fromRequest()->getParam('dashlet')
|
||||
)));
|
||||
|
||||
$this->addElement('submit', 'remove_dashlet', ['label' => t('Remove Dashlet')]);
|
||||
}
|
||||
|
||||
protected function onSuccess()
|
||||
{
|
||||
$requestUrl = Url::fromRequest();
|
||||
$home = $this->dashboard->getActiveHome();
|
||||
$pane = $home->getPane($requestUrl->getParam('pane'));
|
||||
|
||||
$dashlet = $requestUrl->getParam('dashlet');
|
||||
$pane->removeDashlet($dashlet);
|
||||
|
||||
Notification::success(sprintf(t('Removed dashlet "%s" successfully'), $dashlet));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user