object/delete: add new delete form
This commit is contained in:
parent
9e80a5242b
commit
2e0c636574
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||
|
||||
class IcingaDeleteObjectForm extends QuickForm
|
||||
{
|
||||
protected $object;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue