diff --git a/application/forms/IcingaDeleteObjectForm.php b/application/forms/IcingaDeleteObjectForm.php new file mode 100644 index 00000000..fe49a39f --- /dev/null +++ b/application/forms/IcingaDeleteObjectForm.php @@ -0,0 +1,43 @@ +submitLabel = sprintf( + $this->translate('YES, please delete "%s"'), + $this->object->object_name + ); + + } + + public function onSuccess() + { + $object = $this->object; + $msg = sprintf( + 'The %s "%s" has been deleted', + $object->getShortTableName(), + $object->object_name + ); + + if ($object->delete()) { + $this->redirectOnSuccess($msg); + } else { + $this->redirectOnFailure($msg); + } + } + + public function setObject(IcingaObject $object) + { + $this->object = $object; + return $this; + } +} diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index aa4040cb..f46b61ed 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -24,6 +24,10 @@ abstract class ObjectController extends ActionController 'url' => sprintf('director/%s/edit', $ltype), 'urlParams' => $params, 'label' => $this->translate('Modify') + ))->add('delete', array( + 'url' => sprintf('director/%s/delete', $ltype), + 'urlParams' => $params, + 'label' => $this->translate('Delete') ))->add('history', array( 'url' => sprintf('director/%s/history', $ltype), 'urlParams' => $params, @@ -45,6 +49,27 @@ abstract class ObjectController extends ActionController $this->render('object/show', null, true); } + public function deleteAction() + { + $this->getTabs()->activate('delete'); + $type = $this->getType(); + $ltype = strtolower($type); + + $this->view->form = $form = $this->loadForm( + 'icingaDeleteObject' + )->setObject($this->object()); + + $url = Url::fromPath(sprintf('director/%ss', $ltype)); + $form->setSuccessUrl($url); + + $this->view->title = sprintf( + $this->translate('Delete Icinga %s'), + ucfirst($ltype) + ); + $this->view->form->handleRequest(); + $this->render('object/form', null, true); + } + public function editAction() { $this->getTabs()->activate('modify');