Skip to content

Commit

Permalink
Add delete button to modify view
Browse files Browse the repository at this point in the history
The modify view for the process form and edit node form must contain delete button. This allows the user to either
store the modifications or delete the nodes.
  • Loading branch information
raviks789 committed Jul 24, 2023
1 parent cbb6b01 commit b1a06e0
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
41 changes: 41 additions & 0 deletions application/forms/EditNodeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Session\SessionNamespace;
use ipl\Sql\Connection as IcingaDbConnection;
use ipl\Web\Url;

class EditNodeForm extends QuickForm
{
Expand Down Expand Up @@ -79,6 +80,18 @@ public function setup()
$this->setSubmitLabel($this->translate('Next'));
return;
}

$this->deleteButtonName = 'delete_node';

$this->addElement(
'submit',
$this->deleteButtonName,
[
'label' => $this->translate('Delete'),
'data-base-target' => '_main',
'decorators' => ['ViewHelper']
]
);
}

protected function isService()
Expand Down Expand Up @@ -388,6 +401,24 @@ public function getNode()
return $this->node;
}

protected function onRequest()
{
$params = Url::fromRequest()->getParams();
if ($this->shouldBeDeleted()) {
$url = Url::fromRequest();

$url->setParams([
'config' => $params->get('config'),
'node' => $params->get('node'),
'unlocked' => 1,
'action' => 'delete',
'deletenode' => $params->get('editmonitorednode')
]);

$this->redirectAndExit($url);
}
}

public function onSuccess()
{
$changes = ProcessChanges::construct($this->bp, $this->session);
Expand Down Expand Up @@ -443,4 +474,14 @@ public function isValid($data)

return parent::isValid($data);
}

public function shouldBeDeleted()
{
if ($this->deleteButtonName === null) {
return false;
}

$name = $this->deleteButtonName;
return $this->getSentValue($name) === $this->getElement($name)->getLabel();
}
}
49 changes: 49 additions & 0 deletions application/forms/ProcessForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Icinga\Web\Notification;
use Icinga\Web\Session\SessionNamespace;
use ipl\Sql\Connection as IcingaDbConnection;
use ipl\Web\Url;

class ProcessForm extends QuickForm
{
Expand Down Expand Up @@ -92,6 +93,13 @@ public function setup()
$this->getElement('url')->setValue($node->getInfoUrl());
}
}

$label = $this->translate('Delete');
$el = $this->createElement('submit', $label, array(
'data-base-target' => '_main'
))->setLabel($label)->setDecorators(array('ViewHelper'));
$this->deleteButtonName = $el->getName();
$this->addElement($el);
}

/**
Expand Down Expand Up @@ -135,6 +143,32 @@ public function setSession(SessionNamespace $session)
return $this;
}

protected function onRequest()
{
$params = Url::fromRequest()->getParams();
if ($this->shouldBeDeleted()) {
$url = Url::fromRequest();

$url->setParams([
'config' => $params->get('config'),
'unlocked' => 1,
'action' => 'delete',
'deletenode' => $params->get('editnode')
]);

$this->redirectAndExit($url);
}
}

protected function getNode(BpConfig $bp, $nodeName)
{
if ($nodeName) {
return $bp->getNode($nodeName);
} else {
return null;
}
}

public function onSuccess()
{
$changes = ProcessChanges::construct($this->bp, $this->session);
Expand Down Expand Up @@ -195,4 +229,19 @@ public function onSuccess()

parent::onSuccess();
}

public function hasDeleteButton()
{
return $this->deleteButtonName !== null;
}

public function shouldBeDeleted()
{
if (! $this->hasDeleteButton()) {
return false;
}

$name = $this->deleteButtonName;
return $this->getSentValue($name) === $this->getElement($name)->getLabel();
}
}

0 comments on commit b1a06e0

Please sign in to comment.