Skip to content

Commit 038d04b

Browse files
committed
Add delete button to modify view
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.
1 parent cbb6b01 commit 038d04b

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

application/forms/EditNodeForm.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
1313
use Icinga\Web\Session\SessionNamespace;
1414
use ipl\Sql\Connection as IcingaDbConnection;
15+
use ipl\Web\Url;
1516

1617
class EditNodeForm extends QuickForm
1718
{
@@ -79,6 +80,20 @@ public function setup()
7980
$this->setSubmitLabel($this->translate('Next'));
8081
return;
8182
}
83+
84+
$this->deleteButtonName = 'delete_node';
85+
86+
$el = $this->createElement(
87+
'submit',
88+
$this->deleteButtonName,
89+
[
90+
'label' => $this->translate('Delete'),
91+
'data-base-target' => '_main',
92+
'decorators' => ['ViewHelper']
93+
]
94+
);
95+
96+
$this->addElement($el);
8297
}
8398

8499
protected function isService()
@@ -388,6 +403,24 @@ public function getNode()
388403
return $this->node;
389404
}
390405

406+
protected function onRequest()
407+
{
408+
$params = Url::fromRequest()->getParams();
409+
if ($this->shouldBeDeleted()) {
410+
$url = Url::fromRequest();
411+
412+
$url->setParams([
413+
'config' => $params->get('config'),
414+
'node' => $params->get('node'),
415+
'unlocked' => 1,
416+
'action' => 'delete',
417+
'deletenode' => $params->get('editmonitorednode')
418+
]);
419+
420+
$this->redirectAndExit($url);
421+
}
422+
}
423+
391424
public function onSuccess()
392425
{
393426
$changes = ProcessChanges::construct($this->bp, $this->session);
@@ -443,4 +476,14 @@ public function isValid($data)
443476

444477
return parent::isValid($data);
445478
}
479+
480+
public function shouldBeDeleted()
481+
{
482+
if ($this->deleteButtonName === null) {
483+
return false;
484+
}
485+
486+
$name = $this->deleteButtonName;
487+
return $this->getSentValue($name) === $this->getElement($name)->getLabel();
488+
}
446489
}

application/forms/ProcessForm.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Icinga\Web\Notification;
1212
use Icinga\Web\Session\SessionNamespace;
1313
use ipl\Sql\Connection as IcingaDbConnection;
14+
use ipl\Web\Url;
1415

1516
class ProcessForm extends QuickForm
1617
{
@@ -92,6 +93,13 @@ public function setup()
9293
$this->getElement('url')->setValue($node->getInfoUrl());
9394
}
9495
}
96+
97+
$label = $this->translate('Delete');
98+
$el = $this->createElement('submit', $label, array(
99+
'data-base-target' => '_main'
100+
))->setLabel($label)->setDecorators(array('ViewHelper'));
101+
$this->deleteButtonName = $el->getName();
102+
$this->addElement($el);
95103
}
96104

97105
/**
@@ -135,6 +143,32 @@ public function setSession(SessionNamespace $session)
135143
return $this;
136144
}
137145

146+
protected function onRequest()
147+
{
148+
$params = Url::fromRequest()->getParams();
149+
if ($this->shouldBeDeleted()) {
150+
$url = Url::fromRequest();
151+
152+
$url->setParams([
153+
'config' => $params->get('config'),
154+
'unlocked' => 1,
155+
'action' => 'delete',
156+
'deletenode' => $params->get('editnode')
157+
]);
158+
159+
$this->redirectAndExit($url);
160+
}
161+
}
162+
163+
protected function getNode(BpConfig $bp, $nodeName)
164+
{
165+
if ($nodeName) {
166+
return $bp->getNode($nodeName);
167+
} else {
168+
return null;
169+
}
170+
}
171+
138172
public function onSuccess()
139173
{
140174
$changes = ProcessChanges::construct($this->bp, $this->session);
@@ -195,4 +229,19 @@ public function onSuccess()
195229

196230
parent::onSuccess();
197231
}
232+
233+
public function hasDeleteButton()
234+
{
235+
return $this->deleteButtonName !== null;
236+
}
237+
238+
public function shouldBeDeleted()
239+
{
240+
if (! $this->hasDeleteButton()) {
241+
return false;
242+
}
243+
244+
$name = $this->deleteButtonName;
245+
return $this->getSentValue($name) === $this->getElement($name)->getLabel();
246+
}
198247
}

0 commit comments

Comments
 (0)