From bcaa706197fd342f75b27a03ae0478224a1ec7e5 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Thu, 19 Jul 2012 11:20:42 -0700 Subject: [PATCH] cloudstack 3.0 UI - call getExtaPropertiesForIpObj() to get extra properties for IP Address object when every time it's refreshed by listPublicIpAddresses API call. --- ui/scripts/network.js | 138 +++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 68 deletions(-) diff --git a/ui/scripts/network.js b/ui/scripts/network.js index 6a3c9a4a2df..3a5df98421e 100644 --- a/ui/scripts/network.js +++ b/ui/scripts/network.js @@ -44,7 +44,7 @@ item.issystem == true ) { return []; } - + if(item.networkOfferingConserveMode == false) { /* (1) If IP is SourceNat, no StaticNat/VPN/PortForwarding/LoadBalancer can be enabled/added. @@ -1177,14 +1177,10 @@ async: true, success: function(json) { var items = json.listpublicipaddressesresponse.publicipaddress; - var processedItems = 0; - - if (!items) { - args.response.success({ - data: [] - }); - return; - } + + $(items).each(function() { + getExtaPropertiesForIpObj(this, args); + }); args.response.success({ actionFilter: actionFilters.ipAddress, @@ -1634,51 +1630,9 @@ dataType: "json", async: true, success: function(json) { - var ipObj = json.listpublicipaddressesresponse.publicipaddress[0]; - - if('networks' in args.context) { //from Guest Network section - //get ipObj.networkOfferingConserveMode and ipObj.networkOfferingHavingVpnService from guest network's network offering - $.ajax({ - url: createURL('listNetworkOfferings'), - data: { - id: args.context.networks[0].networkofferingid - }, - async: false, - success: function(json) { - var networkOfferingObj = json.listnetworkofferingsresponse.networkoffering[0]; - ipObj.networkOfferingConserveMode = networkOfferingObj.conservemode; - - $(networkOfferingObj.service).each(function(){ - var thisService = this; - if(thisService.name == "Vpn") - ipObj.networkOfferingHavingVpnService = true; - }); - - if(ipObj.networkOfferingHavingVpnService == true) { - $.ajax({ - url: createURL('listRemoteAccessVpns'), - data: { - listAll: true, - publicipid: ipObj.id - }, - async: false, - success: function(vpnResponse) { - var isVPNEnabled = vpnResponse.listremoteaccessvpnsresponse.count; - if (isVPNEnabled) { - ipObj.vpnenabled = true; - ipObj.remoteaccessvpn = vpnResponse.listremoteaccessvpnsresponse.remoteaccessvpn[0]; - }; - } - }); - } - } - }); - } - else { //from VPC section - ipObj.networkOfferingConserveMode = false; //conserve mode of IP in VPC is always off, so hardcode it as false - ipObj.networkOfferingHavingVpnService = false; //VPN is not supported in IP in VPC, so hardcode it as false - } - + var ipObj = json.listpublicipaddressesresponse.publicipaddress[0]; + getExtaPropertiesForIpObj(ipObj, args); + args.response.success({ actionFilter: actionFilters.ipAddress, data: ipObj @@ -1694,7 +1648,7 @@ ipRules: { //Configuration tab title: 'label.configuration', custom: cloudStack.ipRules({ - preFilter: function(args) { + preFilter: function(args) { var disallowedActions = []; if (args.context.ipAddresses[0].isstaticnat) disallowedActions.push("nonStaticNATChart"); //tell ipRules widget to show staticNAT chart instead of non-staticNAT chart. @@ -1981,11 +1935,12 @@ }, dataType: 'json', async: true, - success: function(data) { - var ipAddress = data.listpublicipaddressesresponse.publicipaddress[0]; - + success: function(data) { + var ipObj = data.listpublicipaddressesresponse.publicipaddress[0]; + getExtaPropertiesForIpObj(ipObj, args); + args.response.success({ - data: ipAddress + data: ipObj }); }, error: function(data) { @@ -2557,12 +2512,13 @@ id: args.context.ipAddresses[0].id, listAll: true }, - success: function(json) { - var item = json.listpublicipaddressesresponse.publicipaddress[0]; - + success: function(json) { + var ipObj = json.listpublicipaddressesresponse.publicipaddress[0]; + getExtaPropertiesForIpObj(ipObj, args); + args.context.ipAddresses.shift(); //remove the first element in args.context.ipAddresses - args.context.ipAddresses.push(item); - + args.context.ipAddresses.push(ipObj); + var $headerFields = $multi.find('.header-fields'); if ('vpc' in args.context) { if(args.context.ipAddresses[0].associatednetworkid == null) { @@ -2837,11 +2793,12 @@ listAll: true }, success: function(json) { - var item = json.listpublicipaddressesresponse.publicipaddress[0]; + var ipObj = json.listpublicipaddressesresponse.publicipaddress[0]; + getExtaPropertiesForIpObj(ipObj, args); args.context.ipAddresses.shift(); //remove the first element in args.context.ipAddresses - args.context.ipAddresses.push(item); - + args.context.ipAddresses.push(ipObj); + var $headerFields = $multi.find('.header-fields'); if ('vpc' in args.context) { if(args.context.ipAddresses[0].associatednetworkid == null) { @@ -3809,5 +3766,50 @@ } } }; - + + function getExtaPropertiesForIpObj(ipObj, args){ + if('networks' in args.context) { //from Guest Network section + //get ipObj.networkOfferingConserveMode and ipObj.networkOfferingHavingVpnService from guest network's network offering + $.ajax({ + url: createURL('listNetworkOfferings'), + data: { + id: args.context.networks[0].networkofferingid + }, + async: false, + success: function(json) { + var networkOfferingObj = json.listnetworkofferingsresponse.networkoffering[0]; + ipObj.networkOfferingConserveMode = networkOfferingObj.conservemode; + + $(networkOfferingObj.service).each(function(){ + var thisService = this; + if(thisService.name == "Vpn") + ipObj.networkOfferingHavingVpnService = true; + }); + + if(ipObj.networkOfferingHavingVpnService == true) { + $.ajax({ + url: createURL('listRemoteAccessVpns'), + data: { + listAll: true, + publicipid: ipObj.id + }, + async: false, + success: function(vpnResponse) { + var isVPNEnabled = vpnResponse.listremoteaccessvpnsresponse.count; + if (isVPNEnabled) { + ipObj.vpnenabled = true; + ipObj.remoteaccessvpn = vpnResponse.listremoteaccessvpnsresponse.remoteaccessvpn[0]; + }; + } + }); + } + } + }); + } + else { //from VPC section + ipObj.networkOfferingConserveMode = false; //conserve mode of IP in VPC is always off, so hardcode it as false + ipObj.networkOfferingHavingVpnService = false; //VPN is not supported in IP in VPC, so hardcode it as false + } + } + })(cloudStack, jQuery);