Updated Branches:
  refs/heads/4.2 a3e086334 -> 63e73ca94

CLOUDSTACK-2989: UI > Networks menu > Add Isolated Network dialog > network 
offering dropdown > populate network offerings whose specifyvlan=false to 
normal user.


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

Branch: refs/heads/4.2
Commit: 63e73ca94e6881f224d8481a62bb1a310861634c
Parents: a3e0863
Author: Jessica Wang <[email protected]>
Authored: Thu Aug 15 14:24:53 2013 -0700
Committer: Jessica Wang <[email protected]>
Committed: Thu Aug 15 14:26:29 2013 -0700

----------------------------------------------------------------------
 ui/scripts/network.js | 113 +++++++++++++++++++++++++--------------------
 1 file changed, 63 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/63e73ca9/ui/scripts/network.js
----------------------------------------------------------------------
diff --git a/ui/scripts/network.js b/ui/scripts/network.js
index a03dc13..568c0a5 100755
--- a/ui/scripts/network.js
+++ b/ui/scripts/network.js
@@ -377,63 +377,76 @@
                                         },
                                         dependsOn: 'zoneId',
                                         docID: 
'helpGuestNetworkNetworkOffering',
-                                        select: function(args) {
-                                            $.ajax({
-                                                url: createURL('listVPCs'),
-                                                data: {
-                                                    listAll: true
-                                                },
-                                                success: function(json) {
-                                                    var items = 
json.listvpcsresponse.vpc;
-                                                    var baseUrl = 
'listNetworkOfferings&zoneid=' + args.zoneId;
-                                                    var listUrl;
-                                                    var data = {
-                                                        guestiptype: 
'Isolated',
-                                                        supportedServices: 
'SourceNat',
-                                                        state: 'Enabled',
-                                                    };
-
-                                                    if (items != null && 
items.length > 0)
-                                                        listUrl = baseUrl;
-                                                    else
-                                                        listUrl = baseUrl + 
'&forVpc=false';
-
-                                                    if (args.context.vpc) {
-                                                        data.forVpc = true;
+                                        select: function(args) {   
+                                            var data = {
+                                               zoneid: args.zoneId,
+                                                guestiptype: 'Isolated',
+                                                supportedServices: 'SourceNat',
+                                                state: 'Enabled',
+                                            };
+                                           
+                                            if ('vpc' in args.context) { 
//from VPC section                                                    
+                                               $.extend(data, {
+                                                       forVpc: true
+                                               });
+                                            }
+                                            else { //from guest network section
+                                               var vpcs;
+                                               $.ajax({
+                                                    url: createURL('listVPCs'),
+                                                    data: {
+                                                        listAll: true
+                                                    },
+                                                    async: false,
+                                                    success: function(json) {  
                                                        
+                                                       vpcs = 
json.listvpcsresponse.vpc;                                                      
 
                                                     }
+                                                });                            
                        
+                                                if (vpcs == null || 
vpcs.length == 0) { //if there is no VPC in the system
+                                                       $.extend(data, {
+                                                               forVpc: false
+                                                       });
+                                                }
+                                            }
 
-                                                    $.ajax({
-                                                        url: 
createURL(listUrl),
-                                                        data: data,
-                                                        success: 
function(json) {
-                                                            
networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
-                                                            
args.$select.change(function() {
-                                                                var $vlan = 
args.$select.closest('form').find('[rel=vlan]');
-                                                                var 
networkOffering = $.grep(
-                                                                    
networkOfferingObjs, function(netoffer) {
-                                                                        return 
netoffer.id == args.$select.val();
-                                                                    }
-                                                                )[0];
-
-                                                                if 
(networkOffering.specifyvlan) {
-                                                                    
$vlan.css('display', 'inline-block');
-                                                                } else {
-                                                                    
$vlan.hide();
-                                                                }
-                                                            });
+                                            if(!isAdmin()) { //normal user is 
not aware of the VLANs in the system, so normal user is not allowed to create 
network with network offerings whose specifyvlan = true 
+                                               $.extend(data, {
+                                                       specifyvlan: false
+                                               });
+                                            }
+                                            
+                                            $.ajax({
+                                                url: 
createURL('listNetworkOfferings'),
+                                                data: data,
+                                                success: function(json) {
+                                                    networkOfferingObjs = 
json.listnetworkofferingsresponse.networkoffering;
+                                                    
args.$select.change(function() {
+                                                        var $vlan = 
args.$select.closest('form').find('[rel=vlan]');
+                                                        var networkOffering = 
$.grep(
+                                                            
networkOfferingObjs, function(netoffer) {
+                                                                return 
netoffer.id == args.$select.val();
+                                                            }
+                                                        )[0];
 
-                                                            
args.response.success({
-                                                                data: 
$.map(networkOfferingObjs, function(zone) {
-                                                                    return {
-                                                                        id: 
zone.id,
-                                                                        
description: zone.name
-                                                                    };
-                                                                })
-                                                            });
+                                                        if 
(networkOffering.specifyvlan) {
+                                                            
$vlan.css('display', 'inline-block');
+                                                        } else {
+                                                            $vlan.hide();
                                                         }
                                                     });
+
+                                                    args.response.success({
+                                                        data: 
$.map(networkOfferingObjs, function(zone) {
+                                                            return {
+                                                                id: zone.id,
+                                                                description: 
zone.name
+                                                            };
+                                                        })
+                                                    });
                                                 }
                                             });
+                                            //???
+                                            
                                         }
                                     },
 

Reply via email to