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 must contain delete button. This allows the user to either
store the modifications or delete the process node.
  • Loading branch information
raviks789 committed Aug 5, 2022
1 parent ce812c0 commit b7920fc
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions application/forms/ProcessForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -109,6 +110,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 @@ -152,6 +160,33 @@ public function setSession(SessionNamespace $session)
return $this;
}

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

$url->setParams([
'config' => $params->get('config'),
'node' => $params->get('path'),
'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 @@ -212,4 +247,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 b7920fc

Please sign in to comment.