mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 16:54:04 +02:00
parent
0626bb19cb
commit
53d2e34e23
@ -101,7 +101,17 @@ class Monitoring_CommandController extends ActionController
|
|||||||
if ($this->form->isSubmittedAndValid()) {
|
if ($this->form->isSubmittedAndValid()) {
|
||||||
$this->_helper->viewRenderer->setNoRender(true);
|
$this->_helper->viewRenderer->setNoRender(true);
|
||||||
$this->_helper->layout()->disableLayout();
|
$this->_helper->layout()->disableLayout();
|
||||||
|
|
||||||
|
$requested = strtolower($this->_request->getHeader('x-requested-with'));
|
||||||
|
$ajaxRequest = $requested === 'xmlhttprequest' ? true : false;
|
||||||
|
|
||||||
|
if ($this->_request->getHeader('referer') && $ajaxRequest === false) {
|
||||||
|
$this->redirect($this->_request->getHeader('referer'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->view->form = $this->form;
|
$this->view->form = $this->form;
|
||||||
}
|
}
|
||||||
parent::postDispatch();
|
parent::postDispatch();
|
||||||
@ -719,7 +729,7 @@ class Monitoring_CommandController extends ActionController
|
|||||||
$this->setSupportedParameters(array('commentid', 'host', 'service'));
|
$this->setSupportedParameters(array('commentid', 'host', 'service'));
|
||||||
$form = new SingleArgumentCommandForm();
|
$form = new SingleArgumentCommandForm();
|
||||||
$form->setRequest($this->_request);
|
$form->setRequest($this->_request);
|
||||||
$form->setCommand('DEL_HOST_COMMENT', 'DEL_SERVICE_COMMENT');
|
$form->setCommand('DEL_HOST_COMMENT', 'DEL_SVC_COMMENT');
|
||||||
$form->setParameterName('commentid');
|
$form->setParameterName('commentid');
|
||||||
$form->setSubmitLabel(t('Remove comment'));
|
$form->setSubmitLabel(t('Remove comment'));
|
||||||
$form->setObjectIgnoreFlag(true);
|
$form->setObjectIgnoreFlag(true);
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Form\Command\CommandForm;
|
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to build inline html command forms
|
* Helper to build inline html command forms
|
||||||
@ -15,7 +15,7 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
|
|||||||
/**
|
/**
|
||||||
* Creates a simple form without additional input fields
|
* Creates a simple form without additional input fields
|
||||||
*
|
*
|
||||||
* @param string $commandName Name of command
|
* @param string $commandName Name of command (icinga 2 web name)
|
||||||
* @param string $submitLabel Label of submit button
|
* @param string $submitLabel Label of submit button
|
||||||
* @param array $arguments Add parameter as hidden fields
|
* @param array $arguments Add parameter as hidden fields
|
||||||
*
|
*
|
||||||
@ -23,7 +23,22 @@ class Zend_View_Helper_CommandForm extends Zend_View_Helper_Abstract
|
|||||||
*/
|
*/
|
||||||
public function simpleForm($commandName, $submitLabel, array $arguments = array())
|
public function simpleForm($commandName, $submitLabel, array $arguments = array())
|
||||||
{
|
{
|
||||||
return '{{{COMMAND_FORM}}}';
|
$form = new Form();
|
||||||
|
|
||||||
|
$form->setIgnoreChangeDiscarding(true);
|
||||||
|
$form->setAttrib('data-icinga-component', 'app/ajaxPostSubmitForm');
|
||||||
|
|
||||||
|
$form->setRequest(Zend_Controller_Front::getInstance()->getRequest());
|
||||||
|
$form->setSubmitLabel($submitLabel !== null ? $submitLabel : 'Submit');
|
||||||
|
$form->setAction($this->view->href('monitoring/command/' . $commandName));
|
||||||
|
|
||||||
|
foreach ($arguments as $elementName => $elementValue) {
|
||||||
|
$hiddenField = new Zend_Form_Element_Hidden($elementName);
|
||||||
|
$hiddenField->setValue($elementValue);
|
||||||
|
$form->addElement($hiddenField);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $form->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
$viewHelper = $this->getHelper('MonitoringState');
|
$viewHelper = $this->getHelper('MonitoringState');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<h1>Comments</h1>
|
||||||
|
|
||||||
<div data-icinga-component="app/mainDetailGrid">
|
<div data-icinga-component="app/mainDetailGrid">
|
||||||
<?= $this->sortControl->render($this); ?>
|
<?= $this->sortControl->render($this); ?>
|
||||||
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
|
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
|
||||||
@ -98,17 +100,24 @@ $viewHelper = $this->getHelper('MonitoringState');
|
|||||||
<?=
|
<?=
|
||||||
($comment->comment_expiration_timestamp) ?
|
($comment->comment_expiration_timestamp) ?
|
||||||
$dateHelper->formatDateTime($comment->comment_expiration_timestamp) :
|
$dateHelper->formatDateTime($comment->comment_expiration_timestamp) :
|
||||||
' ';
|
'Never';
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?=
|
<?php
|
||||||
$commandHelper->simpleForm(
|
$data = array(
|
||||||
|
'commentid' => $comment->comment_id,
|
||||||
|
'host' => $comment->host_name
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($objectType === 'service') {
|
||||||
|
$data['service'] = $comment->service_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $commandHelper->simpleForm(
|
||||||
'removecomment',
|
'removecomment',
|
||||||
'Remove',
|
'Remove Comment',
|
||||||
array(
|
$data
|
||||||
'commentid' => $comment->comment_id
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
@ -117,4 +126,5 @@ $viewHelper = $this->getHelper('MonitoringState');
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<?= $this->paginationControl($comments, null, null, array('preserve' => $this->preserve)); ?>
|
||||||
</div>
|
</div>
|
92
public/js/icinga/components/ajaxPostSubmitForm.js
Normal file
92
public/js/icinga/components/ajaxPostSubmitForm.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
/**
|
||||||
|
* This file is part of Icinga 2 Web.
|
||||||
|
*
|
||||||
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||||
|
* Copyright (C) 2013 Icinga Development Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||||
|
* @author Icinga Development Team <info@icinga.org>
|
||||||
|
*/
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
/*global Icinga:false define:false require:false base_url:false console:false */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Icinga app/ajaxPostSubmitForm component.
|
||||||
|
*
|
||||||
|
* This component converts generic post forms into ajax
|
||||||
|
* submit forms.
|
||||||
|
*/
|
||||||
|
define(['components/app/container', 'jquery'], function(Container, $) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns owner container
|
||||||
|
*
|
||||||
|
* @param {Element} targetElement
|
||||||
|
* @returns {Container}
|
||||||
|
*/
|
||||||
|
var getOwnerContainer = function(targetElement) {
|
||||||
|
var me = new Container(targetElement);
|
||||||
|
return new Container(me.findNearestContainer(targetElement));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for ajax post submit
|
||||||
|
*
|
||||||
|
* @param {Event} e
|
||||||
|
*/
|
||||||
|
var submitHandler = function(e) {
|
||||||
|
var form = $(this);
|
||||||
|
var url = form.attr('action');
|
||||||
|
var submit = form.find('input[type="submit"]');
|
||||||
|
var data = form.serialize();
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Submit name is missing for valid submission
|
||||||
|
if (data) {
|
||||||
|
data += '&';
|
||||||
|
}
|
||||||
|
data += submit.attr('name') + '=1';
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: 'POST',
|
||||||
|
data: data,
|
||||||
|
beforeSend: function() {
|
||||||
|
submit.prop('disabled', true);
|
||||||
|
}
|
||||||
|
}).done(function() {
|
||||||
|
var container = getOwnerContainer(form);
|
||||||
|
container.replaceDomFromUrl(container.getContainerHref());
|
||||||
|
}).error(function() {
|
||||||
|
submit.removeProp('disabled');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The component bootstrap
|
||||||
|
*
|
||||||
|
* @param {Element} targetElement
|
||||||
|
*/
|
||||||
|
return function(targetForm) {
|
||||||
|
var form = $(targetForm);
|
||||||
|
form.submit(submitHandler);
|
||||||
|
};
|
||||||
|
});
|
@ -91,7 +91,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
|
|||||||
* @returns {HTMLElement|null} The nearest container found or null if target is no container
|
* @returns {HTMLElement|null} The nearest container found or null if target is no container
|
||||||
* and no container is above target
|
* and no container is above target
|
||||||
*/
|
*/
|
||||||
var findNearestContainer = function(target) {
|
this.findNearestContainer = function(target) {
|
||||||
target = $(target);
|
target = $(target);
|
||||||
if (target.attr('data-icinga-component') === 'app/container' ||
|
if (target.attr('data-icinga-component') === 'app/container' ||
|
||||||
target.attr('id') === 'icingamain' || target.attr('id') === 'icingadetail') {
|
target.attr('id') === 'icingamain' || target.attr('id') === 'icingadetail') {
|
||||||
@ -106,7 +106,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe
|
|||||||
* @param {HTMLElement, jQuery, String} target A jQuery resultset, dom element or matcher string
|
* @param {HTMLElement, jQuery, String} target A jQuery resultset, dom element or matcher string
|
||||||
*/
|
*/
|
||||||
this.construct = function(target) {
|
this.construct = function(target) {
|
||||||
this.containerDom = $(findNearestContainer(target));
|
this.containerDom = $(this.findNearestContainer(target));
|
||||||
this.containerType = CONTAINER_TYPES.GENERIC;
|
this.containerType = CONTAINER_TYPES.GENERIC;
|
||||||
|
|
||||||
if (this.containerDom.attr('id') === CONTAINER_TYPES.MAIN) {
|
if (this.containerDom.attr('id') === CONTAINER_TYPES.MAIN) {
|
||||||
|
@ -130,6 +130,11 @@ function(Container, $, logger, URI) {
|
|||||||
if (true || Container.isExternalLink(a.attr('href'))) {
|
if (true || Container.isExternalLink(a.attr('href'))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else if (targetEl.nodeName.toLowerCase() === 'input') {
|
||||||
|
var type = $(targetEl).attr('type');
|
||||||
|
if (type === 'submit') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Container.getDetailContainer().replaceDomFromUrl($('a', this).attr('href'));
|
Container.getDetailContainer().replaceDomFromUrl($('a', this).attr('href'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user