DashboardController: Allow to update panes

refs #2901
This commit is contained in:
Johannes Meyer 2018-04-06 11:10:42 +02:00
parent 72f0e809ae
commit 30920d1178
3 changed files with 72 additions and 0 deletions

View File

@ -6,6 +6,7 @@ namespace Icinga\Controllers;
use Exception;
use Zend_Controller_Action_Exception;
use Icinga\Exception\ProgrammingError;
use Icinga\Exception\Http\HttpNotFoundException;
use Icinga\Forms\ConfirmRemovalForm;
use Icinga\Forms\Dashboard\DashletForm;
use Icinga\Web\Controller\ActionController;
@ -197,6 +198,62 @@ class DashboardController extends ActionController
$this->view->form = $form;
}
public function renamePaneAction()
{
$paneName = $this->params->getRequired('pane');
if (! $this->dashboard->hasPane($paneName)) {
throw new HttpNotFoundException('Pane not found');
}
$form = new Form();
$form->setRedirectUrl('dashboard/settings');
$form->setSubmitLabel($this->translate('Update Pane'));
$form->addElement(
'text',
'name',
array(
'required' => true,
'label' => $this->translate('Name')
)
);
$form->addElement(
'text',
'title',
array(
'required' => true,
'label' => $this->translate('Title')
)
);
$form->setDefaults(array(
'name' => $paneName,
'title' => $this->dashboard->getPane($paneName)->getTitle()
));
$form->setOnSuccess(function ($form) use ($paneName) {
$newName = $form->getValue('name');
$newTitle = $form->getValue('title');
$pane = $this->dashboard->getPane($paneName);
$pane->setName($newName);
$pane->setTitle($newTitle);
$this->dashboard->getConfig()->saveIni();
Notification::success(
sprintf($this->translate('Pane "%s" successfully renamed to "%s"'), $paneName, $newName)
);
});
$form->handleRequest();
$this->view->form = $form;
$this->getTabs()->add(
'update-pane',
array(
'title' => $this->translate('Update Pane'),
'url' => $this->getRequest()->getUrl()
)
)->activate('update-pane');
}
public function removePaneAction()
{
$form = new ConfirmRemovalForm();

View File

@ -0,0 +1,6 @@
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content">
<?= $this->form; ?>
</div>

View File

@ -21,7 +21,16 @@
<?php if ($pane->getDisabled()) continue; ?>
<tr style="background-color: #f1f1f1;">
<th colspan="2" style="text-align: left; padding: 0.5em;">
<?php if ($pane->isUserWidget()): ?>
<?= $this->qlink(
$pane->getName(),
'dashboard/rename-pane',
array('pane' => $pane->getName()),
array('title' => sprintf($this->translate('Edit pane %s'), $pane->getName()))
) ?>
<?php else: ?>
<?= $this->escape($pane->getName()) ?>
<?php endif ?>
</th>
<th>
<?= $this->qlink(