From 18db984057b83ca4962c89b6b79bdce6a660b58f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:42:35 +0200 Subject: Adding upstream version 2.4.0. Signed-off-by: Daniel Baumann --- application/forms/DeleteNodeForm.php | 165 +++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 application/forms/DeleteNodeForm.php (limited to 'application/forms/DeleteNodeForm.php') diff --git a/application/forms/DeleteNodeForm.php b/application/forms/DeleteNodeForm.php new file mode 100644 index 0000000..dada9d3 --- /dev/null +++ b/application/forms/DeleteNodeForm.php @@ -0,0 +1,165 @@ +node; + $view = $this->getView(); + $this->addHtml( + '

' . $view->escape( + sprintf($this->translate('Delete "%s"'), $node->getAlias()) + ) . '

' + ); + + $biLink = $view->qlink( + $node->getAlias(), + 'businessprocess/node/impact', + array('name' => $node->getName()), + array('data-base-target' => '_next') + ); + $this->addHtml( + '

' . sprintf( + $view->escape( + $this->translate('Unsure? Show business impact of "%s"') + ), + $biLink + ) . '

' + ); + + if ($this->parentNode) { + $yesMsg = sprintf( + $this->translate('Delete from %s'), + $this->parentNode->getAlias() + ); + } else { + $yesMsg = sprintf( + $this->translate('Delete root node "%s"'), + $this->node->getAlias() + ); + } + + $this->addElement('select', 'confirm', array( + 'label' => $this->translate('Are you sure?'), + 'required' => true, + 'description' => $this->translate( + 'Do you really want to delete this node?' + ), + 'multiOptions' => $this->optionalEnum(array( + 'no' => $this->translate('No'), + 'yes' => $yesMsg, + 'all' => sprintf($this->translate('Delete all occurrences of %s'), $node->getAlias()), + )) + )); + } + + /** + * @param MonitoringBackend|IcingaDbConnection $backend + * @return $this + */ + public function setBackend($backend) + { + $this->backend = $backend; + return $this; + } + + /** + * @param BpConfig $process + * @return $this + */ + public function setProcess(BpConfig $process) + { + $this->bp = $process; + $this->setBackend($process->getBackend()); + return $this; + } + + /** + * @param Node $node + * @return $this + */ + public function setNode(Node $node) + { + $this->node = $node; + return $this; + } + + /** + * @param BpNode|null $node + * @return $this + */ + public function setParentNode(BpNode $node = null) + { + $this->parentNode = $node; + return $this; + } + + /** + * @param SessionNamespace $session + * @return $this + */ + public function setSession(SessionNamespace $session) + { + $this->session = $session; + return $this; + } + + public function onSuccess() + { + $changes = ProcessChanges::construct($this->bp, $this->session); + + $confirm = $this->getValue('confirm'); + switch ($confirm) { + case 'yes': + $changes->deleteNode($this->node, $this->parentNode === null ? null : $this->parentNode->getName()); + break; + case 'all': + $changes->deleteNode($this->node); + break; + case 'no': + $this->setSuccessMessage($this->translate('Well, maybe next time')); + } + + switch ($confirm) { + case 'yes': + case 'all': + if ($this->successUrl === null) { + $this->successUrl = clone $this->getRequest()->getUrl(); + } + + $this->successUrl->getParams()->remove(array('action', 'deletenode')); + } + + // Trigger session desctruction to make sure it get's stored. + // TODO: figure out why this is necessary, might be an unclean shutdown on redirect + unset($changes); + + parent::onSuccess(); + } +} -- cgit v1.2.3