From a0aa949eda6cbdf7242e1c245ea79c3a688acfc7 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Tue, 5 Oct 2010 17:27:44 -0700 Subject: [PATCH] new UI - VM reset password - fix a bug that spinning wheel don't disappear after action succeeds when it's multiple selection in middle menu. --- ui/new/scripts/cloud.core2.instance.js | 112 +++++++++++++------------ 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/ui/new/scripts/cloud.core2.instance.js b/ui/new/scripts/cloud.core2.instance.js index c58e7696b62..4d7b8f47306 100644 --- a/ui/new/scripts/cloud.core2.instance.js +++ b/ui/new/scripts/cloud.core2.instance.js @@ -831,61 +831,8 @@ function doResetPassword($t, selectedItemsInMidMenu, vmListAPIMap) { $midMenuItem.find("#info_icon").addClass("error").show(); $midMenuItem.data("afterActionInfo", ($t.data("label") + " action failed. Reason: This instance is not using a template that has the password reset feature enabled. If you have forgotten your root password, please contact support.")); continue; - } - var apiCommand = "command=resetPasswordForVirtualMachine&id="+id; - - var $midmenuItem = $("#midmenuItem_"+id); - $midmenuItem.find("#content").removeClass("selected").addClass("inaction"); - $midmenuItem.find("#spinning_wheel").addClass("midmenu_addingloader").show(); - $midmenuItem.find("#info_icon").hide(); - - //??? - $.ajax({ - data: createURL(apiCommand), - dataType: "json", - success: function(json) { - var jobId = json.resetpasswordforvirtualmachineresponse.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); - $midmenuItem.find("#content").removeClass("inaction"); - $midmenuItem.find("#spinning_wheel").hide(); - if (result.jobstatus == 1) { // Succeeded - $midmenuItem.find("#info_icon").removeClass("error").show(); - $midmenuItem.find("#second_row").text("New password: " + result.virtualmachine[0].password); - var afterActionInfo = "Your password has been successfully resetted. Your new password is : " + result.virtualmachine[0].password; - $midmenuItem.data("afterActionInfo", afterActionInfo); - } else if (result.jobstatus == 2) { // Failed - $midmenuItem.find("#info_icon").addClass("error").show(); - $midmenuItem.data("afterActionInfo", (label + " action failed. Reason: " + fromdb(result.jobresult))); - } - } - }, - error: function(XMLHttpResponse) { - $("body").stopTime(timerKey); - handleErrorInMidMenu(XMLHttpResponse, $midmenuItem); - } - }); - }, - 0 - ); - }, - error: function(XMLHttpResponse) { - handleErrorInMidMenu(XMLHttpResponse, $midmenuItem); - } - }); - //??? + } + doResetPassword2(id); } }, "No": function() { @@ -894,6 +841,61 @@ function doResetPassword($t, selectedItemsInMidMenu, vmListAPIMap) { }).dialog("open"); } +function doResetPassword2(id) { + var apiCommand = "command=resetPasswordForVirtualMachine&id="+id; + + var $midmenuItem = $("#midmenuItem_"+id); + $midmenuItem.find("#content").removeClass("selected").addClass("inaction"); + $midmenuItem.find("#spinning_wheel").addClass("midmenu_addingloader").show(); + $midmenuItem.find("#info_icon").hide(); + + $.ajax({ + data: createURL(apiCommand), + dataType: "json", + success: function(json) { + var jobId = json.resetpasswordforvirtualmachineresponse.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); + $midmenuItem.find("#content").removeClass("inaction"); + $midmenuItem.find("#spinning_wheel").hide(); + if (result.jobstatus == 1) { // Succeeded + $midmenuItem.find("#info_icon").removeClass("error").show(); + $midmenuItem.find("#second_row").text("New password: " + result.virtualmachine[0].password); + var afterActionInfo = "Your password has been successfully resetted. Your new password is : " + result.virtualmachine[0].password; + $midmenuItem.data("afterActionInfo", afterActionInfo); + } else if (result.jobstatus == 2) { // Failed + $midmenuItem.find("#info_icon").addClass("error").show(); + $midmenuItem.data("afterActionInfo", (label + " action failed. Reason: " + fromdb(result.jobresult))); + } + } + }, + error: function(XMLHttpResponse) { + $("body").stopTime(timerKey); + handleErrorInMidMenu(XMLHttpResponse, $midmenuItem); + } + }); + }, + 0 + ); + }, + error: function(XMLHttpResponse) { + handleErrorInMidMenu(XMLHttpResponse, $midmenuItem); + } + }); +} + function doChangeName($t, selectedItemsInMidMenu, vmListAPIMap) { $("#dialog_change_name") .dialog('option', 'buttons', {