bug 7277: template page - implement "Download Template" action. (merge from 2.2.beta1 branch to master branch)

This commit is contained in:
Jessica Wang 2010-11-23 16:57:26 -08:00
parent 8666fb3fc4
commit b18add1373
3 changed files with 102 additions and 3 deletions

View File

@ -350,6 +350,26 @@
</form>
</div>
</div>
<!-- Download Template Dialog (begin) -->
<div id="dialog_download_template" title="Download Template" style="display: none">
<!--Loading box-->
<div id="spinning_wheel" class="ui_dialog_loaderbox">
<div class="ui_dialog_loader">
</div>
<p>
Generating URL....</p>
</div>
<!--Confirmation msg box-->
<!--Note: for error msg, just have to add error besides everything for eg. add error(class) next to ui_dialog_messagebox error, ui_dialog_msgicon error, ui_dialog_messagebox_text error. -->
<div id="info_container" class="ui_dialog_messagebox error" style="display: none;">
<div id="icon" class="ui_dialog_msgicon error">
</div>
<div id="info" class="ui_dialog_messagebox_text error">
(info)</div>
</div>
</div>
<!-- Download Template Dialog (end) -->
<!-- Add Template Dialog (end) -->
<div id="dialog_confirmation_delete_template_all_zones" title="Confirmation" style="display:none">

View File

@ -1005,6 +1005,10 @@ function bindAndListMidMenuItems($leftmenu, commandString, jsonResponse1, jsonRe
function handleErrorInDialog(XMLHttpResponse, $thisDialog) {
var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
handleErrorInDialog2(errorMsg, $thisDialog);
}
function handleErrorInDialog2(errorMsg, $thisDialog) {
var $infoContainer = $thisDialog.find("#info_container");
if(errorMsg != null && errorMsg.length > 0)

View File

@ -209,6 +209,7 @@ function afterLoadTemplateJSP() {
initDialog("dialog_add_template", 450);
initDialog("dialog_copy_template", 300);
initDialog("dialog_create_vm_from_template", 300);
initDialog("dialog_download_template");
}
function templateGetMidmenuId(jsonObj) {
@ -287,7 +288,7 @@ function templateJsonToDetailsTab() {
var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu");
$actionMenu.find("#action_list").empty();
var noAvailableActions = true;
// action Edit, Copy, Create VM
if ((isUser() && jsonObj.ispublic == true && !(jsonObj.domainid == g_domainid && jsonObj.account == g_account)) || jsonObj.id==DomRTemplateId || jsonObj.isready == false) {
//$("#edit_button").hide();
@ -310,6 +311,9 @@ function templateJsonToDetailsTab() {
noAvailableActions = false;
}
buildActionLinkForTab("Download Template", templateActionMap, $actionMenu, $midmenuItem1, $thisTab);
noAvailableActions = false;
// no available actions
if(noAvailableActions == true) {
$actionMenu.find("#action_list").append($("#no_available_actions").clone().show());
@ -399,7 +403,10 @@ var templateActionMap = {
dialogBeforeActionFn : doCreateVMFromTemplate,
inProcessText: "Creating VM....",
afterActionSeccessFn: function(json, $midmenuItem1, id){}
}
},
"Download Template": {
dialogBeforeActionFn : doDownloadTemplate
}
}
function doEditTemplate($actionLink, $detailsTab, $midmenuItem1) {
@ -625,4 +632,72 @@ function doCreateVMFromTemplate($actionLink, $detailsTab, $midmenuItem1) {
$(this).dialog("close");
}
}).dialog("open");
}
}
function doDownloadTemplate($actionLink, $detailsTab, $midmenuItem1) {
var jsonObj = $detailsTab.data("jsonObj");
var id = jsonObj.id;
var zoneId = jsonObj.zoneid;
var apiCommand = "command=extractTemplate&id="+id+"&zoneid="+zoneId+"&mode=HTTP_DOWNLOAD";
var $dialogDownloadTemplate = $("#dialog_download_template");
$spinningWheel = $dialogDownloadTemplate.find("#spinning_wheel");
$spinningWheel.show();
var $infoContainer = $dialogDownloadTemplate.find("#info_container");
$infoContainer.hide();
$dialogDownloadTemplate
.dialog('option', 'buttons', {
"Close": function() {
$(this).dialog("close");
}
}).dialog("open");
$.ajax({
data: createURL(apiCommand),
dataType: "json",
success: function(json) {
var jobId = json.extracttemplateresponse.jobid;
var timerKey = "asyncJob_" + jobId;
$("body").everyTime(
10000,
timerKey,
function() {
$.ajax({
data: createURL("command=queryAsyncJobResult&jobId="+jobId),
dataType: "json",
success: function(json) {
var result = json.queryasyncjobresultresponse;
if (result.jobstatus == 0) {
return; //Job has not completed
} else {
$("body").stopTime(timerKey);
$spinningWheel.hide();
if (result.jobstatus == 1) { // Succeeded
$infoContainer.find("#info").html("download template succeeded");
$infoContainer.show();
} else if (result.jobstatus == 2) { // Failed
handleErrorInDialog2(fromdb(result.jobresult.errortext), $dialogDownloadTemplate);
}
}
},
error: function(XMLHttpResponse) {
$("body").stopTime(timerKey);
handleError(XMLHttpResponse, function() {
handleErrorInDialog(XMLHttpResponse, $dialogDownloadTemplate);
});
}
});
},
0
);
},
error: function(XMLHttpResponse) {
handleError(XMLHttpResponse, function() {
handleErrorInDialog(XMLHttpResponse, $dialogDownloadTemplate);
});
}
});
//???
}