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")+ ' '+ + '
'+ + ''+ + 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")+ ' '+ + '
'+ + ''+ + (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("Images")+' | |
---|---|
'+value['name']+' | \ +'+humanize_size(value['size'])+' | \ +
'+tr("No Images defined")+' | \ +