mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
new UI - subgrid item actions - code optimization.
This commit is contained in:
parent
768add3488
commit
c68b16154a
@ -1234,7 +1234,7 @@ var vmVolumeActionMap = {
|
||||
isAsyncJob: true,
|
||||
asyncJobResponse: "detachvolumeresponse",
|
||||
inProcessText: "Detaching disk....",
|
||||
afterActionSeccessFn: function(jsonObj, $subgridItem) {
|
||||
afterActionSeccessFn: function(json, id, $subgridItem) {
|
||||
$subgridItem.slideUp("slow", function(){
|
||||
$(this).remove();
|
||||
});
|
||||
@ -1245,7 +1245,7 @@ var vmVolumeActionMap = {
|
||||
asyncJobResponse: "createtemplateresponse",
|
||||
dialogBeforeActionFn : doCreateTemplateFromVmVolume,
|
||||
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.vmstate == "Stopped") {
|
||||
buildActionLinkForSubgridItem("Create Template", vmVolumeActionMap, $actionMenu, volumeListAPIMap, $template);
|
||||
buildActionLinkForSubgridItem("Create Template", vmVolumeActionMap, $actionMenu, $template);
|
||||
noAvailableActions = false;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1328,12 +1328,12 @@ function vmRouterJSONToTemplate(jsonObj, $template) {
|
||||
var noAvailableActions = true;
|
||||
|
||||
if (jsonObj.state == 'Running') {
|
||||
buildActionLinkForSubgridItem("Stop Router", vmRouterActionMap, $actionMenu, routerListAPIMap, $template);
|
||||
buildActionLinkForSubgridItem("Reboot Router", vmRouterActionMap, $actionMenu, routerListAPIMap, $template);
|
||||
buildActionLinkForSubgridItem("Stop Router", vmRouterActionMap, $actionMenu, $template);
|
||||
buildActionLinkForSubgridItem("Reboot Router", vmRouterActionMap, $actionMenu, $template);
|
||||
noAvailableActions = false;
|
||||
}
|
||||
else if (jsonObj.state == 'Stopped') {
|
||||
buildActionLinkForSubgridItem("Start Router", vmRouterActionMap, $actionMenu, routerListAPIMap, $template);
|
||||
buildActionLinkForSubgridItem("Start Router", vmRouterActionMap, $actionMenu, $template);
|
||||
noAvailableActions = false;
|
||||
}
|
||||
|
||||
@ -1386,7 +1386,7 @@ function appendInstanceGroup(groupId, groupName) {
|
||||
$("#leftmenu_instance_group_container").append($leftmenuSubmenuTemplate);
|
||||
}
|
||||
|
||||
function doCreateTemplateFromVmVolume($actionLink, listAPIMap, $subgridItem) {
|
||||
function doCreateTemplateFromVmVolume($actionLink, $subgridItem) {
|
||||
var jsonObj = $subgridItem.data("jsonObj");
|
||||
|
||||
$("#dialog_create_template")
|
||||
@ -1409,7 +1409,7 @@ function doCreateTemplateFromVmVolume($actionLink, listAPIMap, $subgridItem) {
|
||||
|
||||
var id = $subgridItem.data("jsonObj").id;
|
||||
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() {
|
||||
$(this).dialog("close");
|
||||
@ -1418,11 +1418,11 @@ function doCreateTemplateFromVmVolume($actionLink, listAPIMap, $subgridItem) {
|
||||
}
|
||||
|
||||
//***** Routers tab (begin) ***************************************************************************************
|
||||
var routerListAPIMap = {
|
||||
listAPI: "listRouters",
|
||||
listAPIResponse: "listroutersresponse",
|
||||
listAPIResponseObj: "router"
|
||||
};
|
||||
|
||||
function routerAfterSubgridItemAction(json, id, $subgridItem) {
|
||||
var jsonObj = json.queryasyncjobresultresponse.router[0];
|
||||
vmRouterJSONToTemplate(jsonObj, $subgridItem);
|
||||
}
|
||||
|
||||
var vmRouterActionMap = {
|
||||
"Stop Router": {
|
||||
@ -1430,27 +1430,21 @@ var vmRouterActionMap = {
|
||||
isAsyncJob: true,
|
||||
asyncJobResponse: "stoprouterresponse",
|
||||
inProcessText: "Stopping Router....",
|
||||
afterActionSeccessFn: function(jsonObj, $subgridItem) {
|
||||
vmRouterJSONToTemplate(jsonObj, $subgridItem);
|
||||
}
|
||||
afterActionSeccessFn: routerAfterSubgridItemAction
|
||||
},
|
||||
"Start Router": {
|
||||
api: "startRouter",
|
||||
isAsyncJob: true,
|
||||
asyncJobResponse: "startrouterresponse",
|
||||
inProcessText: "Starting Router....",
|
||||
afterActionSeccessFn: function(jsonObj, $subgridItem) {
|
||||
vmRouterJSONToTemplate(jsonObj, $subgridItem);
|
||||
}
|
||||
afterActionSeccessFn: routerAfterSubgridItemAction
|
||||
},
|
||||
"Reboot Router": {
|
||||
api: "rebootRouter",
|
||||
isAsyncJob: true,
|
||||
asyncJobResponse: "rebootrouterresponse",
|
||||
inProcessText: "Rebooting Router....",
|
||||
afterActionSeccessFn: function(jsonObj, $subgridItem) {
|
||||
vmRouterJSONToTemplate(jsonObj, $subgridItem);
|
||||
}
|
||||
afterActionSeccessFn: routerAfterSubgridItemAction
|
||||
}
|
||||
}
|
||||
//***** Routers tab (end) ***************************************************************************************
|
||||
@ -91,30 +91,8 @@ function doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId) {
|
||||
$spinningWheel.hide();
|
||||
if (result.jobstatus == 1) { // Succeeded
|
||||
$("#right_panel_content #after_action_info").text(label + " action succeeded.");
|
||||
$("#right_panel_content #after_action_info_container").removeClass("errorbox").show();
|
||||
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
||||
$("#right_panel_content #after_action_info_container").removeClass("errorbox").show();
|
||||
afterActionSeccessFn(json, id, midmenuItemId);
|
||||
} 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_container").addClass("errorbox").show();
|
||||
@ -146,31 +124,8 @@ function doActionToDetailsTab(id, $actionLink, apiCommand, midmenuItemId) {
|
||||
success: function(json) {
|
||||
$spinningWheel.hide();
|
||||
$("#right_panel_content #after_action_info").text(label + " action succeeded.");
|
||||
$("#right_panel_content #after_action_info_container").removeClass("errorbox").show();
|
||||
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
||||
$("#right_panel_content #after_action_info_container").removeClass("errorbox").show();
|
||||
afterActionSeccessFn(json, id, midmenuItemId);
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleErrorInDetailsTab(XMLHttpResponse, $detailsTab, label);
|
||||
@ -395,7 +350,7 @@ function handleAsyncJobFailInMidMenu(errorMsg, $midmenuItem1) {
|
||||
|
||||
|
||||
//***** 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 $listItem = $("#action_list_item").clone();
|
||||
$actionMenu.find("#action_list").append($listItem.show());
|
||||
@ -416,28 +371,26 @@ function buildActionLinkForSubgridItem(label, actionMap, $actionMenu, listAPIMap
|
||||
var dialogBeforeActionFn = $actionLink.data("dialogBeforeActionFn");
|
||||
if(dialogBeforeActionFn == null) {
|
||||
var apiCommand = "command="+$actionLink.data("api")+"&id="+id;
|
||||
doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem);
|
||||
doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem);
|
||||
}
|
||||
else {
|
||||
dialogBeforeActionFn($actionLink, listAPIMap, $subgridItem);
|
||||
dialogBeforeActionFn($actionLink, $subgridItem);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem) {
|
||||
function doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem) {
|
||||
var label = $actionLink.data("label");
|
||||
var inProcessText = $actionLink.data("inProcessText");
|
||||
var isAsyncJob = $actionLink.data("isAsyncJob");
|
||||
var asyncJobResponse = $actionLink.data("asyncJobResponse");
|
||||
var afterActionSeccessFn = $actionLink.data("afterActionSeccessFn");
|
||||
var listAPI = listAPIMap["listAPI"];
|
||||
var listAPIResponse = listAPIMap["listAPIResponse"];
|
||||
var listAPIResponseObj = listAPIMap["listAPIResponseObj"];
|
||||
|
||||
|
||||
var $spinningWheel = $subgridItem.find("#spinning_wheel");
|
||||
$spinningWheel.find("#description").text(inProcessText);
|
||||
$spinningWheel.show();
|
||||
$spinningWheel.show();
|
||||
$subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").hide();
|
||||
|
||||
//Async job (begin) *****
|
||||
if(isAsyncJob == true) {
|
||||
@ -463,25 +416,8 @@ function doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgrid
|
||||
$spinningWheel.hide();
|
||||
if (result.jobstatus == 1) { // Succeeded
|
||||
$subgridItem.find("#after_action_info").text(label + " action succeeded.");
|
||||
$subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").show();
|
||||
|
||||
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);
|
||||
}
|
||||
$subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").show();
|
||||
afterActionSeccessFn(json, id, $subgridItem);
|
||||
} else if (result.jobstatus == 2) { // Failed
|
||||
$subgridItem.find("#after_action_info").text(label + " action failed. Reason: " + fromdb(result.jobresult));
|
||||
$subgridItem.find("#after_action_info_container").removeClass("success").addClass("error").show();
|
||||
@ -511,27 +447,10 @@ function doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgrid
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(json) {
|
||||
$spinningWheel.hide();
|
||||
if(apiCommand.indexOf("command=delete")!=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) {
|
||||
$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);
|
||||
}
|
||||
$spinningWheel.hide();
|
||||
$subgridItem.find("#after_action_info").text(label + " action succeeded.");
|
||||
$subgridItem.find("#after_action_info_container").removeClass("error").addClass("success").show();
|
||||
afterActionSeccessFn(json, id, $subgridItem);
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleErrorInSubgridItem(XMLHttpResponse, $subgridItem, label);
|
||||
|
||||
@ -491,9 +491,9 @@ function volumeSnapshotJSONToTemplate(jsonObj, template) {
|
||||
var $actionMenu = $actionLink.find("#snapshot_action_menu");
|
||||
$actionMenu.find("#action_list").empty();
|
||||
|
||||
buildActionLinkForSubgridItem("Create Volume", volumeSnapshotActionMap, $actionMenu, snapshotListAPIMap, template);
|
||||
buildActionLinkForSubgridItem("Delete Snapshot", volumeSnapshotActionMap, $actionMenu, snapshotListAPIMap, template);
|
||||
buildActionLinkForSubgridItem("Create Template", volumeSnapshotActionMap, $actionMenu, snapshotListAPIMap, template);
|
||||
buildActionLinkForSubgridItem("Create Volume", volumeSnapshotActionMap, $actionMenu, template);
|
||||
buildActionLinkForSubgridItem("Delete Snapshot", volumeSnapshotActionMap, $actionMenu, template);
|
||||
buildActionLinkForSubgridItem("Create Template", volumeSnapshotActionMap, $actionMenu, template);
|
||||
}
|
||||
|
||||
function volumeClearRightPanel() {
|
||||
@ -862,11 +862,14 @@ var volumeSnapshotActionMap = {
|
||||
asyncJobResponse: "createvolumeresponse",
|
||||
dialogBeforeActionFn : doCreateVolumeFromSnapshotInVolumePage,
|
||||
inProcessText: "Creating Volume....",
|
||||
afterActionSeccessFn: function(jsonObj, $subgridItem) {
|
||||
afterActionSeccessFn: function(json, id, $subgridItem) {
|
||||
//var jsonObj = ???
|
||||
/*
|
||||
var $midmenuItem1 = $("#midmenu_item").clone();
|
||||
$("#midmenu_container").append($midmenuItem1.show());
|
||||
volumeToMidmenu(jsonObj, $midmenuItem1);
|
||||
bindClickToMidMenu($midmenuItem1, volumeToRigntPanel);
|
||||
*/
|
||||
}
|
||||
}
|
||||
,
|
||||
@ -875,8 +878,8 @@ var volumeSnapshotActionMap = {
|
||||
isAsyncJob: true,
|
||||
asyncJobResponse: "deletesnapshotresponse",
|
||||
inProcessText: "Deleting snapshot....",
|
||||
afterActionSeccessFn: function(id) {
|
||||
$("#volume_snapshot_"+id).slideUp("slow", function() {
|
||||
afterActionSeccessFn: function(json, id, $subgridItem) {
|
||||
$subgridItem.slideUp("slow", function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
@ -887,11 +890,11 @@ var volumeSnapshotActionMap = {
|
||||
asyncJobResponse: "createtemplateresponse",
|
||||
dialogBeforeActionFn : doCreateTemplateFromSnapshotInVolumePage,
|
||||
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");
|
||||
|
||||
$("#dialog_add_volume_from_snapshot")
|
||||
@ -909,7 +912,7 @@ function doCreateVolumeFromSnapshotInVolumePage($actionLink, listAPIMap, $subgri
|
||||
|
||||
var id = jsonObj.id;
|
||||
var apiCommand = "command=createVolume&snapshotid="+id+"&name="+fromdb(name);
|
||||
doActionToSubgridItem(id, $actionLink, apiCommand, listAPIMap, $subgridItem);
|
||||
doActionToSubgridItem(id, $actionLink, apiCommand, $subgridItem);
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
@ -917,7 +920,7 @@ function doCreateVolumeFromSnapshotInVolumePage($actionLink, listAPIMap, $subgri
|
||||
}).dialog("open");
|
||||
}
|
||||
|
||||
function doCreateTemplateFromSnapshotInVolumePage($actionLink, listAPIMap, $subgridItem) {
|
||||
function doCreateTemplateFromSnapshotInVolumePage($actionLink, $subgridItem) {
|
||||
var jsonObj = $subgridItem.data("jsonObj");
|
||||
|
||||
$("#dialog_create_template_from_snapshot")
|
||||
@ -938,16 +941,10 @@ function doCreateTemplateFromSnapshotInVolumePage($actionLink, listAPIMap, $subg
|
||||
|
||||
var id = jsonObj.id;
|
||||
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() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
}
|
||||
|
||||
var snapshotListAPIMap = {
|
||||
listAPI: "listSnapshots",
|
||||
listAPIResponse: "listsnapshotsresponse",
|
||||
listAPIResponseObj: "snapshot"
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user