From ddd5bb03d00d9fffd21b0c8e3ead93c72ecf9b38 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 7 Dec 2010 10:00:20 -0800 Subject: [PATCH] Creat port forwarding rules has been changed from sync to async --- ui/scripts/cloud.core.ipaddress.js | 82 +++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 19 deletions(-) diff --git a/ui/scripts/cloud.core.ipaddress.js b/ui/scripts/cloud.core.ipaddress.js index cba1bd11db5..f3946dda36f 100644 --- a/ui/scripts/cloud.core.ipaddress.js +++ b/ui/scripts/cloud.core.ipaddress.js @@ -154,25 +154,69 @@ function afterLoadIpJSP() { array1.push("&publicport="+publicPort); array1.push("&protocol="+protocol); array1.push("&virtualmachineid=" + virtualMachineId); - $.ajax({ - data: createURL("command=createPortForwardingRule"+array1.join("")), - dataType: "json", - success: function(json) { - var item = json.createportforwardingruleresponse.portforwardingrule; - portForwardingJsonToTemplate(item,$template); - $spinningWheel.hide(); - refreshCreatePortForwardingRow(); - }, - error: function(XMLHttpResponse) { - handleError(XMLHttpResponse, function() { - $template.slideUp("slow", function() { - $(this).remove(); - }); - var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - $("#dialog_error").text(fromdb(errorMsg)).dialog("open"); - }); - } - }); + + + //??? + $.ajax({ + data: createURL("command=createPortForwardingRule"+array1.join("")), + dataType: "json", + success: function(json) { + var jobId = json.createportforwardingruleresponse.jobid; + var timerKey = "asyncJob_" + jobId; + $("body").everyTime( + 10000, + timerKey, + function() { + $.ajax({ + data: createURL("command=queryAsyncJobResult&jobId="+jobId), + dataType: "json", + success: function(json) { + var result = json.queryasyncjobresultresponse; + if (result.jobstatus == 0) { + return; //Job has not completed + } else { + $("body").stopTime(timerKey); + $spinningWheel.hide(); + if (result.jobstatus == 1) { // Succeeded + var item = json.createportforwardingruleresponse.portforwardingrule; + portForwardingJsonToTemplate(item,$template); + $spinningWheel.hide(); + refreshCreatePortForwardingRow(); + } else if (result.jobstatus == 2) { // Failed + $template.slideUp("slow", function() { + $(this).remove(); + }); + var errorMsg = "Create Port Fowarding Rule action failed. Reason: " + fromdb(result.jobresult.errortext); + $("#dialog_error").text(errorMsg).dialog("open"); + } + } + }, + error: function(XMLHttpResponse) { + $("body").stopTime(timerKey); + handleError(XMLHttpResponse, function() { + $template.slideUp("slow", function() { + $(this).remove(); + }); + var errorMsg = parseXMLHttpResponse(XMLHttpResponse); + $("#dialog_error").text(fromdb(errorMsg)).dialog("open"); + }); + } + }); + }, + 0 + ); + }, + error: function(XMLHttpResponse) { + handleError(XMLHttpResponse, function() { + $template.slideUp("slow", function() { + $(this).remove(); + }); + var errorMsg = parseXMLHttpResponse(XMLHttpResponse); + $("#dialog_error").text(fromdb(errorMsg)).dialog("open"); + }); + } + }); + return false; });