bug 10631: cloudStack - Instance page - details tab - add new action "Create Template" when hypervisor is BareMetal.

This commit is contained in:
Jessica Wang 2011-07-27 11:38:39 -07:00
parent 2a8613cdff
commit 609679db2b
2 changed files with 121 additions and 14 deletions

View File

@ -1413,8 +1413,58 @@ dictionary = {
</div>
</div>
<!-- Create template of disk volume dialog (begin) -->
<div id="dialog_create_template" title='<fmt:message key="label.action.create.template" />' style="display: none">
<!-- Create template from VM dialog (begin) -->
<div id="dialog_create_template_from_vm" title='<fmt:message key="label.action.create.template.from.vm" />' style="display: none">
<p>
<fmt:message key="message.vm.create.template.confirm" />
</p>
<div class="dialog_formcontent">
<form action="#" method="post" id="form_acquire">
<ol>
<li>
<label>
<fmt:message key="label.name" />:</label>
<input class="text" type="text" name="create_template_name" id="create_template_name" />
<div id="create_template_name_errormsg" class="dialog_formcontent_errormsg" style="display: none;">
</div>
</li>
<li>
<label>
<fmt:message key="label.display.text" />:</label>
<input class="text" type="text" name="create_template_desc" id="create_template_desc" />
<div id="create_template_desc_errormsg" class="dialog_formcontent_errormsg" style="display: none;">
</div>
</li>
<li>
<label for="create_template_os_type">
<fmt:message key="label.os.type" />:</label>
<select class="select" name="create_template_os_type" id="create_template_os_type">
</select>
</li>
<li>
<label for="create_template_public">
<fmt:message key="label.public" />:</label>
<select class="select" name="create_template_public" id="create_template_public">
<option value="false"><fmt:message key="label.no" /></option>
<option value="true"><fmt:message key="label.yes" /></option>
</select>
</li>
<li>
<label>
<fmt:message key="label.password.enabled" />:</label>
<select class="select" name="create_template_password" id="create_template_password">
<option value="false"><fmt:message key="label.no" /></option>
<option value="true"><fmt:message key="label.yes" /></option>
</select>
</li>
</ol>
</form>
</div>
</div>
<!-- Create template from VM dialog (end) -->
<!-- Create template from volume dialog (begin) -->
<div id="dialog_create_template_from_volume" title='<fmt:message key="label.action.create.template.from.volume" />' style="display: none">
<p>
<fmt:message key="message.volume.create.template.confirm" />
</p>
@ -1461,7 +1511,7 @@ dictionary = {
</form>
</div>
</div>
<!-- Create template of disk volume dialog (end) -->
<!-- Create template from volume dialog (end) -->
<!-- Confirm to stop VM (begin) -->
<div id="dialog_confirmation_stop_vm" title='<fmt:message key="label.confirmation"/>' style="display: none">

View File

@ -140,8 +140,9 @@ function afterLoadInstanceJSP() {
// dialogs
initDialog("dialog_detach_iso_from_vm");
initDialog("dialog_attach_iso");
initDialog("dialog_change_service_offering", 600);
initDialog("dialog_create_template", 400);
initDialog("dialog_change_service_offering", 600);
initDialog("dialog_create_template_from_vm", 400);
initDialog("dialog_create_template_from_volume", 400);
initDialog("dialog_migrate_instance", 600);
initDialog("dialog_confirmation_stop_vm");
@ -156,14 +157,16 @@ function afterLoadInstanceJSP() {
async: false,
success: function(json) {
types = json.listostypesresponse.ostype;
var osTypeDropdown1 = $("#right_panel_content").find("#tab_content_details").find("#ostypename_edit").empty();
var osTypeDropdown2 = $("#dialog_create_template #create_template_os_type").empty();
var osTypeDropdown1 = $("#right_panel_content").find("#tab_content_details").find("#ostypename_edit").empty();
var osTypeDropdown2 = $("#dialog_create_template_from_vm #create_template_os_type").empty();
var osTypeDropdown3 = $("#dialog_create_template_from_volume #create_template_os_type").empty();
if (types != null && types.length > 0) {
for (var i = 0; i < types.length; i++) {
osTypeMap[types[i].id] = fromdb(types[i].description);
var html = "<option value='" + types[i].id + "'>" + fromdb(types[i].description) + "</option>";
osTypeDropdown1.append(html);
osTypeDropdown2.append(html);
osTypeDropdown2.append(html);
osTypeDropdown3.append(html);
}
}
}
@ -1386,7 +1389,14 @@ var vmActionMap = {
var jsonObj = json.changeserviceforvirtualmachineresponse.virtualmachine;
vmToMidmenu(jsonObj, $midmenuItem1);
}
},
},
"label.action.create.template": {
isAsyncJob: true,
asyncJobResponse: "createtemplateresponse",
dialogBeforeActionFn : doCreateTemplateFromVM,
inProcessText: "label.action.create.template.processing",
afterActionSeccessFn: function(json, $midmenuItem1, id) {}
},
"label.action.migrate.instance": {
isAsyncJob: true,
asyncJobResponse: "migratevirtualmachineresponse",
@ -1960,7 +1970,11 @@ function vmBuildActionMenu(jsonObj, $thisTab, $midmenuItem1) {
buildActionLinkForTab("label.action.detach.iso", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
buildActionLinkForTab("label.action.reset.password", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
buildActionLinkForTab("label.action.change.service", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
buildActionLinkForTab("label.action.change.service", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
if(jsonObj.hypervisor == "BareMetal")
buildActionLinkForTab("label.action.create.template", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
noAvailableActions = false;
}
else if (jsonObj.state == 'Stopped') {
@ -1974,7 +1988,11 @@ function vmBuildActionMenu(jsonObj, $thisTab, $midmenuItem1) {
buildActionLinkForTab("label.action.detach.iso", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
buildActionLinkForTab("label.action.reset.password", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
buildActionLinkForTab("label.action.change.service", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
buildActionLinkForTab("label.action.change.service", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
if(jsonObj.hypervisor == "BareMetal")
buildActionLinkForTab("label.action.create.template", vmActionMap, $actionMenu, $midmenuItem1, $thisTab);
noAvailableActions = false;
}
else if (jsonObj.state == 'Error') {
@ -2459,10 +2477,12 @@ function appendInstanceGroup(groupId, groupName) {
$("#leftmenu_instance_group_container").append($leftmenuSubmenuTemplate);
}
function doCreateTemplateFromVmVolume($actionLink, $subgridItem) {
var jsonObj = $subgridItem.data("jsonObj");
function doCreateTemplateFromVmVolume($actionLink, $subgridItem) {
var $dialogCreateTemplate = $("#dialog_create_template_from_volume");
var jsonObj = $subgridItem.data("jsonObj");
$("#dialog_create_template")
$dialogCreateTemplate
.dialog('option', 'buttons', {
"OK": function() {
var thisDialog = $(this);
@ -2491,6 +2511,43 @@ function doCreateTemplateFromVmVolume($actionLink, $subgridItem) {
}
}).dialog("open");
}
function doCreateTemplateFromVM($actionLink, $detailsTab, $midmenuItem1) {
var $dialogCreateTemplate = $("#dialog_create_template_from_vm");
if (getUserPublicTemplateEnabled() == "true" || isAdmin()) {
$dialogCreateTemplate.find("#create_template_public_container").show();
}
var jsonObj = $midmenuItem1.data("jsonObj");
$dialogCreateTemplate
.dialog('option', 'buttons', {
"Create": function() {
var thisDialog = $(this);
thisDialog.dialog("close");
// validate values
var isValid = true;
isValid &= validateString("Name", thisDialog.find("#create_template_name"), thisDialog.find("#create_template_name_errormsg"));
isValid &= validateString("Display Text", thisDialog.find("#create_template_desc"), thisDialog.find("#create_template_desc_errormsg"));
if (!isValid) return;
var name = trim(thisDialog.find("#create_template_name").val());
var desc = trim(thisDialog.find("#create_template_desc").val());
var osType = thisDialog.find("#create_template_os_type").val();
var isPublic = thisDialog.find("#create_template_public").val();
var password = thisDialog.find("#create_template_password").val();
var id = $midmenuItem1.data("jsonObj").id;
var apiCommand = "command=createTemplate&virtualmachineid="+id+"&name="+todb(name)+"&displayText="+todb(desc)+"&osTypeId="+osType+"&isPublic="+isPublic+"&passwordEnabled="+password;
doActionToTab(id, $actionLink, apiCommand, $midmenuItem1, $detailsTab);
},
"Cancel": function() {
$(this).dialog("close");
}
}).dialog("open");
}
function doTakeSnapshotFromVmVolume($actionLink, $subgridItem) {
$("#dialog_confirmation")