diff --git a/ui/new/jsp/snapshot.jsp b/ui/new/jsp/snapshot.jsp index 5b53579b6a8..cf339d8f150 100644 --- a/ui/new/jsp/snapshot.jsp +++ b/ui/new/jsp/snapshot.jsp @@ -141,3 +141,36 @@ + + + + diff --git a/ui/new/scripts/cloud.core2.snapshot.js b/ui/new/scripts/cloud.core2.snapshot.js index a81be9b0b36..89474815ae6 100644 --- a/ui/new/scripts/cloud.core2.snapshot.js +++ b/ui/new/scripts/cloud.core2.snapshot.js @@ -1,9 +1,32 @@ function afterLoadSnapshotJSP() { + //initialize dialog activateDialog($("#dialog_add_volume_from_snapshot").dialog({ autoOpen: false, modal: true, zIndex: 2000 - })); + })); + activateDialog($("#dialog_create_template_from_snapshot").dialog({ + width: 400, + autoOpen: false, + modal: true, + zIndex: 2000 + })); + + //populate dropdown + $.ajax({ + data: createURL("command=listOsTypes"), + dataType: "json", + success: function(json) { + types = json.listostypesresponse.ostype; + if (types != null && types.length > 0) { + var osTypeField = $("#dialog_create_template_from_snapshot").find("#os_type").empty(); + for (var i = 0; i < types.length; i++) { + var html = ""; + osTypeField.append(html); + } + } + } + }); } function snapshotToMidmenu(jsonObj, $midmenuItem1) { @@ -37,7 +60,8 @@ function snapshotJsonToDetailsTab(jsonObj) { var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu"); $actionMenu.find("#action_list").empty(); buildActionLinkForDetailsTab("Create Volume", snapshotActionMap, $actionMenu, snapshotListAPIMap); - buildActionLinkForDetailsTab("Delete snapshot", snapshotActionMap, $actionMenu, snapshotListAPIMap); + buildActionLinkForDetailsTab("Delete Snapshot", snapshotActionMap, $actionMenu, snapshotListAPIMap); + buildActionLinkForDetailsTab("Create Template", snapshotActionMap, $actionMenu, snapshotListAPIMap); } function snapshotClearRightPanel() { @@ -60,7 +84,7 @@ var snapshotActionMap = { afterActionSeccessFn: function(jsonObj) {} } , - "Delete snapshot": { + "Delete Snapshot": { api: "deleteSnapshot", isAsyncJob: true, asyncJobResponse: "deletesnapshotresponse", @@ -72,6 +96,14 @@ var snapshotActionMap = { snapshotClearRightPanel(); } } + , + "Create Template": { + isAsyncJob: true, + asyncJobResponse: "createtemplateresponse", + dialogBeforeActionFn : doCreateTemplateFromSnapshotInSnapshotPage, + inProcessText: "Creating Template....", + afterActionSeccessFn: function(jsonObj) {} + } } var snapshotListAPIMap = { @@ -104,4 +136,33 @@ function doCreateVolumeFromSnapshotInSnapshotPage($actionLink, listAPIMap, $deta $(this).dialog("close"); } }).dialog("open"); +} + +function doCreateTemplateFromSnapshotInSnapshotPage($actionLink, listAPIMap, $detailsTab) { + var jsonObj = $detailsTab.data("jsonObj"); + + $("#dialog_create_template_from_snapshot") + .dialog("option", "buttons", { + "Add": function() { + var thisDialog = $(this); + var isValid = true; + isValid &= validateString("Name", thisDialog.find("#name"), thisDialog.find("#name_errormsg"), false); + isValid &= validateString("Display Text", thisDialog.find("#display_text"), thisDialog.find("#display_text_errormsg"), false); + if (!isValid) return; + + thisDialog.dialog("close"); + + var name = thisDialog.find("#name").val(); + var displayText = thisDialog.find("#display_text").val(); + var osTypeId = thisDialog.find("#os_type").val(); + var password = thisDialog.find("#password").val(); + + var id = jsonObj.id; + var apiCommand = "command=createTemplate&snapshotid="+id+"&name="+name+"&displaytext="+displayText+"&ostypeid="+osTypeId+"&passwordEnabled="+password; + doActionToDetailsTab(id, $actionLink, apiCommand, listAPIMap); + }, + "Cancel": function() { + $(this).dialog("close"); + } + }).dialog("open"); } \ No newline at end of file