JS/XHR: get ready to get XHR redirect-aware

These are just the first steps, there is more to come
This commit is contained in:
Thomas Gelf 2014-06-05 03:37:36 +00:00
parent b3f65c8e37
commit 99aae5a0d9
2 changed files with 22 additions and 7 deletions

View File

@ -370,13 +370,19 @@ class ActionController extends Zend_Controller_Action
**/ **/
public function redirectNow($url) public function redirectNow($url)
{ {
if ($url instanceof Url) { if (! $url instanceof Url) {
$url = $url->getRelativeUrl(); $url = Url::fromPath($url);
} else {
$url = Url::fromPath($url)->getRelativeUrl();
} }
$this->_helper->Redirector->gotoUrlAndExit(preg_replace('~&~', '&', $url)); $url = preg_replace('~&~', '&', $url);
$this->isRedirect = true; if ($this->_request->isXmlHttpRequest()) {
header('X-Icinga-Redirect: ' . rawurlencode($url));
// $this->getResponse()->sendHeaders() ??
// Session shutdown
exit; // Really?
} else {
$this->_helper->Redirector->gotoUrlAndExit($url);
}
$this->isRedirect = true; // pretty useless right now
} }
/** /**

View File

@ -244,6 +244,15 @@
this.icinga.logger.debug( this.icinga.logger.debug(
'Got response for ', req.$target, ', URL was ' + url 'Got response for ', req.$target, ', URL was ' + url
); );
var redirect = req.getResponseHeader('X-Icinga-Redirect');
if (redirect) {
this.icinga.logger.debug(
'Got redirect for ', req.$target, ', URL was ' + redirect
);
redirect = decodeURIComponent(redirect);
this.loadUrl(redirect, req.$target);
return;
}
// div helps getting an XML tree // div helps getting an XML tree
var $resp = $('<div>' + req.responseText + '</div>'); var $resp = $('<div>' + req.responseText + '</div>');
@ -400,6 +409,7 @@
this.icinga.history.pushCurrentState(); this.icinga.history.pushCurrentState();
} }
} }
this.icinga.ui.initializeTriStates($resp); this.icinga.ui.initializeTriStates($resp);
// Make multiselection-tables not selectable. // Make multiselection-tables not selectable.
@ -459,7 +469,6 @@
); );
} }
if (active) { if (active) {
var focusedUrl = this.icinga.ui.getFocusedContainerDataUrl(); var focusedUrl = this.icinga.ui.getFocusedContainerDataUrl();
var oldSelectionData = this.icinga.ui.loadSelectionData(); var oldSelectionData = this.icinga.ui.loadSelectionData();