From 289c433cb920479bd559b51c551be6fa44c1e515 Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Wed, 27 Feb 2013 09:12:25 -0800 Subject: [PATCH] Regions UI: Highlight active region in selector --- ui/scripts/regions.js | 8 ++++++-- ui/scripts/ui-custom/regions.js | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ui/scripts/regions.js b/ui/scripts/regions.js index 6c0da682e18..543c17e06b5 100644 --- a/ui/scripts/regions.js +++ b/ui/scripts/regions.js @@ -23,10 +23,14 @@ $.ajax({ url: createURL('listRegions&listAll=true'), success: function(json) { - var regions = json.listregionsresponse.region + var regions = json.listregionsresponse.region; args.response.success({ - data: regions ? regions : [] + data: regions ? regions : [ + { id: -1, name: '(Default region)' } + ], + activeRegionID: cloudStack.context.users.regionid ? + cloudStack.context.users.regionid : 1 }); } }); diff --git a/ui/scripts/ui-custom/regions.js b/ui/scripts/ui-custom/regions.js index 73b14a78a26..744a9d9ecb3 100644 --- a/ui/scripts/ui-custom/regions.js +++ b/ui/scripts/ui-custom/regions.js @@ -10,12 +10,18 @@ response: { success: function(args) { var data = args.data; + var activeRegionID = args.activeRegionID; $(data).each(function() { var region = this; var $li = $('
  • ').append($('').html(_s(region.name))); $li.data('region-data', region); + + if (region.id == activeRegionID) { + $li.addClass('active'); + } + $regionList.append($li); }); } @@ -62,11 +68,16 @@ $regionList.click(function(event) { var $target = $(event.target); var $li = $target.closest('li'); + var region, url; - if ($li.size()) { - var url = $li.data('region-data').endpoint; + if ($li.size() && !$li.hasClass('active')) { + region = $li.data('region-data'); + url = region.endpoint; + id = region.id; - switchRegion(url); + if (id != '-1') { + switchRegion(url); + } } });