CLOUDSTACK-1065: cloudstack UI - AWS Style Regions - when switching region, set location without parameters.

This commit is contained in:
Jessica Wang 2013-04-07 00:13:46 -07:00
parent 265cf42ffe
commit b1ef74737a
4 changed files with 33 additions and 28 deletions

View File

@ -52,25 +52,31 @@ Below is a sample login attempt
var clientApiUrl = "/client/api";
var clientConsoleUrl = "/client/console";
$(document).ready(function() {
/*
condition 1: If window.location.href contains parameter 'loginUrl', save the parameter's value to a cookie, then reload the page without any URL parameter.
(After the page is reloaded without any URL parameter, it will fall in condition 2.)
*/
if ($.urlParam('loginUrl') != 0) {
$.cookie('loginUrl', $.urlParam('loginUrl'), { expires: 1});
document.location.href = window.location.href.substring(0, window.location.href.indexOf('?'));
}
$(document).ready(function() {
/*
condition 2: If window.location.href does not contain parameter 'loginUrl' but cookie 'loginUrl' exists,
save the cookie's value to g_regionUrlParam (a global variable for switching regions),
then call login API to set g_loginResponse (a global variable for single-sign-on).
*/
else if($.cookie('loginUrl') != null) {
g_regionUrlParam = '?loginUrl=' + $.cookie('loginUrl');
var url = $.urlParam("loginUrl");
if (url != undefined && url != null && url.length > 0) {
url = unescape(clientApiUrl+"?"+url);
$.ajax({
url: unescape(clientApiUrl + "?" + $.cookie('loginUrl')),
url: url,
dataType: "json",
async: false,
success: function(json) {
g_loginResponse = json.loginresponse;
},
error: function() {
onLogoutCallback();
// This means the login failed. You should redirect to your login page.
},
beforeSend: function(XMLHttpRequest) {
return true;
}
});
}
else if(window.name != null && window.name.indexOf("command=login") != -1) { //from region switching
g_loginCmdText = window.name;
$.ajax({
url: clientApiUrl + "?" + window.name,
dataType: "json",
async: false,
success: function(json) {
@ -85,7 +91,6 @@ $(document).ready(function() {
}
});
}
});

View File

@ -251,12 +251,11 @@
array1.push("&domain=" + encodeURIComponent("/"));
}
g_regionUrlParam = '?loginUrl=' + escape("command=login" + array1.join("") + "&response=json");
$.cookie('loginUrl', escape("command=login" + array1.join("") + "&response=json"), { expires: 1});
g_loginCmdText = "command=login" + array1.join("") + "&response=json";
$.ajax({
type: "POST",
data: "command=login" + array1.join("") + "&response=json",
data: g_loginCmdText,
dataType: "json",
async: false,
success: function(json) {
@ -386,7 +385,8 @@
g_timezoneoffset = null;
g_timezone = null;
g_supportELB = null;
g_regionUrlParam = null;
g_loginCmdText = null;
window.name = '';
$.cookie('JSESSIONID', null);
$.cookie('sessionKey', null);
@ -398,8 +398,7 @@
$.cookie('timezoneoffset', null);
$.cookie('timezone', null);
$.cookie('supportELB', null);
$.cookie('loginUrl', null);
if(onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen.
document.location.reload(); //when onLogoutCallback() returns true, reload the current document.
}
@ -466,7 +465,8 @@
document.title = 'CloudStack';
if ($.cookie('loginUrl') != null || $.urlParam('loginUrl') != 0) {
if ($.urlParam('loginUrl') != 0
||(window.name != null && window.name.indexOf("command=login") != -1)) {
// SSO
loginArgs.hideLoginScreen = true;
}

View File

@ -20,7 +20,7 @@ var g_role = null; // roles - root, domain-admin, ro-admin, user
var g_username = null;
var g_account = null;
var g_domainid = null;
var g_regionUrlParam = null;
var g_loginCmdText = null;
var g_enableLogging = false;
var g_timezoneoffset = null;
var g_timezone = null;

View File

@ -89,8 +89,8 @@
closeRegionSelector({
complete: function() {
$('#container').prepend($('<div>').addClass('loading-overlay'));
document.location.href = url + g_regionUrlParam;
window.name = g_loginCmdText;
document.location.href = url;
}
});
};