You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by je...@apache.org on 2013/04/07 09:14:40 UTC

git commit: updated refs/heads/master to b1ef747

Updated Branches:
  refs/heads/master 265cf42ff -> b1ef74737


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


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b1ef7473
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b1ef7473
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b1ef7473

Branch: refs/heads/master
Commit: b1ef74737af85997fa250ccbb53089ecb20a65eb
Parents: 265cf42
Author: Jessica Wang <je...@citrix.com>
Authored: Sun Apr 7 00:13:46 2013 -0700
Committer: Jessica Wang <je...@citrix.com>
Committed: Sun Apr 7 00:14:18 2013 -0700

----------------------------------------------------------------------
 ui/scripts/cloud.core.callbacks.js |   41 +++++++++++++++++-------------
 ui/scripts/cloudStack.js           |   14 +++++-----
 ui/scripts/sharedFunctions.js      |    2 +-
 ui/scripts/ui-custom/regions.js    |    4 +-
 4 files changed, 33 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b1ef7473/ui/scripts/cloud.core.callbacks.js
----------------------------------------------------------------------
diff --git a/ui/scripts/cloud.core.callbacks.js b/ui/scripts/cloud.core.callbacks.js
index 1a9e045..a081294 100644
--- a/ui/scripts/cloud.core.callbacks.js
+++ b/ui/scripts/cloud.core.callbacks.js
@@ -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: 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: unescape(clientApiUrl + "?" + $.cookie('loginUrl')),
+			url: clientApiUrl + "?" + window.name,
 			dataType: "json",
 			async: false,
 			success: function(json) {
@@ -85,7 +91,6 @@ $(document).ready(function() {
 			}
 		});
 	}
-	
 });
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b1ef7473/ui/scripts/cloudStack.js
----------------------------------------------------------------------
diff --git a/ui/scripts/cloudStack.js b/ui/scripts/cloudStack.js
index 985627b..499cb83 100644
--- a/ui/scripts/cloudStack.js
+++ b/ui/scripts/cloudStack.js
@@ -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;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b1ef7473/ui/scripts/sharedFunctions.js
----------------------------------------------------------------------
diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js
index dbcb781..86fe7f6 100644
--- a/ui/scripts/sharedFunctions.js
+++ b/ui/scripts/sharedFunctions.js
@@ -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;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b1ef7473/ui/scripts/ui-custom/regions.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui-custom/regions.js b/ui/scripts/ui-custom/regions.js
index 17bc86c..2f61dfd 100644
--- a/ui/scripts/ui-custom/regions.js
+++ b/ui/scripts/ui-custom/regions.js
@@ -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;
         }
       });
     };