1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Improve import dialog

This commit is contained in:
Daniel Molina 2014-04-16 17:02:21 +02:00
parent 3b716e53eb
commit 0a90be018c
4 changed files with 346 additions and 162 deletions

View File

@ -246,14 +246,9 @@ var image_actions = {
call: OpenNebula.Image.create,
callback: function(request, response){
addImageElement(request, response);
if (typeof($appmarket_import_dialog) !== 'undefined' ||
typeof($marketplace_import_dialog) !== 'undefined') {
$create_image_dialog.trigger('close');
} else {
$create_image_dialog.foundation('reveal', 'close');
$create_image_dialog.empty();
setupCreateImageDialog();
}
$create_image_dialog.foundation('reveal', 'close');
$create_image_dialog.empty();
setupCreateImageDialog();
notifyCustom(tr("Image created"), " ID: " + response.IMAGE.ID, false)
},
error: onError

View File

@ -47,133 +47,263 @@ var market_actions = {
type: "multiple",
elements: marketplaceElements,
call: OpenNebula.Marketplace.show,
callback: function(request,response){
if (response['status'] && response['status'] != 'ready') {
callback: function(request,appliance){
if (appliance['status'] && appliance['status'] != 'ready') {
notifyError(tr("The appliance is not ready"));
return;
}
if ($('#marketplace_import_dialog',dialogs_context) != undefined) {
$('#marketplace_import_dialog',dialogs_context).remove();
if ($('#market_import_dialog',dialogs_context) != undefined) {
$('#market_import_dialog',dialogs_context).remove();
}
dialogs_context.append(marketplace_import_dialog);
$marketplace_import_dialog = $('#marketplace_import_dialog',dialogs_context);
$marketplace_import_dialog.addClass("reveal-modal large max-height").attr("data-reveal", "");
$marketplace_import_dialog = $('#market_import_dialog',dialogs_context);
$marketplace_import_dialog.addClass("reveal-modal medium").attr("data-reveal", "");
var tab_id = 1;
//var tab_id = 1;
$('<div class="row">'+
'<div class="large-12 columns">'+
'<p style="font-size:14px">'+
tr("The following images will be created in OpenNebula.")+ ' '+
tr("If you want to edit parameters of the image you can do it later in the images tab")+ ' '+
'</p>'+
'</div>'+
'</div>').appendTo($("#market_import_dialog_content"));
$.each(response['files'], function(index, value){
// Append the new div containing the tab and add the tab to the list
var image_dialog = $('<div id="Tab'+tab_id+'" class="content disk wizard_internal_tab">'+
create_image_tmpl +
'</div>').appendTo($("#marketplace_import_dialog_tabs_content"));
$('<div class="row">'+
'<div class="large-10 large-centered columns">'+
'<div class="large-10 columns">'+
'<label for="market_img_datastore">'+tr("Select the datastore for the images")+
'</label>'+
'<div id="market_img_datastore" name="market_img_datastore">'+
'</div>'+
'</div>'+
'<div class="large-2 columns">'+
'</div>'+
'</div>'+
'</div>').appendTo($("#market_import_dialog_content"));
var a_image_dialog = $("<dd>\
<a id='disk_tab"+tab_id+"' href='#Tab"+tab_id+"'>"+tr("Image")+"</a>\
</dd>").appendTo($("dl#marketplace_import_dialog_tabs"));
// Filter out DS with type system (1) or file (2)
var filter_att = ["TYPE", "TYPE"];
var filter_val = ["1", "2"];
$(".create_image_header", image_dialog).hide();
$("#wizard_image_reset_button", image_dialog).hide();
insertSelectOptions('div#market_img_datastore', $marketplace_import_dialog, "Datastore",
null, false, null, filter_att, filter_val);
initialize_create_image_dialog(image_dialog);
initialize_datastore_info_create_image_dialog(image_dialog);
$('#img_name', image_dialog).val(value['name']||response['name']);
$('#img_path', image_dialog).val(response['links']['download']['href']+'/'+index);
$('#src_path_select input[value="path"]', image_dialog).trigger('click');
$('select#img_type', image_dialog).val(value['type']);
$('select#img_type', image_dialog).trigger('change');
//remove any options from the custom vars dialog box
$("#custom_var_image_box",image_dialog).empty();
var md5 = value['md5']
if ( md5 ) {
option = '<option value=\'' +
md5 + '\' name="MD5">MD5=' +
md5 + '</option>';
$("#custom_var_image_box",image_dialog).append(option);
}
var sha1 = value['sha1']
if ( sha1 ) {
option = '<option value=\'' +
sha1 + '\' name="SHA1">SHA1=' +
sha1 + '</option>';
$("#custom_var_image_box",image_dialog).append(option);
}
a_image_dialog.on('click', function(){
$create_image_dialog = image_dialog;
})
image_dialog.on("close", function(){
a_image_dialog.remove();
image_dialog.remove();
if ($('a', $("dl#marketplace_import_dialog_tabs")).size > 0) {
$('a', $("dl#marketplace_import_dialog_tabs")).first().click();
} else {
$marketplace_import_dialog.foundation('reveal', 'close');
}
return false;
});
$("a[href='#img_manual']", image_dialog).closest('dl').remove();
tab_id++;
$.each(appliance['files'], function(index, value){
$('<div class="row" id="market_import_file_'+index+'">'+
'<div class="large-10 large-centered columns">'+
'<div class="large-10 columns">'+
'<label>'+
'<i class="fa fa-fw fa-download"/>&emsp;'+
index+' - '+tr("Image Name")+
'<span class="right">'+
humanize_size(value['size'])+
'</span>'+
'</label>'+
'<input type="text" class="name" value="' + (value['name']||appliance['name']) +'" />'+
'</div>'+
'<div class="large-2 columns market_image_result">'+
'</div>'+
'</div>'+
'<div class="large-10 large-centered columns market_image_response">'+
'</div>'+
'</div>').appendTo($("#market_import_dialog_content"));
})
if (response['opennebula_template'] && response['opennebula_template'] !== "CPU=1") {
var opennebula_template;
if (appliance['opennebula_template'] && appliance['opennebula_template'] !== "CPU=1") {
$('<br>'+
'<div class="row">'+
'<div class="large-12 columns">'+
'<p style="font-size:14px">'+
tr("The following template will be created in OpenNebula and the previous images will be referenced in the disks")+ ' '+
tr("If you want to edit parameters of the template you can do it later in the templates tab")+ ' '+
'</p>'+
'</div>'+
'</div>').appendTo($("#market_import_dialog_content"));
try {
opennebula_template = JSON.parse(response['opennebula_template']);
} catch (error) {
notifyError("Error parsing OpenNebula template: " + error.message);
return;
}
if ($create_template_dialog) {
$create_template_dialog.html("");
}
// Template
// Append the new div containing the tab and add the tab to the list
var template_dialog = $('<div id="'+tab_id+'Tab" class="content disk wizard_internal_tab">'+
create_template_tmpl +
'</div>').appendTo($("#marketplace_import_dialog_tabs_content"));
var a_template_dialog = $("<dd>\
<a id='disk_tab"+tab_id+"' href='#"+tab_id+"Tab'>"+tr("Template")+"</a>\
</dd>").appendTo($("dl#marketplace_import_dialog_tabs"));
initialize_create_template_dialog(template_dialog);
fillTemplatePopUp(opennebula_template, template_dialog);
a_template_dialog.on('click', function(){
$create_template_dialog = template_dialog;
})
template_dialog.on("close", function(){
a_template_dialog.remove();
template_dialog.remove();
if ($('a', $("dl#marketplace_import_dialog_tabs")).size > 0) {
$('a', $("dl#marketplace_import_dialog_tabs")).first().click();
} else {
$marketplace_import_dialog.foundation('reveal', 'close');
}
return false;
});
$("a[href='#manual']", template_dialog).closest('dl').remove();
$('<div class="row" id="market_import_file_template">'+
'<div class="large-10 large-centered columns">'+
'<div class="large-10 columns">'+
'<label>'+
'<i class="fa fa-fw fa-file-text-o"/>&emsp;'+
tr("Template Name")+
'</label>'+
'<input type="text" class="name" value="' + (appliance['opennebula_template']['NAME']||appliance['name']) +'" />'+
'</div>'+
'<div class="large-2 columns market_template_result">'+
'</div>'+
'</div>'+
'<div class="large-10 large-centered columns market_template_response">'+
'</div>'+
'</div>').appendTo($("#market_import_dialog_content"));
}
$marketplace_import_dialog.foundation().foundation('reveal', 'open');
$('a', $("dl#marketplace_import_dialog_tabs")).first().click();
$marketplace_import_dialog.on('closed', function(){
$marketplace_import_dialog.remove();
$marketplace_import_dialog = undefined;
var images_information = [];
$("#market_import_form").submit(function(){
function try_to_create_template(){
var images_created = $(".market_image_result.success", $marketplace_import_dialog).length;
if ((images_created == number_of_files) && !template_created) {
template_created = true;
if (appliance['opennebula_template'] && appliance['opennebula_template'] !== "CPU=1") {
var vm_template
try {
vm_template = JSON.parse(appliance['opennebula_template'])
} catch (error) {
$(".market_template_result", template_context).html('<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-warning fa-stack-1x fa-inverse"></i>'+
'</span>');
$(".market_template_response", template_context).html('<p style="font-size:12px" class="error-color">'+
(error.message || tr("Cannot contact server: is it running and reachable?"))+
'</p>');
$("input", template_context).removeAttr("disabled");
$("button", $marketplace_import_dialog).removeAttr("disabled");
template_created = false;
return;
}
if ($.isEmptyObject(vm_template.DISK))
vm_template.DISK = []
else if (!$.isArray(vm_template.DISK))
vm_template.DISK = [vm_template.DISK]
vm_template.NAME = $("input", template_context).val();
if (!vm_template.CPU)
vm_template.CPU = "1"
if (!vm_template.MEMORY)
vm_template.MEMORY = "1024"
$.each(images_information, function(image_index, image_info){
if (!vm_template.DISK[image_index]) {
vm_template.DISK[image_index] = {}
}
vm_template.DISK[image_index].IMAGE = image_info.IMAGE.NAME;
vm_template.DISK[image_index].IMAGE_UNAME = image_info.IMAGE.UNAME;
})
vm_template.FROM_APP = appliance['_id']["$oid"];
vm_template.FROM_APP_NAME = appliance['name'];
OpenNebula.Template.create({
timeout: true,
data: {vmtemplate: vm_template},
success: function (request, response){
$(".market_template_result", template_context).addClass("success").html('<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-check fa-stack-1x fa-inverse"></i>'+
'</span>');
$(".market_template_response", template_context).html('<p style="font-size:12px" class="running-color">'+
tr("Template created successfully")+' ID:'+response.VMTEMPLATE.ID+
'</p>');
$("button", $marketplace_import_dialog).hide();
},
error: function (request, error_json){
$(".market_template_result", template_context).html('<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-warning fa-stack-1x fa-inverse"></i>'+
'</span>');
$(".market_template_response", template_context).html('<p style="font-size:12px" class="error-color">'+
(error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+
'</p>');
$("input", template_context).removeAttr("disabled");
$("button", $marketplace_import_dialog).removeAttr("disabled");
template_created = false;
}
});
} else {
$("button", $marketplace_import_dialog).hide();
}
};
}
var number_of_files = appliance['files'].length;
var template_created = false;
$("input, button", $marketplace_import_dialog).attr("disabled", "disabled");
$(".market_image_result:not(.success)", $marketplace_import_dialog).html('<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-spinner fa-spin fa-stack-1x fa-inverse"></i>'+
'</span>');
$(".market_template_result", $marketplace_import_dialog).html('<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-spinner fa-spin fa-stack-1x fa-inverse"></i>'+
'</span>');
var template_context = $("#market_import_file_template", $marketplace_import_dialog);
$.each(appliance['files'], function(index, value){
var context = $("#market_import_file_"+index, $marketplace_import_dialog);
if ($(".market_image_result:not(.success)", context).length > 0) {
img_obj = {
"image" : {
"NAME": $("input.name",context).val(),
"PATH": appliance['links']['download']['href']+'/'+index,
"TYPE": value['type'],
"MD5": value['md5'],
"SHA1": value['sha1'],
"FROM_APP": appliance['_id']["$oid"],
"FROM_APP_NAME": appliance['name'],
"FROM_APP_FILE": index
},
"ds_id" : $("#market_img_datastore select", $marketplace_import_dialog).val()
};
OpenNebula.Image.create({
timeout: true,
data: img_obj,
success: function (file_index, file_context){
return function(request, response) {
$(".market_image_result", file_context).addClass("success").html('<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-check fa-stack-1x fa-inverse"></i>'+
'</span>');
$(".market_image_response", file_context).html('<p style="font-size:12px" class="running-color">'+
tr("Image created successfully")+' ID:'+response.IMAGE.ID+
'</p>');
images_information[file_index] = response;
try_to_create_template();
};
}(index, context),
error: function (request, error_json){
$(".market_template_result", template_context).html('');
$(".market_image_result", context).html('<span class="fa-stack fa-2x" style="color: #dfdfdf">'+
'<i class="fa fa-cloud fa-stack-2x"></i>'+
'<i class="fa fa-warning fa-stack-1x fa-inverse"></i>'+
'</span>');
$(".market_image_response", context).html('<p style="font-size:12px" class="error-color">'+
(error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+
'</p>');
$("input", template_context).removeAttr("disabled");
$("input", context).removeAttr("disabled");
$("button", $marketplace_import_dialog).removeAttr("disabled");
}
});
}
});
try_to_create_template();
return false;
})
},
error: onError
@ -207,18 +337,19 @@ var market_buttons = {
};
var marketplace_import_dialog =
'<div id="marketplace_import_dialog">'+
'<div id="market_import_dialog">'+
'<div class="row">'+
'<div class="large-12 columns">'+
'<div class="large-12">'+
'<h3 class="subheader">'+tr("Import Appliance")+'</h3>'+
'</div>'+
'</div>'+
'<div class="reveal-body">'+
'<dl class="tabs" id="marketplace_import_dialog_tabs" data-tab>'+
'</dl>'+
'<div class="tabs-content" id="marketplace_import_dialog_tabs_content">'+
'</div>'+
'</div>'+
'<form id="market_import_form">'+
'<div id="market_import_dialog_content">'+
'</div>'+
'<div class="form_buttons">'+
'<button class="button radius right success" id="market_import_button" type="submit">'+tr("Import")+'</button>'+
'</div>'+
'</form>'+
'<a class="close-reveal-modal">&#215;</a>'+
'</div>';
@ -270,26 +401,52 @@ function marketplaceElements(){
}
function updateMarketInfo(request,app){
var url = app.links.download.href;
url = url.replace(/\/download$/, '');
var files_table = '<table id="info_marketplace_table2" class="dataTable">\
<thead>\
<tr><th colspan="2">'+tr("Images")+'</th></tr>\
</thead>\
<tbody>';
if (app['files']) {
$.each(app['files'], function(index, value){
files_table += '<tr>\
<td class="value_td">'+value['name']+'</td>\
<td class="value_td">'+humanize_size(value['size'])+'</td>\
</tr>'
});
} else {
files_table += '<tr>\
<td colspan="2" class="value_td">'+tr("No Images defined")+'</td>\
</tr>'
}
files_table += '</tbody>\
</table>';
var info_tab = {
title : tr("Info"),
icon: "fa-info-circle",
content :
'<form class="custom"><div class="row">\
content: '<div class="row">\
<div class="large-6 columns">\
<table id="info_marketplace_table" class="dataTable extended_table">\
<table id="info_marketplace_table" class="dataTable">\
<thead>\
<tr>\
<th colspan="2">'+tr("Information") + '</th>\
</tr>\
<tr><th colspan="2">'+tr("Information")+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="key_td">' + tr("ID") + '</td>\
<td class="value_td">'+app['_id']["$oid"]+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Name") + '</td>\
<td class="value_td">'+app['name']+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("URL") + '</td>\
<td class="value_td"><a href="'+config.system_config.marketplace_url+'/'+app['_id']["$oid"]+'" target="_blank">'+tr("link")+'</a></td>\
<td class="value_td"><a href="'+url+'" target="_blank">'+tr("link")+'</a></td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Publisher") + '</td>\
@ -297,41 +454,76 @@ function updateMarketInfo(request,app){
</tr>\
<tr>\
<td class="key_td">' + tr("Downloads") + '</td>\
<td class="value_td">'+app['downloads']+'</td>\
</tr>\
<tr>\
<td class="value_td">'+app['downloads']+'</td>'+
(app['status'] ? '<tr>\
<td class="key_td">' + tr("Status") + '</td>\
<td class="value_td">'+app['status']+'</td>\
</tr>' : '') +
(app['tags'] ? '<tr>\
<td class="key_td">' + tr("Tags") + '</td>\
<td class="value_td">'+app['tags'].join(' ')+'</td>\
</tr>' : '') +
(app['catalog'] ? '<tr>\
<td class="key_td">' + tr("Catalog") + '</td>\
<td class="value_td">'+app['catalog']+'</td>\
</tr>' : '') +
'<tr>\
<td class="key_td">' + tr("OS") + '</td>\
<td class="value_td">'+app['files'][0]['os-id']+' '+app['files'][0]['os-release']+'</td>\
<td class="value_td">'+app['os-id']+' '+app['os-release']+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Arch") + '</td>\
<td class="value_td">'+app['files'][0]['os-arch']+'</td>\
</tr>\
<tr>\
<td class="value_td">'+app['os-arch']+'</td>\
</tr>' +
(app['files'] ? '<tr>\
<td class="key_td">' + tr("Size") + '</td>\
<td class="value_td">'+humanize_size(app['files'][0]['size'],true)+'</td>\
</tr>' : '') +
'<tr>\
<td class="key_td">' + tr("Hypervisor") + '</td>\
<td class="value_td">'+app['hypervisor']+'</td>\
</tr>\
<tr>\
<td class="key_td">' + tr("Hypervisor") + '</td>\
<td class="value_td">'+app['files'][0]['hypervisor']+'</td>\
</tr>\
</tbody>\
<td class="key_td">' + tr("Format") + '</td>\
<td class="value_td">'+app['format']+'</td>\
</tr>' +
'</tbody>\
</table>\
</div>\
<div class="large-6 columns">\
<table id="info_marketplace_table2" class="dataTable extended_table">\
<thead>\
<tr><th>'+tr("Description")+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="">'+app['description'].replace(/\n/g, "<br />")+'</td>\
</tr>\
</tbody>\
</table>\
</div>\
</div>\
</form>'
<div class="large-6 columns">'+
(app['short_description'] ? '<table class="dataTable">\
<thead>\
<tr><th colspan="2">'+tr("Short Description")+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="value_td">'+app['short_description'].replace(/\n/g, "<br />")+'</td>\
</tr>\
</tbody>\
</table>' : '') +
'<table id="info_marketplace_table2" class="dataTable">\
<thead>\
<tr><th colspan="2">'+tr("Description")+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="value_td">'+app['description'].replace(/\n/g, "<br />")+'</td>\
</tr>\
</tbody>\
</table>'+
files_table+
(app['opennebula_template'] ? '<table class="dataTable">\
<thead>\
<tr><th colspan="2">'+tr("OpenNebula Template")+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="value_td">'+app['opennebula_template'].replace(/\n/g, "<br />")+'</td>\
</tr>\
</tbody>\
</table>' : '') +
'</div>\
</div>'
};
Sunstone.updateInfoPanelTab("marketplace_info_panel", "marketplace_info_tab", info_tab);

View File

@ -226,12 +226,7 @@ var template_actions = {
type: "create",
call: OpenNebula.Template.create,
callback: function(request, response){
if (typeof($appmarket_import_dialog) !== 'undefined' ||
typeof($marketplace_import_dialog) !== 'undefined') {
$create_template_dialog.trigger('close');
} else {
$create_template_dialog.foundation('reveal', 'close');
}
$create_template_dialog.foundation('reveal', 'close');
addTemplateElement(request, response);
notifyCustom(tr("Template created"), " ID: " + response.VMTEMPLATE.ID, false)
},

View File

@ -1703,6 +1703,8 @@ function setupTips(context, position){
//replace the text with an icon and spans
obj.html('<span data-tooltip class="'+tip_classes.join(' ')+'" data-width="210" title="'+tip+'"><i class="fa fa-question-circle"></i></span>');
});
context.foundation();
}
//returns an array of ids of selected elements in a dataTable