diff --git a/library/Icinga/Web/Response.php b/library/Icinga/Web/Response.php index 13e88e32b..140dc770f 100644 --- a/library/Icinga/Web/Response.php +++ b/library/Icinga/Web/Response.php @@ -15,6 +15,13 @@ class Response extends Zend_Controller_Response_Http */ protected $request; + /** + * Whether to send the rerender layout header on XHR + * + * @var bool + */ + protected $rerenderLayout = false; + /** * Get the request * @@ -28,6 +35,39 @@ class Response extends Zend_Controller_Response_Http return $this->request; } + /** + * Get whether to send the rerender layout header on XHR + * + * @return bool + */ + public function getRerenderLayout() + { + return $this->rerenderLayout; + } + + /** + * Get whether to send the rerender layout header on XHR + * + * @param bool $rerenderLayout + * + * @return $this + */ + public function setRerenderLayout($rerenderLayout = true) + { + $this->rerenderLayout = (bool) $rerenderLayout; + return $this; + } + + /** + * Prepare the request before sending + */ + protected function prepare() + { + if ($this->getRequest()->isXmlHttpRequest() && $this->getRerenderLayout()) { + $this->setHeader('X-Icinga-Rerender-Layout', 'yes'); + } + } + /** * Redirect to the given URL and exit immediately * @@ -54,4 +94,13 @@ class Response extends Zend_Controller_Response_Http $this->sendHeaders(); exit; } + + /** + * {@inheritdoc} + */ + public function sendHeaders() + { + $this->prepare(); + return parent::sendHeaders(); + } }