new UI - subgrid item actions - code optimization.

This commit is contained in:
Jessica Wang 2010-10-09 00:10:28 -07:00
parent 768add3488
commit c68b16154a
3 changed files with 48 additions and 138 deletions

View File

@ -1234,7 +1234,7 @@ var vmVolumeActionMap = {
isAsyncJob: true, isAsyncJob: true,
asyncJobResponse: "detachvolumeresponse", asyncJobResponse: "detachvolumeresponse",
inProcessText: "Detaching disk....", inProcessText: "Detaching disk....",
afterActionSeccessFn: function(jsonObj, $subgridItem) { afterActionSeccessFn: function(json, id, $subgridItem) {
$subgridItem.slideUp("slow", function(){ $subgridItem.slideUp("slow", function(){
$(this).remove(); $(this).remove();
}); });
@ -1245,7 +1245,7 @@ var vmVolumeActionMap = {
asyncJobResponse: "createtemplateresponse", asyncJobResponse: "createtemplateresponse",
dialogBeforeActionFn : doCreateTemplateFromVmVolume, dialogBeforeActionFn : doCreateTemplateFromVmVolume,
inProcessText: "Creating template....", inProcessText: "Creating template....",
afterActionSeccessFn: function(jsonObj, $subgridItem){} afterActionSeccessFn: function(json, id, $subgridItem) {}
} }
} }
@ -1280,12 +1280,12 @@ function vmVolumeJSONToTemplate(json, $template) {
if(json.type=="ROOT") { //"create template" is allowed(when stopped), "detach disk" is disallowed. if(json.type=="ROOT") { //"create template" is allowed(when stopped), "detach disk" is disallowed.
if (json.vmstate == "Stopped") { if (json.vmstate == "Stopped") {
buildActionLinkForSubgridItem("Create Template", vmVolumeActionMap, $actionMenu, volumeListAPIMap, $template); buildActionLinkForSubgridItem("Create Template", vmVolumeActionMap, $actionMenu, $template);
noAvailableActions = false; noAvailableActions = false;
} }
} }
else { //json.type=="DATADISK": "detach disk" is allowed, "create template" is disallowed. else { //json.type=="DATADISK": "detach disk" is allowed, "create template" is disallowed.
buildActionLinkForSubgridItem("Detach Disk", vmVolumeActionMap, $actionMenu, volumeListAPIMap, $template); buildActionLinkForSubgridItem("Detach Disk", vmVolumeActionMap, $actionMenu, $template);
noAvailableActions = false; noAvailableActions = false;
} }
@ -1328,12 +1328,12 @@ function vmRouterJSONToTemplate(jsonObj, $template) {
var noAvailableActions = true; var noAvailableActions = true;
if (jsonObj.state == 'Running') { if (jsonObj.state == 'Running') {
buildActionLinkForSubgridItem("Stop Router", vmRouterActionMap, $actionMenu, routerListAPIMap, $template); buildActionLinkForSubgridItem("Stop Router", vmRouterActionMap, $actionMenu, $template);
buildActionLinkForSubgridItem("Reboot Router", vmRouterActionMap, $actionMenu, routerListAPIMap, $template); buildActionLinkForSubgridItem("Reboot Router", vmRouterActionMap, $actionMenu, $template);
noAvailableActions = false; noAvailableActions = false;
} }
else if (jsonObj.state == 'Stopped') { else if (jsonObj.state == 'Stopped') {
buildActionLinkForSubgridItem("Start Router", vmRouterActionMap, $actionMenu, routerListAPIMap, $template); buildActionLinkForSubgridItem("Start Router", vmRouterActionMap, $actionMenu, $template);
noAvailableActions = false; noAvailableActions = false;
} }
@ -1386,7 +1386,7 @@ function appendInstanceGroup(groupId, groupName) {
$("#leftmenu_instance_group_container").append($leftmenuSubmenuTemplate); $("#leftmenu_instance_group_container").append($leftmenuSubmenuTemplate);
} }
function doCreateTemplateFromVmVolume($actionLink, listAPIMap, $subgridItem) { function doCreateTemplateFromVmVolume($actionLink, $subgridItem) {
var jsonObj = $subgridItem.data("jsonObj"); var jsonObj = $subgridItem.data("jsonObj");
$("#dialog_create_template") $("#dialog_create_template")
@ -1409,7 +1409,7 @@ function doCreateTemplateFromVmVolume($actionLink, listAPIMap, $subgridItem) {
var id = $subgridItem.data("jsonObj").id; var id = $subgridItem.data("jsonObj").id;
var apiCommand = "command=createTemplate&volumeId="+id+"&name="+todb(name)+"&displayText="+todb(desc)+"&osTypeId="+osType+"&isPublic="+isPublic+"&passwordEnabled="+password; var apiCommand = "command=createTemplate&volumeId="+id+"&name="+todb(name)+"&displayText="+todb(desc)+"&osTypeId="+osType+"&isPublic="+isPublic+"&passwordEnabled="+password;
doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem); doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem);
}, },
"Cancel": function() { "Cancel": function() {
$(this).dialog("close"); $(this).dialog("close");
@ -1418,11 +1418,11 @@ function doCreateTemplateFromVmVolume($actionLink, listAPIMap, $subgridItem) {
} }
//***** Routers tab (begin) *************************************************************************************** //***** Routers tab (begin) ***************************************************************************************
var routerListAPIMap = {
listAPI: "listRouters", function routerAfterSubgridItemAction(json, id, $subgridItem) {
listAPIResponse: "listroutersresponse", var jsonObj = json.queryasyncjobresultresponse.router[0];
listAPIResponseObj: "router" vmRouterJSONToTemplate(jsonObj, $subgridItem);
}; }
var vmRouterActionMap = { var vmRouterActionMap = {
"Stop Router": { "Stop Router": {
@ -1430,27 +1430,21 @@ var vmRouterActionMap = {
isAsyncJob: true, isAsyncJob: true,
asyncJobResponse: "stoprouterresponse", asyncJobResponse: "stoprouterresponse",
inProcessText: "Stopping Router....", inProcessText: "Stopping Router....",
afterActionSeccessFn: function(jsonObj, $subgridItem) { afterActionSeccessFn: routerAfterSubgridItemAction
vmRouterJSONToTemplate(jsonObj, $subgridItem);
}
}, },
"Start Router": { "Start Router": {
api: "startRouter", api: "startRouter",
isAsyncJob: true, isAsyncJob: true,
asyncJobResponse: "startrouterresponse", asyncJobResponse: "startrouterresponse",
inProcessText: "Starting Router....", inProcessText: "Starting Router....",
afterActionSeccessFn: function(jsonObj, $subgridItem) { afterActionSeccessFn: routerAfterSubgridItemAction
vmRouterJSONToTemplate(jsonObj, $subgridItem);
}
}, },
"Reboot Router": { "Reboot Router": {
api: "rebootRouter", api: "rebootRouter",
isAsyncJob: true, isAsyncJob: true,
asyncJobResponse: "rebootrouterresponse", asyncJobResponse: "rebootrouterresponse",
inProcessText: "Rebooting Router....", inProcessText: "Rebooting Router....",
afterActionSeccessFn: function(jsonObj, $subgridItem) { afterActionSeccessFn: routerAfterSubgridItemAction
vmRouterJSONToTemplate(jsonObj, $subgridItem);
}
} }
} }
//***** Routers tab (end) *************************************************************************************** //***** Routers tab (end) ***************************************************************************************

View File

@ -92,29 +92,7 @@ function doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId) {
if (result.jobstatus == 1) { // Succeeded if (result.jobstatus == 1) { // Succeeded
$("#right_panel_content #after_action_info").text(label + " action succeeded."); $("#right_panel_content #after_action_info").text(label + " action succeeded.");
$("#right_panel_content #after_action_info_container").removeClass("errorbox").show(); $("#right_panel_content #after_action_info_container").removeClass("errorbox").show();
afterActionSeccessFn(json, id, midmenuItemId); afterActionSeccessFn(json, id, midmenuItemId);
/*
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(json, id, midmenuItemId);
}
*/
} else if (result.jobstatus == 2) { // Failed } else if (result.jobstatus == 2) { // Failed
$("#right_panel_content #after_action_info").text(label + " action failed. Reason: " + fromdb(result.jobresult)); $("#right_panel_content #after_action_info").text(label + " action failed. Reason: " + fromdb(result.jobresult));
$("#right_panel_content #after_action_info_container").addClass("errorbox").show(); $("#right_panel_content #after_action_info_container").addClass("errorbox").show();
@ -147,30 +125,7 @@ function doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId) {
$spinningWheel.hide(); $spinningWheel.hide();
$("#right_panel_content #after_action_info").text(label + " action succeeded."); $("#right_panel_content #after_action_info").text(label + " action succeeded.");
$("#right_panel_content #after_action_info_container").removeClass("errorbox").show(); $("#right_panel_content #after_action_info_container").removeClass("errorbox").show();
afterActionSeccessFn(json, id, midmenuItemId); afterActionSeccessFn(json, id, midmenuItemId);
/*
if(apiCommand.indexOf("command=delete")!=0 && apiCommand.indexOf("command=disassociateIpAddress")!=0) {
//RecoverVirtualMachine API doesn't return an embedded object on success (Bug 6037)
//Before Bug 6037 get fixed, use the temporary solution below.
$.ajax({
cache: false,
data: createURL("command="+listAPI+"&id="+id),
dataType: "json",
async: false,
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(json, id, midmenuItemId);
}
*/
}, },
error: function(XMLHttpResponse) { error: function(XMLHttpResponse) {
handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label); handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label);
@ -395,7 +350,7 @@ function handleAsyncJobFailInMidMenu(errorMsg, $midmenuItem1) {
//***** actions for a subgrid item in right panel (begin) ************************************************************************ //***** actions for a subgrid item in right panel (begin) ************************************************************************
function buildActionLinkForSubgridItem(label, actionMap, $actionMenu, listAPIMap, $subgridItem) { function buildActionLinkForSubgridItem(label, actionMap, $actionMenu, $subgridItem) {
var apiInfo = actionMap[label]; var apiInfo = actionMap[label];
var $listItem = $("#action_list_item").clone(); var $listItem = $("#action_list_item").clone();
$actionMenu.find("#action_list").append($listItem.show()); $actionMenu.find("#action_list").append($listItem.show());
@ -416,28 +371,26 @@ function buildActionLinkForSubgridItem(label, actionMap, $actionMenu, listAPIMap
var dialogBeforeActionFn = $actionLink.data("dialogBeforeActionFn"); var dialogBeforeActionFn = $actionLink.data("dialogBeforeActionFn");
if(dialogBeforeActionFn == null) { if(dialogBeforeActionFn == null) {
var apiCommand = "command="+$actionLink.data("api")+"&id="+id; var apiCommand = "command="+$actionLink.data("api")+"&id="+id;
doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem); doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem);
} }
else { else {
dialogBeforeActionFn($actionLink, listAPIMap, $subgridItem); dialogBeforeActionFn($actionLink, $subgridItem);
} }
return false; return false;
}); });
} }
function doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem) { function doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem) {
var label = $actionLink.data("label"); var label = $actionLink.data("label");
var inProcessText = $actionLink.data("inProcessText"); var inProcessText = $actionLink.data("inProcessText");
var isAsyncJob = $actionLink.data("isAsyncJob"); var isAsyncJob = $actionLink.data("isAsyncJob");
var asyncJobResponse = $actionLink.data("asyncJobResponse"); var asyncJobResponse = $actionLink.data("asyncJobResponse");
var afterActionSeccessFn = $actionLink.data("afterActionSeccessFn"); var afterActionSeccessFn = $actionLink.data("afterActionSeccessFn");
var listAPI = listAPIMap["listAPI"];
var listAPIResponse = listAPIMap["listAPIResponse"];
var listAPIResponseObj = listAPIMap["listAPIResponseObj"];
var $spinningWheel = $subgridItem.find("#spinning_wheel"); var $spinningWheel = $subgridItem.find("#spinning_wheel");
$spinningWheel.find("#description").text(inProcessText); $spinningWheel.find("#description").text(inProcessText);
$spinningWheel.show(); $spinningWheel.show();
$subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").hide();
//Async job (begin) ***** //Async job (begin) *****
if(isAsyncJob == true) { if(isAsyncJob == true) {
@ -464,24 +417,7 @@ function doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgrid
if (result.jobstatus == 1) { // Succeeded if (result.jobstatus == 1) { // Succeeded
$subgridItem.find("#after_action_info").text(label + " action succeeded."); $subgridItem.find("#after_action_info").text(label + " action succeeded.");
$subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").show(); $subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").show();
afterActionSeccessFn(json, id, $subgridItem);
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], $subgridItem);
}
});
//After Bug 6037 is fixed, remove temporary solution above and uncomment the line below
//afterActionSeccessFn(json[listAPIResponse][listAPIResponseObj][0], $subgridItem);
}
else { //apiCommand is deleteXXXXXXX
afterActionSeccessFn(id);
}
} else if (result.jobstatus == 2) { // Failed } else if (result.jobstatus == 2) { // Failed
$subgridItem.find("#after_action_info").text(label + " action failed. Reason: " + fromdb(result.jobresult)); $subgridItem.find("#after_action_info").text(label + " action failed. Reason: " + fromdb(result.jobresult));
$subgridItem.find("#after_action_info_container").removeClass("success").addClass("error").show(); $subgridItem.find("#after_action_info_container").removeClass("success").addClass("error").show();
@ -512,26 +448,9 @@ function doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgrid
async: false, async: false,
success: function(json) { success: function(json) {
$spinningWheel.hide(); $spinningWheel.hide();
if(apiCommand.indexOf("command=delete")!=0) { $subgridItem.find("#after_action_info").text(label + " action succeeded.");
//RecoverVirtualMachine API doesn't return an embedded object on success (Bug 6037) $subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").show();
//Before Bug 6037 get fixed, use the temporary solution below. afterActionSeccessFn(json, id, $subgridItem);
$.ajax({
cache: false,
data: createURL("command="+listAPI+"&id="+id),
dataType: "json",
async: false,
success: function(json) {
$subgridItem.find("#after_action_info").text(label + " action succeeded.");
$subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").show();
afterActionSeccessFn(json[listAPIResponse][listAPIResponseObj][0], $subgridItem);
}
});
//After Bug 6037 is fixed, remove temporary solution above and uncomment the line below
//afterActionSeccessFn(json[listAPIResponse][listAPIResponseObj][0], $subgridItem);
}
else { //apiCommand is deleteXXXXXXX
afterActionSeccessFn(id);
}
}, },
error: function(XMLHttpResponse) { error: function(XMLHttpResponse) {
handleErrorInSubgridItem(XMLHttpResponse, $subgridItem, label); handleErrorInSubgridItem(XMLHttpResponse, $subgridItem, label);

View File

@ -491,9 +491,9 @@ function volumeSnapshotJSONToTemplate(jsonObj, template) {
var $actionMenu = $actionLink.find("#snapshot_action_menu"); var $actionMenu = $actionLink.find("#snapshot_action_menu");
$actionMenu.find("#action_list").empty(); $actionMenu.find("#action_list").empty();
buildActionLinkForSubgridItem("Create Volume", volumeSnapshotActionMap, $actionMenu, snapshotListAPIMap, template); buildActionLinkForSubgridItem("Create Volume", volumeSnapshotActionMap, $actionMenu, template);
buildActionLinkForSubgridItem("Delete Snapshot", volumeSnapshotActionMap, $actionMenu, snapshotListAPIMap, template); buildActionLinkForSubgridItem("Delete Snapshot", volumeSnapshotActionMap, $actionMenu, template);
buildActionLinkForSubgridItem("Create Template", volumeSnapshotActionMap, $actionMenu, snapshotListAPIMap, template); buildActionLinkForSubgridItem("Create Template", volumeSnapshotActionMap, $actionMenu, template);
} }
function volumeClearRightPanel() { function volumeClearRightPanel() {
@ -862,11 +862,14 @@ var volumeSnapshotActionMap = {
asyncJobResponse: "createvolumeresponse", asyncJobResponse: "createvolumeresponse",
dialogBeforeActionFn : doCreateVolumeFromSnapshotInVolumePage, dialogBeforeActionFn : doCreateVolumeFromSnapshotInVolumePage,
inProcessText: "Creating Volume....", inProcessText: "Creating Volume....",
afterActionSeccessFn: function(jsonObj, $subgridItem) { afterActionSeccessFn: function(json, id, $subgridItem) {
//var jsonObj = ???
/*
var $midmenuItem1 = $("#midmenu_item").clone(); var $midmenuItem1 = $("#midmenu_item").clone();
$("#midmenu_container").append($midmenuItem1.show()); $("#midmenu_container").append($midmenuItem1.show());
volumeToMidmenu(jsonObj, $midmenuItem1); volumeToMidmenu(jsonObj, $midmenuItem1);
bindClickToMidMenu($midmenuItem1, volumeToRigntPanel); bindClickToMidMenu($midmenuItem1, volumeToRigntPanel);
*/
} }
} }
, ,
@ -875,8 +878,8 @@ var volumeSnapshotActionMap = {
isAsyncJob: true, isAsyncJob: true,
asyncJobResponse: "deletesnapshotresponse", asyncJobResponse: "deletesnapshotresponse",
inProcessText: "Deleting snapshot....", inProcessText: "Deleting snapshot....",
afterActionSeccessFn: function(id) { afterActionSeccessFn: function(json, id, $subgridItem) {
$("#volume_snapshot_"+id).slideUp("slow", function() { $subgridItem.slideUp("slow", function() {
$(this).remove(); $(this).remove();
}); });
} }
@ -887,11 +890,11 @@ var volumeSnapshotActionMap = {
asyncJobResponse: "createtemplateresponse", asyncJobResponse: "createtemplateresponse",
dialogBeforeActionFn : doCreateTemplateFromSnapshotInVolumePage, dialogBeforeActionFn : doCreateTemplateFromSnapshotInVolumePage,
inProcessText: "Creating Template....", inProcessText: "Creating Template....",
afterActionSeccessFn: function(jsonObj, $subgridItem) {} afterActionSeccessFn: function(json, id, $subgridItem) {}
} }
} }
function doCreateVolumeFromSnapshotInVolumePage($actionLink, listAPIMap, $subgridItem) { function doCreateVolumeFromSnapshotInVolumePage($actionLink, $subgridItem) {
var jsonObj = $subgridItem.data("jsonObj"); var jsonObj = $subgridItem.data("jsonObj");
$("#dialog_add_volume_from_snapshot") $("#dialog_add_volume_from_snapshot")
@ -909,7 +912,7 @@ function doCreateVolumeFromSnapshotInVolumePage($actionLink, listAPIMap, $subgri
var id = jsonObj.id; var id = jsonObj.id;
var apiCommand = "command=createVolume&snapshotid="+id+"&name="+fromdb(name); var apiCommand = "command=createVolume&snapshotid="+id+"&name="+fromdb(name);
doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem); doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem);
}, },
"Cancel": function() { "Cancel": function() {
$(this).dialog("close"); $(this).dialog("close");
@ -917,7 +920,7 @@ function doCreateVolumeFromSnapshotInVolumePage($actionLink, listAPIMap, $subgri
}).dialog("open"); }).dialog("open");
} }
function doCreateTemplateFromSnapshotInVolumePage($actionLink, listAPIMap, $subgridItem) { function doCreateTemplateFromSnapshotInVolumePage($actionLink, $subgridItem) {
var jsonObj = $subgridItem.data("jsonObj"); var jsonObj = $subgridItem.data("jsonObj");
$("#dialog_create_template_from_snapshot") $("#dialog_create_template_from_snapshot")
@ -938,16 +941,10 @@ function doCreateTemplateFromSnapshotInVolumePage($actionLink, listAPIMap, $subg
var id = jsonObj.id; var id = jsonObj.id;
var apiCommand = "command=createTemplate&snapshotid="+id+"&name="+todb(name)+"&displaytext="+todb(displayText)+"&ostypeid="+osTypeId+"&passwordEnabled="+password; var apiCommand = "command=createTemplate&snapshotid="+id+"&name="+todb(name)+"&displaytext="+todb(displayText)+"&ostypeid="+osTypeId+"&passwordEnabled="+password;
doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem); doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem);
}, },
"Cancel": function() { "Cancel": function() {
$(this).dialog("close"); $(this).dialog("close");
} }
}).dialog("open"); }).dialog("open");
} }
var snapshotListAPIMap = {
listAPI: "listSnapshots",
listAPIResponse: "listsnapshotsresponse",
listAPIResponseObj: "snapshot"
};