Skip to content

Commit

Permalink
js/loader: Handle __SELF__ in redirection URLs
Browse files Browse the repository at this point in the history
That's one more step to smoothly handle #! URLs, especially when you
are not yet authenticated.

refs #6935
  • Loading branch information
Thomas-Gelf committed Aug 19, 2014
1 parent 9d4a4f4 commit 512e7d5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions public/js/icinga/loader.js
Expand Up @@ -250,14 +250,24 @@
var icinga = this.icinga;
var redirect = req.getResponseHeader('X-Icinga-Redirect');
if (! redirect) return false;
redirect = decodeURIComponent(redirect);
if (redirect.match(/__SELF__/)) {
redirect = redirect.replace(/__SELF__/, encodeURIComponent(document.location.pathname + document.location.search + document.location.hash));
}
icinga.logger.debug(
'Got redirect for ', req.$target, ', URL was ' + redirect
);
redirect = decodeURIComponent(redirect);

if (req.getResponseHeader('X-Icinga-Rerender-Layout')) {
var parts = redirect.split(/#!/);
redirect = parts.shift();
var redirectionUrl = this.addUrlFlag(redirect, 'renderLayout');
this.loadUrl(redirectionUrl, $('#layout')).url = redirect;
var r = this.loadUrl(redirectionUrl, $('#layout'));
r.url = redirect;
if (parts.length) {
r.loadNext = parts;
}

} else {
if (req.$target.attr('id') === 'col2') { // TODO: multicol
if ($('#col1').data('icingaUrl') === redirect) {
Expand Down Expand Up @@ -556,6 +566,17 @@
req.$target.data('lastUpdate', (new Date()).getTime());
delete this.requests[req.$target.attr('id')];
this.icinga.ui.fadeNotificationsAway();


if (typeof req.loadNext !== 'undefined') {
if ($('#col2').length) {
this.loadUrl(req.loadNext[0], $('#col2'));
this.icinga.ui.layout2col();
} else {
this.icinga.logger.error('Failed to load URL for #col2', req.loadNext);
}
}

this.icinga.ui.refreshDebug();
},

Expand Down

0 comments on commit 512e7d5

Please sign in to comment.