From 5c255089495d1e19d7a7b62070b91dfda99fbe43 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 7 Dec 2010 13:28:05 -0800 Subject: [PATCH] IP address page - optimize code to call listVirtualMachines only once. --- ui/scripts/cloud.core.ipaddress.js | 40 +++++++++++++++++------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/ui/scripts/cloud.core.ipaddress.js b/ui/scripts/cloud.core.ipaddress.js index 993e4b269bb..659f62e1f05 100644 --- a/ui/scripts/cloud.core.ipaddress.js +++ b/ui/scripts/cloud.core.ipaddress.js @@ -889,10 +889,12 @@ function ipJsonToDetailsTab() { if(noAvailableActions == true) { $actionMenu.find("#action_list").append($("#no_available_actions").clone().show()); } - + //populate dropdown var IpDomainid = ipObj.domainid; var IpAccount = ipObj.account; + ipPopulateVMarray(IpDomainid, IpAccount); //popoulate VM array + var $vmSelect = $("#dialog_enable_static_NAT").find("#vm_dropdown").empty(); ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount); @@ -1216,20 +1218,15 @@ function refreshCreatePortForwardingRow() { var $vmSelect = $createPortForwardingRow.find("#vm").empty(); ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount); } - -function ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount) { + +var runningVMs, stoppedVMs; +function ipPopulateVMarray(IpDomainid, IpAccount) { $.ajax({ data: createURL("command=listVirtualMachines&domainid="+IpDomainid+"&account="+IpAccount+"&state=Running"), dataType: "json", async: false, success: function(json) { - var instances = json.listvirtualmachinesresponse.virtualmachine; - if (instances != null && instances.length > 0) { - for (var i = 0; i < instances.length; i++) { - var html = $(""); - $vmSelect.append(html); - } - } + runningVMs = json.listvirtualmachinesresponse.virtualmachine; } }); @@ -1238,15 +1235,24 @@ function ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount) { dataType: "json", async: false, success: function(json) { - var instances = json.listvirtualmachinesresponse.virtualmachine; - if (instances != null && instances.length > 0) { - for (var i = 0; i < instances.length; i++) { - var html = $(""); - $vmSelect.append(html); - } - } + stoppedVMs = json.listvirtualmachinesresponse.virtualmachine; } }); +} + +function ipPopulateVMDropdown($vmSelect, IpDomainid, IpAccount) { + if (runningVMs != null && runningVMs.length > 0) { + for (var i = 0; i < runningVMs.length; i++) { + var html = $(""); + $vmSelect.append(html); + } + } + if (stoppedVMs != null && stoppedVMs.length > 0) { + for (var i = 0; i < stoppedVMs.length; i++) { + var html = $(""); + $vmSelect.append(html); + } + } } //***** Port Forwarding tab (end) **********************************************************************************************************