new UI - instance menu - implement change service action

This commit is contained in:
jessica 2010-08-27 21:08:06 -07:00 committed by unknown
parent 1b78b9cda2
commit 95aee2414e
3 changed files with 100 additions and 6 deletions

View File

@ -597,7 +597,7 @@
<!-- Attach ISO Dialog -->
<div id="dialog_attach_iso" title="Attach ISO" style="display:none">
<p>
Please specify the ISO you wish to attach to your Virtual Instance(s).
Please specify the ISO you wish to attach to virtual instance.
</p>
<div class="dialog_formcontent">
<form action="#" method="post" id="form_acquire">
@ -617,7 +617,7 @@
<!-- Change Name Dialog -->
<div id="dialog_change_name" title="Change Name" style="display:none">
<p>
Please specify the new name you want to change for your Virtual Instance(s).
Please specify the new name you want to change for virtual instance.
</p>
<div class="dialog_formcontent">
<form action="#" method="post" id="form_acquire">
@ -632,4 +632,23 @@
</ol>
</form>
</div>
</div>
<!-- Change Service Offering Dialog -->
<div id="dialog_change_service_offering" title="Change Service Offering" style="display:none">
<p>
After changing service offering, you must restart virtual instance for the new service offering to take effect.
</p>
<div class="dialog_formcontent">
<form action="#" method="post" id="form_acquire">
<ol>
<li>
<label for="user_name">
Service Offering:</label>
<select class="select" name="change_service_offerings" id="change_service_offerings">
</select>
</li>
</ol>
</form>
</div>
</div>

View File

@ -73,6 +73,12 @@ function clickInstanceGroupHeader($arrowIcon) {
isAsyncJob: false,
dialogBeforeActionFn : doChangeName,
afterActionSeccessFn: setMidmenuItemVm
},
"Change Service": {
isAsyncJob: true,
asyncJobResponse: "changeserviceforvirtualmachineresponse",
dialogBeforeActionFn : doChangeService,
afterActionSeccessFn: setMidmenuItemVm
}
}
@ -185,6 +191,47 @@ function clickInstanceGroupHeader($arrowIcon) {
}).dialog("open");
}
function doChangeService($t, selectedItemIds, listAPIMap) {
$.ajax({
//data: createURL("command=listServiceOfferings&VirtualMachineId="+vmId), //can not specifiy VirtualMachineId since we allow multiple-item-selection.
data: createURL("command=listServiceOfferings"), //can not specifiy VirtualMachineId since we support multiple-item-selection.
dataType: "json",
success: function(json) {
var offerings = json.listserviceofferingsresponse.serviceoffering;
var offeringSelect = $("#dialog_change_service_offering #change_service_offerings").empty();
if (offerings != null && offerings.length > 0) {
for (var i = 0; i < offerings.length; i++) {
var option = $("<option value='" + offerings[i].id + "'>" + sanitizeXSS(unescape(offerings[i].displaytext)) + "</option>").data("name", sanitizeXSS(unescape(offerings[i].name)));
offeringSelect.append(option);
}
}
}
});
$("#dialog_change_service_offering")
.dialog('option', 'buttons', {
"Change": function() {
var thisDialog = $(this);
thisDialog.dialog("close");
for(var id in selectedItemIds) {
var $midMenuItem = selectedItemIds[id];
var jsonObj = $midMenuItem.data("jsonObj");
if(jsonObj.state != "Stopped") {
$midMenuItem.find("#info_icon").addClass("error").show();
$midMenuItem.data("afterActionInfo", ($t.data("label") + " action failed. Reason: virtual instance needs to be stopped before you can change its service."));
continue;
}
var apiCommand = "command=changeServiceForVirtualMachine&id="+id+"&serviceOfferingId="+thisDialog.find("#change_service_offerings").val();
doAction(id, $t, apiCommand, listAPIMap);
}
},
"Cancel": function() {
$(this).dialog("close");
}
}).dialog("open");
}
function updateVirtualMachineStateInRightPanel(state) {
@ -389,6 +436,13 @@ function clickInstanceGroupHeader($arrowIcon) {
zIndex: 2000
}));
activateDialog($("#dialog_change_service_offering").dialog({
width: 600,
autoOpen: false,
modal: true,
zIndex: 2000
}));
//***** VM Wizard (begin) ******************************************************************************
$vmPopup = $("#vm_popup");
var $serviceOfferingTemplate = $("#vm_popup_service_offering_template");

View File

@ -86,8 +86,18 @@ function doAction(id, $t, apiCommand, listAPIMap) {
$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);
var errorMsg = "";
if(XMLHttpResponse.responseText != null & XMLHttpResponse.responseText.length > 0) {
var start = XMLHttpResponse.responseText.indexOf("h1") + 3;
var end = XMLHttpResponse.responseText.indexOf("</h1");
errorMsg = XMLHttpResponse.responseText.substring(start, end);
}
if(errorMsg.length > 0)
$midmenuItem.data("afterActionInfo", ((label + " action failed. Reason: " + sanitizeXSS(unescape(errorMsg)))));
else
$midmenuItem.data("afterActionInfo", (label + " action failed."));
//handleError(XMLHttpResponse);
}
});
},
@ -98,8 +108,19 @@ function doAction(id, $t, apiCommand, listAPIMap) {
$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);
$midmenuItem.data("afterActionInfo", (label + " action failed."));
var errorMsg = "";
if(XMLHttpResponse.responseText != null & XMLHttpResponse.responseText.length > 0) {
var start = XMLHttpResponse.responseText.indexOf("h1") + 3;
var end = XMLHttpResponse.responseText.indexOf("</h1");
errorMsg = XMLHttpResponse.responseText.substring(start, end);
}
if(errorMsg.length > 0)
$midmenuItem.data("afterActionInfo", ((label + " action failed. Reason: " + sanitizeXSS(unescape(errorMsg)))));
else
$midmenuItem.data("afterActionInfo", (label + " action failed."));
//handleError(XMLHttpResponse);
}
});
}