From e8a16e052cfc9acd51caf3d849db6ef063ba80d3 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Thu, 23 Sep 2010 16:59:19 -0700 Subject: [PATCH] new UI - snapshots page - implement delete snapshot action. --- ui/new/scripts/cloud.core2.js | 31 ++++++++++++----------- ui/new/scripts/cloud.core2.snapshot.js | 35 ++++++++++++++++++++------ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/ui/new/scripts/cloud.core2.js b/ui/new/scripts/cloud.core2.js index 0508c5f8a88..b73a4614bd4 100644 --- a/ui/new/scripts/cloud.core2.js +++ b/ui/new/scripts/cloud.core2.js @@ -101,20 +101,23 @@ function doActionToDetailsTab(id, $actionLink, apiCommand, listAPIMap) { if (result.jobstatus == 1) { // Succeeded $detailsTab.find("#action_message_box #description").text(label + " action succeeded."); $detailsTab.find("#action_message_box").removeClass("error").show(); - - //DestroyVirtualMachine API doesn't return an embedded object on success (Bug 6041) - //Before Bug 6041 get fixed, use the temporary solution below. - $.ajax({ - cache: false, - data: createURL("command="+listAPI+"&id="+id), - dataType: "json", - success: function(json) { - afterActionSeccessFn(json[listAPIResponse][listAPIResponseObj][0]); - } - }); - //After Bug 6037 is fixed, remove temporary solution above and uncomment the line below - //afterActionSeccessFn(json[listAPIResponse][listAPIResponseObj][0]); - + if(apiCommand.indexOf("command=delete")!=0) { + //DestroyVirtualMachine API doesn't return an embedded object on success (Bug 6041) + //Before Bug 6041 get fixed, use the temporary solution below. + $.ajax({ + cache: false, + data: createURL("command="+listAPI+"&id="+id), + dataType: "json", + success: function(json) { + afterActionSeccessFn(json[listAPIResponse][listAPIResponseObj][0]); + } + }); + //After Bug 6037 is fixed, remove temporary solution above and uncomment the line below + //afterActionSeccessFn(json[listAPIResponse][listAPIResponseObj][0]); + } + else { //apiCommand is deleteXXXXXXX + afterActionSeccessFn(id); + } } else if (result.jobstatus == 2) { // Failed $detailsTab.find("#action_message_box #description").text(label + " action failed. Reason: " + sanitizeXSS(result.jobresult)); $detailsTab.find("#action_message_box").addClass("error").show(); diff --git a/ui/new/scripts/cloud.core2.snapshot.js b/ui/new/scripts/cloud.core2.snapshot.js index 598ceaac4a2..a81be9b0b36 100644 --- a/ui/new/scripts/cloud.core2.snapshot.js +++ b/ui/new/scripts/cloud.core2.snapshot.js @@ -24,9 +24,7 @@ function snapshotToRigntPanel($midmenuItem) { function snapshotJsonToDetailsTab(jsonObj) { var $detailsTab = $("#right_panel_content #tab_content_details"); - $detailsTab.data("jsonObj", jsonObj); - - var $detailsTab = $("#right_panel_content #tab_content_details"); + $detailsTab.data("jsonObj", jsonObj); $detailsTab.find("#id").text(jsonObj.id); $detailsTab.find("#name").text(fromdb(jsonObj.name)); $detailsTab.find("#volume_name").text(fromdb(jsonObj.volumename)); @@ -38,7 +36,19 @@ function snapshotJsonToDetailsTab(jsonObj) { //actions *** var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu"); $actionMenu.find("#action_list").empty(); - buildActionLinkForDetailsTab("Create Volume", snapshotActionMap, $actionMenu, snapshotListAPIMap); + buildActionLinkForDetailsTab("Create Volume", snapshotActionMap, $actionMenu, snapshotListAPIMap); + buildActionLinkForDetailsTab("Delete snapshot", snapshotActionMap, $actionMenu, snapshotListAPIMap); +} + +function snapshotClearRightPanel() { + var $detailsTab = $("#right_panel_content #tab_content_details"); + $detailsTab.find("#id").text(""); + $detailsTab.find("#name").text(""); + $detailsTab.find("#volume_name").text(""); + $detailsTab.find("#interval_type").text(""); + $detailsTab.find("#account").text(""); + $detailsTab.find("#domain").text(""); + $detailsTab.find("#created").text(""); } var snapshotActionMap = { @@ -47,10 +57,21 @@ var snapshotActionMap = { asyncJobResponse: "createvolumeresponse", dialogBeforeActionFn : doCreateVolumeFromSnapshotInSnapshotPage, inProcessText: "Creating Volume....", - afterActionSeccessFn: function(jsonObj) { - + afterActionSeccessFn: function(jsonObj) {} + } + , + "Delete snapshot": { + api: "deleteSnapshot", + isAsyncJob: true, + asyncJobResponse: "deletesnapshotresponse", + inProcessText: "Deleting snapshot....", + afterActionSeccessFn: function(id) { + var $midmenuItem1 = $("#midmenuItem_"+id); + $midmenuItem1.remove(); + clearRightPanel(); + snapshotClearRightPanel(); } - } + } } var snapshotListAPIMap = {