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

View File

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