CLOUDSTACK-1065: cloudstack UI - AWS Style Regions - implement region switching 
action triggered by region dropdown on top menu.


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

Branch: refs/heads/marvin_refactor
Commit: 7c5f5c336612ceda59229c09ca16f425ecd933a4
Parents: 37e9c91
Author: Jessica Wang <[email protected]>
Authored: Wed Mar 20 11:58:17 2013 -0700
Committer: Prasanna Santhanam <[email protected]>
Committed: Sun Mar 31 22:02:00 2013 +0530

----------------------------------------------------------------------
 ui/scripts/cloud.core.callbacks.js |   22 ++++++++++----------
 ui/scripts/cloudStack.js           |   17 ++------------
 ui/scripts/ui-custom/regions.js    |   34 +++++++++++-------------------
 3 files changed, 27 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7c5f5c33/ui/scripts/cloud.core.callbacks.js
----------------------------------------------------------------------
diff --git a/ui/scripts/cloud.core.callbacks.js 
b/ui/scripts/cloud.core.callbacks.js
index 1a9e045..19d759e 100644
--- a/ui/scripts/cloud.core.callbacks.js
+++ b/ui/scripts/cloud.core.callbacks.js
@@ -52,29 +52,29 @@ Below is a sample login attempt
 var clientApiUrl = "/client/api";
 var clientConsoleUrl   = "/client/console";
 
-$(document).ready(function() {         
+$(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.) 
+       (After the page is reloaded without any URL parameter, it will fall in 
condition 2.)
        */
-       if ($.urlParam('loginUrl') != 0) {       
+       if ($.urlParam('loginUrl') != 0) {
                $.cookie('loginUrl', $.urlParam('loginUrl'), { expires: 1});
-               document.location.href = window.location.href.substring(0, 
window.location.href.indexOf('?'));  
+         document.location.href = '/client/';
        }
        
-       /* 
-       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), 
+       /*
+       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');               
+       else if($.cookie('loginUrl') != null) {
+         g_regionUrlParam = '?loginUrl=' + $.cookie('loginUrl');
                $.ajax({
                        url: unescape(clientApiUrl + "?" + 
$.cookie('loginUrl')),
                        dataType: "json",
                        async: false,
                        success: function(json) {
-                               g_loginResponse = json.loginresponse;           
                
+                               g_loginResponse = json.loginresponse;
                        },
                        error: function() {
                                onLogoutCallback();
@@ -85,7 +85,7 @@ $(document).ready(function() {
                        }
                });
        }
-       
+
 });
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7c5f5c33/ui/scripts/cloudStack.js
----------------------------------------------------------------------
diff --git a/ui/scripts/cloudStack.js b/ui/scripts/cloudStack.js
index 985627b..51a4deb 100644
--- a/ui/scripts/cloudStack.js
+++ b/ui/scripts/cloudStack.js
@@ -253,7 +253,7 @@
 
                                g_regionUrlParam = '?loginUrl=' + 
escape("command=login" + array1.join("") + "&response=json");
                                $.cookie('loginUrl', escape("command=login" + 
array1.join("") + "&response=json"), { expires: 1});
-                               
+
         $.ajax({
           type: "POST",
           data: "command=login" + array1.join("") + "&response=json",          
                        
@@ -385,9 +385,9 @@
                                                g_domainid = null;      
                                                g_timezoneoffset = null;
                                                g_timezone = null;
-                                               g_supportELB = null;            
                                
+                                               g_supportELB = null;
                                                g_regionUrlParam = null;
-                                               
+
                                                $.cookie('JSESSIONID', null);
                                                $.cookie('sessionKey', null);
                                                $.cookie('username', null);
@@ -456,21 +456,10 @@
             context: cloudStack.context
           });
         });
-
-        window._reloadUI = function() {
-          $('#container').html('');
-          $('#container').cloudStack(window.cloudStack);
-        };
       }
     };
                
     document.title = 'CloudStack';
-
-    if ($.cookie('loginUrl') != null || $.urlParam('loginUrl') != 0) {
-      // SSO
-      loginArgs.hideLoginScreen = true;
-    }
-    
     cloudStack.uiCustom.login(loginArgs);
 
     // Localization

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7c5f5c33/ui/scripts/ui-custom/regions.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui-custom/regions.js b/ui/scripts/ui-custom/regions.js
index 17bc86c..b29d914 100644
--- a/ui/scripts/ui-custom/regions.js
+++ b/ui/scripts/ui-custom/regions.js
@@ -27,33 +27,25 @@
         response: {
           success: function(args) {
             var data = args.data;
-            
-                                               var currentRegion = null;
+            var activeRegionID = args.activeRegionID;
+
             $(data).each(function() {
               var region = this;
               var regionName = region.name;
               var $li = $('<li>').append($('<span>').html(_s(region.name)));
 
               $li.data('region-data', region);
-                                                       
-                                                       /* e.g.
-                                                       region.endpoint == 
"http://localhost:8080/client/"; 
-                                                       document.location.href 
== "http://localhost:8080/client/#"; 
-                                                       */
-                                                       
if(document.location.href.indexOf(region.endpoint) != -1) {                     
                                
-                currentRegion = region;        
-                                                               
$li.addClass('active');
-                                                       }
-                                                                               
                                
-              $regionList.append($li);                                         
        
+
+              if (region.id == activeRegionID) {
+                $li.addClass('active');
+              }
+              
+              $regionSwitcherButton.find('.title')
+                .html(regionName)
+                .attr('title', regionName);
+              
+              $regionList.append($li);
             });
-                                                       
-            if(currentRegion != null)  {                                       
        
-                                                 
$regionSwitcherButton.find('.title').html(_s(currentRegion.name)).attr('title', 
_s(currentRegion.name));   
-            }          
-            else {
-              $regionSwitcherButton.find('.title').html('').attr('title', ''); 
  
-            }                                          
           }
         }
       });
@@ -89,7 +81,7 @@
       closeRegionSelector({
         complete: function() {
           $('#container').prepend($('<div>').addClass('loading-overlay'));
-          
+
           document.location.href = url + g_regionUrlParam;
         }
       });

Reply via email to