parent
ffd12e325c
commit
4463f16f04
|
@ -90,8 +90,8 @@ class Monitoring_CommentsController extends Controller
|
|||
$this->translate('Confirm removal of %d comments.'),
|
||||
count($this->comments)
|
||||
));
|
||||
$delCommentForm->setObjects($this->comments)
|
||||
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'))
|
||||
$delCommentForm->setComments($this->comments)
|
||||
->setRedirectUrl(Url::fromPath('monitoring/list/comments'))
|
||||
->handleRequest();
|
||||
$this->view->delCommentForm = $delCommentForm;
|
||||
}
|
||||
|
|
|
@ -4,13 +4,21 @@
|
|||
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
|
||||
use \Icinga\Module\Monitoring\Forms\Command\CommandForm;
|
||||
use Icinga\Web\Notification;
|
||||
|
||||
/**
|
||||
* Form for deleting host or service comments
|
||||
*/
|
||||
class DeleteCommentsCommandForm extends ObjectsCommandForm
|
||||
class DeleteCommentsCommandForm extends CommandForm
|
||||
{
|
||||
/**
|
||||
* The comments deleted on success
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $comments;
|
||||
|
||||
/**
|
||||
* (non-PHPDoc)
|
||||
* @see \Zend_Form::init() For the method documentation.
|
||||
|
@ -27,20 +35,10 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm
|
|||
public function createElements(array $formData = array())
|
||||
{
|
||||
$this->addElements(array(
|
||||
array(
|
||||
'hidden',
|
||||
'comment_id',
|
||||
array(
|
||||
'required' => true,
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'hidden',
|
||||
'redirect',
|
||||
array(
|
||||
'decorators' => array('ViewHelper')
|
||||
)
|
||||
array('decorators' => array('ViewHelper'))
|
||||
)
|
||||
));
|
||||
return $this;
|
||||
|
@ -74,13 +72,11 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm
|
|||
*/
|
||||
public function onSuccess()
|
||||
{
|
||||
foreach ($this->objects as $object) {
|
||||
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
|
||||
$delComment = new DeleteCommentCommand();
|
||||
$delComment
|
||||
->setObject($object)
|
||||
->setCommentId($this->getElement('comment_id')->getValue());
|
||||
$this->getTransport($this->request)->send($delComment);
|
||||
foreach ($this->comments as $comment) {
|
||||
$cmd = new DeleteCommentCommand();
|
||||
$cmd->setCommentId($comment->id)
|
||||
->setIsService(isset($comment->service_description));
|
||||
$this->getTransport($this->request)->send($cmd);
|
||||
}
|
||||
$redirect = $this->getElement('redirect')->getValue();
|
||||
if (! empty($redirect)) {
|
||||
|
@ -89,4 +85,17 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm
|
|||
Notification::success($this->translate('Deleting comment..'));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comments to be deleted upon success
|
||||
*
|
||||
* @param array $comments
|
||||
*
|
||||
* @return this fluent interface
|
||||
*/
|
||||
public function setComments(array $comments)
|
||||
{
|
||||
$this->comments = $comments;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,11 +64,7 @@ class DeleteDowntimesCommandForm extends CommandForm
|
|||
foreach ($this->downtimes as $downtime) {
|
||||
$delDowntime = new DeleteDowntimeCommand();
|
||||
$delDowntime->setDowntimeId($downtime->id);
|
||||
$delDowntime->setDowntimeType(
|
||||
isset($downtime->service_description) ?
|
||||
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
|
||||
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
|
||||
);
|
||||
$delDowntime->setIsService(isset($downtime->service_description));
|
||||
$this->getTransport($this->request)->send($delDowntime);
|
||||
}
|
||||
$redirect = $this->getElement('redirect')->getValue();
|
||||
|
@ -86,7 +82,7 @@ class DeleteDowntimesCommandForm extends CommandForm
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDowntimes($downtimes)
|
||||
public function setDowntimes(array $downtimes)
|
||||
{
|
||||
$this->downtimes = $downtimes;
|
||||
return $this;
|
||||
|
|
|
@ -83,7 +83,13 @@ if (count($comments) === 0) {
|
|||
<td style="width: 2em" data-base-target="self">
|
||||
<?php
|
||||
$delCommentForm = clone $delCommentForm;
|
||||
$delCommentForm->populate(array('comment_id' => $comment->id, 'redirect' => $this->url));
|
||||
$delCommentForm->populate(
|
||||
array(
|
||||
'comment_id' => $comment->id,
|
||||
'comment_is_service' => isset($comment->service_description),
|
||||
'redirect' => $this->url
|
||||
)
|
||||
);
|
||||
$delCommentForm->setAction($this->url('monitoring/comment/remove', array('comment_id' => $comment->id)));
|
||||
echo $delCommentForm;
|
||||
?>
|
||||
|
|
|
@ -128,7 +128,12 @@ if (count($downtimes) === 0) {
|
|||
<td style="width: 2em" data-base-target="self">
|
||||
<?php
|
||||
$delDowntimeForm = clone $delDowntimeForm;
|
||||
$delDowntimeForm->populate(array('downtime_id' => $downtime->id, 'redirect' => $this->url));
|
||||
$delDowntimeForm->populate(
|
||||
array(
|
||||
'downtime_id' => $downtime->id,
|
||||
'redirect' => $this->url
|
||||
)
|
||||
);
|
||||
$delDowntimeForm->setAction($this->url('monitoring/downtime/remove', array('downtime_id' => $downtime->id)));
|
||||
echo $delDowntimeForm;
|
||||
?>
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Icinga\Module\Monitoring\Web\Controller;
|
|||
|
||||
use Icinga\Module\Monitoring\Controller;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
|
||||
|
@ -81,10 +81,8 @@ abstract class MonitoredObjectController extends Controller
|
|||
->handleRequest();
|
||||
$this->view->toggleFeaturesForm = $toggleFeaturesForm;
|
||||
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
|
||||
$delCommentForm = new DeleteCommentsCommandForm();
|
||||
$delCommentForm
|
||||
->setObjects($this->object)
|
||||
->handleRequest();
|
||||
$delCommentForm = new DeleteCommentCommandForm();
|
||||
$delCommentForm->handleRequest();
|
||||
$this->view->delCommentForm = $delCommentForm;
|
||||
}
|
||||
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
||||
|
|
Loading…
Reference in New Issue