ActionController: add isXhr() method

Makes things easier as we use this a lot
This commit is contained in:
Thomas Gelf 2014-06-22 15:36:41 +02:00
parent 331d756a2a
commit 3774eb6889
1 changed files with 10 additions and 5 deletions

View File

@ -158,7 +158,7 @@ class ActionController extends Zend_Controller_Action
protected function handlerBrowserWindows()
{
if ($this->_request->isXmlHttpRequest()) {
if ($this->isXhr()) {
$id = $this->_request->getHeader('X-Icinga-WindowId', null);
if ($id === Window::UNDEFINED) {
@ -281,7 +281,7 @@ class ActionController extends Zend_Controller_Action
protected function ignoreXhrBody()
{
if ($this->getRequest()->isXmlHttpRequest()) {
if ($this->isXhr()) {
$this->getResponse()->setHeader('X-Icinga-Container', 'ignore');
}
}
@ -315,13 +315,18 @@ class ActionController extends Zend_Controller_Action
protected function redirectToLogin($afterLogin = '/dashboard')
{
$url = Url::fromPath('/authentication/login');
if ($this->getRequest()->isXmlHttpRequest()) {
if ($this->isXhr()) {
$url->setParam('_render', 'layout');
}
$url->setParam('redirect', $afterLogin);
$this->redirectNow($url);
}
public function isXhr()
{
return $this->getRequest()->isXmlHttpRequest();
}
/**
* Redirect to a specific url, updating the browsers URL field
*
@ -330,7 +335,7 @@ class ActionController extends Zend_Controller_Action
public function redirectNow($url)
{
$url = preg_replace('~&~', '&', $url);
if ($this->_request->isXmlHttpRequest()) {
if ($this->isXhr()) {
$this->getResponse()
->setHeader('X-Icinga-Redirect', rawurlencode($url))
->sendHeaders();
@ -371,7 +376,7 @@ class ActionController extends Zend_Controller_Action
exit;
}
if ($req->isXmlHttpRequest()) {
if ($this->isXhr()) {
$this->postDispatchXhr();
}
}