mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
new UI - create a shared function doAction()
This commit is contained in:
parent
0ad016839b
commit
09b4e2a7e1
@ -19,26 +19,32 @@ function clickInstanceGroupHeader($arrowIcon) {
|
|||||||
stopVirtualMachine: {
|
stopVirtualMachine: {
|
||||||
label: "Stop Instance",
|
label: "Stop Instance",
|
||||||
isAsyncJob: true,
|
isAsyncJob: true,
|
||||||
asyncJobResponse: "stopvirtualmachineresponse"
|
asyncJobResponse: "stopvirtualmachineresponse",
|
||||||
|
afterActionSeccessFn: updateVirtualMachineStateInMidMenu
|
||||||
},
|
},
|
||||||
startVirtualMachine: {
|
startVirtualMachine: {
|
||||||
label: "Start Instance",
|
label: "Start Instance",
|
||||||
isAsyncJob: true,
|
isAsyncJob: true,
|
||||||
asyncJobResponse: "startvirtualmachineresponse"
|
asyncJobResponse: "startvirtualmachineresponse",
|
||||||
|
afterActionSeccessFn: updateVirtualMachineStateInMidMenu
|
||||||
},
|
},
|
||||||
rebootVirtualMachine: {
|
rebootVirtualMachine: {
|
||||||
label: "Reboot Instance",
|
label: "Reboot Instance",
|
||||||
isAsyncJob: true,
|
isAsyncJob: true,
|
||||||
asyncJobResponse: "rebootvirtualmachineresponse"
|
asyncJobResponse: "rebootvirtualmachineresponse",
|
||||||
|
afterActionSeccessFn: updateVirtualMachineStateInMidMenu
|
||||||
|
|
||||||
},
|
},
|
||||||
destroyVirtualMachine: {
|
destroyVirtualMachine: {
|
||||||
label: "Destroy Instance",
|
label: "Destroy Instance",
|
||||||
isAsyncJob: true,
|
isAsyncJob: true,
|
||||||
asyncJobResponse: "destroyvirtualmachineresponse"
|
asyncJobResponse: "destroyvirtualmachineresponse",
|
||||||
|
afterActionSeccessFn: updateVirtualMachineStateInMidMenu
|
||||||
},
|
},
|
||||||
recoverVirtualMachine: {
|
recoverVirtualMachine: {
|
||||||
label: "Restore Instance",
|
label: "Restore Instance",
|
||||||
isAsyncJob: false
|
isAsyncJob: false,
|
||||||
|
afterActionSeccessFn: updateVirtualMachineStateInMidMenu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +57,10 @@ function clickInstanceGroupHeader($arrowIcon) {
|
|||||||
$rightPanelContent.find("#state").text(state).removeClass("green red").addClass("gray");
|
$rightPanelContent.find("#state").text(state).removeClass("green red").addClass("gray");
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVirtualMachineStateInMidMenu(state, midmenuItem) {
|
function updateVirtualMachineStateInMidMenu(jsonObj, midmenuItem) {
|
||||||
if(state == "Running")
|
if(jsonObj.state == "Running")
|
||||||
midmenuItem.find("#status_icon").attr("src", "images/status_green.png");
|
midmenuItem.find("#status_icon").attr("src", "images/status_green.png");
|
||||||
else if(state == "Stopped")
|
else if(jsonObj.state == "Stopped")
|
||||||
midmenuItem.find("#status_icon").attr("src", "images/status_red.png");
|
midmenuItem.find("#status_icon").attr("src", "images/status_red.png");
|
||||||
else //Destroyed, Creating, ~
|
else //Destroyed, Creating, ~
|
||||||
midmenuItem.find("#status_icon").attr("src", "images/status_gray.png");
|
midmenuItem.find("#status_icon").attr("src", "images/status_gray.png");
|
||||||
@ -68,7 +74,7 @@ function clickInstanceGroupHeader($arrowIcon) {
|
|||||||
var vmName = getVmName(instance.name, instance.displayname);
|
var vmName = getVmName(instance.name, instance.displayname);
|
||||||
$midmenuItemVm1.find("#vm_name").text(vmName);
|
$midmenuItemVm1.find("#vm_name").text(vmName);
|
||||||
$midmenuItemVm1.find("#ip_address").text(instance.ipaddress);
|
$midmenuItemVm1.find("#ip_address").text(instance.ipaddress);
|
||||||
updateVirtualMachineStateInMidMenu(instance.state, $midmenuItemVm1);
|
updateVirtualMachineStateInMidMenu(instance, $midmenuItemVm1);
|
||||||
$midmenuItemVm1.bind("click", function(event) {
|
$midmenuItemVm1.bind("click", function(event) {
|
||||||
var $t = $(this);
|
var $t = $(this);
|
||||||
vmMidmenuItemToRightPanel($t);
|
vmMidmenuItemToRightPanel($t);
|
||||||
@ -199,110 +205,14 @@ function clickInstanceGroupHeader($arrowIcon) {
|
|||||||
$link.data("api", api);
|
$link.data("api", api);
|
||||||
$link.data("label", apiInfo.label);
|
$link.data("label", apiInfo.label);
|
||||||
$link.data("isAsyncJob", apiInfo.isAsyncJob);
|
$link.data("isAsyncJob", apiInfo.isAsyncJob);
|
||||||
$link.data("asyncJobResponse", apiInfo.asyncJobResponse);
|
$link.data("asyncJobResponse", apiInfo.asyncJobResponse);
|
||||||
|
$link.data("afterActionSeccessFn", apiInfo.afterActionSeccessFn);
|
||||||
$link.bind("click", function(event) {
|
$link.bind("click", function(event) {
|
||||||
$actionMenu.hide();
|
$actionMenu.hide();
|
||||||
var $t = $(this);
|
var $t = $(this);
|
||||||
var api = $t.data("api");
|
//jobIdMap = {}; //to remove after testing, jessica
|
||||||
var label = $t.data("label");
|
for(var id in selectedItemIds) {
|
||||||
var isAsyncJob = $t.data("isAsyncJob");
|
doAction(id, $t);
|
||||||
var asyncJobResponse = $t.data("asyncJobResponse");
|
|
||||||
var jobIdMap = {};
|
|
||||||
for(var id in selectedItemIds) {
|
|
||||||
var $midmenuItem = $("#midmenuItemVm_"+id);
|
|
||||||
$midmenuItem.find("#content").removeClass("selected").addClass("inaction");
|
|
||||||
$midmenuItem.find("#spinning_wheel").addClass("midmenu_addingloader").show();
|
|
||||||
$midmenuItem.find("#info_icon").hide();
|
|
||||||
//Async job (begin) *****
|
|
||||||
if(isAsyncJob == true) {
|
|
||||||
$.ajax({
|
|
||||||
data: createURL("command="+api+"&id="+id+"&response=json"),
|
|
||||||
dataType: "json",
|
|
||||||
async: false,
|
|
||||||
success: function(json) {
|
|
||||||
var jobId = json[asyncJobResponse].jobid;
|
|
||||||
jobIdMap[jobId] = id;
|
|
||||||
var timerKey = "asyncJob_" + jobId;
|
|
||||||
$("body").everyTime(
|
|
||||||
10000,
|
|
||||||
timerKey,
|
|
||||||
function() {
|
|
||||||
$.ajax({
|
|
||||||
data: createURL("command=queryAsyncJobResult&jobId="+jobId+"&response=json"),
|
|
||||||
dataType: "json",
|
|
||||||
success: function(json) {
|
|
||||||
var result = json.queryasyncjobresultresponse;
|
|
||||||
if (result.jobstatus == 0) {
|
|
||||||
return; //Job has not completed
|
|
||||||
} else {
|
|
||||||
$("body").stopTime(timerKey);
|
|
||||||
var itemId = jobIdMap[jobId];
|
|
||||||
$item = $("#midmenuItemVm_"+itemId);
|
|
||||||
$item.find("#content").removeClass("inaction");
|
|
||||||
$item.find("#spinning_wheel").hide();
|
|
||||||
if (result.jobstatus == 1) { // Succeeded
|
|
||||||
$item.find("#info_icon").removeClass("error").show();
|
|
||||||
$item.data("afterActionInfo", (label + " action succeeded."));
|
|
||||||
if("virtualmachine" in result)
|
|
||||||
updateVirtualMachineStateInMidMenu(result.virtualmachine[0].state, $item);
|
|
||||||
} else if (result.jobstatus == 2) { // Failed
|
|
||||||
$item.find("#info_icon").addClass("error").show();
|
|
||||||
$item.data("afterActionInfo", (label + " action failed. Reason: " + sanitizeXSS(result.jobresult)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(XMLHttpResponse) {
|
|
||||||
$spinningWheel.hide();
|
|
||||||
$("body").stopTime(timerKey);
|
|
||||||
handleError(XMLHttpResponse);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
,
|
|
||||||
error: function(XMLHttpResponse) {
|
|
||||||
$spinningWheel.hide();
|
|
||||||
handleError(XMLHttpResponse);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//Async job (end) *****
|
|
||||||
|
|
||||||
//Sync job (begin) *****
|
|
||||||
else {
|
|
||||||
$.ajax({
|
|
||||||
data: createURL("command="+api+"&id="+id+"&response=json"),
|
|
||||||
dataType: "json",
|
|
||||||
async: false,
|
|
||||||
success: function(json) {
|
|
||||||
$midmenuItem.find("#content").removeClass("inaction");
|
|
||||||
$midmenuItem.find("#spinning_wheel").hide();
|
|
||||||
|
|
||||||
//RecoverVirtualMachine API doesn't return an embedded object on success (Bug 6037)
|
|
||||||
//Before Bug 6037 is fixed, use the temporary solution below.
|
|
||||||
$.ajax({
|
|
||||||
cache: false,
|
|
||||||
data: createURL("command=listVirtualMachines&id="+id+"&response=json"),
|
|
||||||
dataType: "json",
|
|
||||||
async: false,
|
|
||||||
success: function(json) {
|
|
||||||
updateVirtualMachineStateInMidMenu(json.listvirtualmachinesresponse.virtualmachine[0].state, $midmenuItem);
|
|
||||||
$midmenuItem.find("#info_icon").removeClass("error").show();
|
|
||||||
$midmenuItem.data("afterActionInfo", (label + " action succeeded."));
|
|
||||||
},
|
|
||||||
error: function(XMLHttpResponse) {
|
|
||||||
$midmenuItem.find("#info_icon").addClass("error").show();
|
|
||||||
$midmenuItem.data("afterActionInfo", (label + " action failed."));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//After Bug 6037 is fixed, remove temporary solution above and uncomment the line below
|
|
||||||
//updateVirtualMachineStateInMidMenu(json[asyncJobResponse]virtualmachine[0].state, $item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//Sync job (end) *****
|
|
||||||
}
|
}
|
||||||
selectedItemIds = {}; //clear selected items for action
|
selectedItemIds = {}; //clear selected items for action
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -20,6 +20,125 @@
|
|||||||
|
|
||||||
// Version: @VERSION@
|
// Version: @VERSION@
|
||||||
|
|
||||||
|
//var jobIdMap;
|
||||||
|
function doAction(id, $t) {
|
||||||
|
var api = $t.data("api");
|
||||||
|
var label = $t.data("label");
|
||||||
|
var isAsyncJob = $t.data("isAsyncJob");
|
||||||
|
var asyncJobResponse = $t.data("asyncJobResponse");
|
||||||
|
var afterActionSeccessFn = $t.data("afterActionSeccessFn");
|
||||||
|
|
||||||
|
var $midmenuItem = $("#midmenuItemVm_"+id);
|
||||||
|
$midmenuItem.find("#content").removeClass("selected").addClass("inaction");
|
||||||
|
$midmenuItem.find("#spinning_wheel").addClass("midmenu_addingloader").show();
|
||||||
|
$midmenuItem.find("#info_icon").hide();
|
||||||
|
|
||||||
|
//Async job (begin) *****
|
||||||
|
if(isAsyncJob == true) {
|
||||||
|
$.ajax({
|
||||||
|
data: createURL("command="+api+"&id="+id+"&response=json"),
|
||||||
|
dataType: "json",
|
||||||
|
success: function(json) {
|
||||||
|
var jobId = json[asyncJobResponse].jobid;
|
||||||
|
var timerKey = "asyncJob_" + jobId;
|
||||||
|
$("body").everyTime(
|
||||||
|
10000,
|
||||||
|
timerKey,
|
||||||
|
function() {
|
||||||
|
$.ajax({
|
||||||
|
data: createURL("command=queryAsyncJobResult&jobId="+jobId+"&response=json"),
|
||||||
|
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.data("afterActionInfo", (label + " action succeeded."));
|
||||||
|
if("virtualmachine" in result)
|
||||||
|
afterActionSeccessFn(result.virtualmachine[0], $midmenuItem);
|
||||||
|
} else if (result.jobstatus == 2) { // Failed
|
||||||
|
$midmenuItem.find("#info_icon").addClass("error").show();
|
||||||
|
$midmenuItem.data("afterActionInfo", (label + " action failed. Reason: " + sanitizeXSS(result.jobresult)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(XMLHttpResponse) {
|
||||||
|
$("body").stopTime(timerKey);
|
||||||
|
$midmenuItem.find("#content").removeClass("inaction");
|
||||||
|
$midmenuItem.find("#spinning_wheel").hide();
|
||||||
|
$midmenuItem.find("#info_icon").addClass("error").show();
|
||||||
|
$midmenuItem.data("afterActionInfo", (label + " action failed."));
|
||||||
|
handleError(XMLHttpResponse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
0
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error: function(XMLHttpResponse) {
|
||||||
|
$midmenuItem.find("#content").removeClass("inaction");
|
||||||
|
$midmenuItem.find("#spinning_wheel").hide();
|
||||||
|
$midmenuItem.find("#info_icon").addClass("error").show();
|
||||||
|
$midmenuItem.data("afterActionInfo", (label + " action failed."));
|
||||||
|
handleError(XMLHttpResponse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//Async job (end) *****
|
||||||
|
|
||||||
|
//Sync job (begin) *****
|
||||||
|
else {
|
||||||
|
$.ajax({
|
||||||
|
data: createURL("command="+api+"&id="+id+"&response=json"),
|
||||||
|
dataType: "json",
|
||||||
|
async: false,
|
||||||
|
success: function(json) {
|
||||||
|
$midmenuItem.find("#content").removeClass("inaction");
|
||||||
|
$midmenuItem.find("#spinning_wheel").hide();
|
||||||
|
|
||||||
|
//RecoverVirtualMachine API doesn't return an embedded object on success (Bug 6037)
|
||||||
|
//Before Bug 6037 is fixed, use the temporary solution below.
|
||||||
|
$.ajax({
|
||||||
|
cache: false,
|
||||||
|
data: createURL("command=listVirtualMachines&id="+id+"&response=json"),
|
||||||
|
dataType: "json",
|
||||||
|
async: false,
|
||||||
|
success: function(json) {
|
||||||
|
afterActionSeccessFn(json.listvirtualmachinesresponse.virtualmachine[0], $midmenuItem);
|
||||||
|
$midmenuItem.find("#info_icon").removeClass("error").show();
|
||||||
|
$midmenuItem.data("afterActionInfo", (label + " action succeeded."));
|
||||||
|
},
|
||||||
|
error: function(XMLHttpResponse) {
|
||||||
|
$midmenuItem.find("#info_icon").addClass("error").show();
|
||||||
|
$midmenuItem.data("afterActionInfo", (label + " action failed."));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//After Bug 6037 is fixed, remove temporary solution above and uncomment the line below
|
||||||
|
//afterActionSeccessFn(json[asyncJobResponse]virtualmachine[0], $item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//Sync job (end) *****
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var g_mySession = null;
|
var g_mySession = null;
|
||||||
var g_sessionKey = null;
|
var g_sessionKey = null;
|
||||||
var g_role = null; // roles - root, domain-admin, ro-admin, user
|
var g_role = null; // roles - root, domain-admin, ro-admin, user
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user