diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index b580f61e76..66b74c76e2 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -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 diff --git a/src/sunstone/public/js/plugins/marketplace-tab.js b/src/sunstone/public/js/plugins/marketplace-tab.js index f44125a49e..e3ebace681 100644 --- a/src/sunstone/public/js/plugins/marketplace-tab.js +++ b/src/sunstone/public/js/plugins/marketplace-tab.js @@ -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; + $('
'+ + '
'+ + '

'+ + 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")+ ' '+ + '

'+ + '
'+ + '
').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 = $('
'+ - create_image_tmpl + - '
').appendTo($("#marketplace_import_dialog_tabs_content")); + $('
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
').appendTo($("#market_import_dialog_content")); - var a_image_dialog = $("
\ - "+tr("Image")+"\ -
").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 = ''; - $("#custom_var_image_box",image_dialog).append(option); - } - - var sha1 = value['sha1'] - if ( 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){ + $('
'+ + '
'+ + '
'+ + ''+ + ''+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
').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") { + $('
'+ + '
'+ + '
'+ + '

'+ + 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")+ ' '+ + '

'+ + '
'+ + '
').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 = $('
'+ - create_template_tmpl + - '
').appendTo($("#marketplace_import_dialog_tabs_content")); - - var a_template_dialog = $("
\ - "+tr("Template")+"\ -
").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(); + $('
'+ + '
'+ + '
'+ + ''+ + ''+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
').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(''+ + ''+ + ''+ + ''); + + $(".market_template_response", template_context).html('

'+ + (error.message || tr("Cannot contact server: is it running and reachable?"))+ + '

'); + + $("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(''+ + ''+ + ''+ + ''); + + $(".market_template_response", template_context).html('

'+ + tr("Template created successfully")+' ID:'+response.VMTEMPLATE.ID+ + '

'); + + $("button", $marketplace_import_dialog).hide(); + }, + error: function (request, error_json){ + $(".market_template_result", template_context).html(''+ + ''+ + ''+ + ''); + + $(".market_template_response", template_context).html('

'+ + (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ + '

'); + + $("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(''+ + ''+ + ''+ + ''); + $(".market_template_result", $marketplace_import_dialog).html(''+ + ''+ + ''+ + ''); + + 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(''+ + ''+ + ''+ + ''); + + $(".market_image_response", file_context).html('

'+ + tr("Image created successfully")+' ID:'+response.IMAGE.ID+ + '

'); + + 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(''+ + ''+ + ''+ + ''); + + $(".market_image_response", context).html('

'+ + (error_json.error.message || tr("Cannot contact server: is it running and reachable?"))+ + '

'); + + $("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 = -'
'+ +'
'+ '
'+ - '
'+ + '
'+ '

'+tr("Import Appliance")+'

'+ '
'+ '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ - '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + ''+ + '
'+ + '
'+ '×'+ '
'; @@ -270,26 +401,52 @@ function marketplaceElements(){ } function updateMarketInfo(request,app){ + var url = app.links.download.href; + url = url.replace(/\/download$/, ''); + + var files_table = '\ + \ + \ + \ + '; + + if (app['files']) { + $.each(app['files'], function(index, value){ + files_table += '\ + \ + \ + ' + }); + } else { + files_table += '\ + \ + ' + } + + files_table += '\ +
'+tr("Images")+'
'+value['name']+''+humanize_size(value['size'])+'
'+tr("No Images defined")+'
'; + var info_tab = { title : tr("Info"), icon: "fa-info-circle", - content : - '
\ + content: '
\
\ - \ +
\ \ - \ - \ - \ + \ \ \ \ \ \ \ + \ + \ + \ + \ \ \ - \ + \ \ \ \ @@ -297,41 +454,76 @@ function updateMarketInfo(request,app){ \ \ \ - \ - \ - \ + '+ + (app['status'] ? '\ + \ + \ + ' : '') + + (app['tags'] ? '\ + \ + \ + ' : '') + + (app['catalog'] ? '\ + \ + \ + ' : '') + + '\ \ - \ + \ \ \ \ - \ - \ - \ + \ + ' + + (app['files'] ? '\ \ \ + ' : '') + + '\ + \ + \ \ \ - \ - \ - \ - \ + \ + \ + ' + + '\
'+tr("Information") + '
'+tr("Information")+'
' + tr("ID") + ''+app['_id']["$oid"]+'
' + tr("Name") + ''+app['name']+'
' + tr("URL") + ''+tr("link")+''+tr("link")+'
' + tr("Publisher") + '
' + tr("Downloads") + ''+app['downloads']+'
'+app['downloads']+'
' + tr("Status") + ''+app['status']+'
' + tr("Tags") + ''+app['tags'].join(' ')+'
' + tr("Catalog") + ''+app['catalog']+'
' + tr("OS") + ''+app['files'][0]['os-id']+' '+app['files'][0]['os-release']+''+app['os-id']+' '+app['os-release']+'
' + tr("Arch") + ''+app['files'][0]['os-arch']+'
'+app['os-arch']+'
' + tr("Size") + ''+humanize_size(app['files'][0]['size'],true)+'
' + tr("Hypervisor") + ''+app['hypervisor']+'
' + tr("Hypervisor") + ''+app['files'][0]['hypervisor']+'
' + tr("Format") + ''+app['format']+'
\
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Description")+'
'+app['description'].replace(/\n/g, "
")+'
\ -
\ -
\ - ' +
'+ + (app['short_description'] ? '\ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Short Description")+'
'+app['short_description'].replace(/\n/g, "
")+'
' : '') + + '\ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Description")+'
'+app['description'].replace(/\n/g, "
")+'
'+ + files_table+ + (app['opennebula_template'] ? '\ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("OpenNebula Template")+'
'+app['opennebula_template'].replace(/\n/g, "
")+'
' : '') + + '
\ +
' }; Sunstone.updateInfoPanelTab("marketplace_info_panel", "marketplace_info_tab", info_tab); diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 95ecb4b2cb..3f722c692a 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -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) }, diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index 94da626c5c..21790d112e 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -1703,6 +1703,8 @@ function setupTips(context, position){ //replace the text with an icon and spans obj.html(''); }); + + context.foundation(); } //returns an array of ids of selected elements in a dataTable