diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 21a8e06fab..5ac5d6e8d7 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -244,13 +244,15 @@ var image_actions = { type: "create", call: OpenNebula.Image.create, callback: function(request, response){ - // Reset the create wizard + addImageElement(request, response); + if ($appmarket_import_dialog || $marketplace_import_dialog) { + $create_image_dialog.trigger('close'); + } else { $create_image_dialog.foundation('reveal', 'close'); $create_image_dialog.empty(); setupCreateImageDialog(); - - addImageElement(request, response); - notifyCustom(tr("Image created"), " ID: " + response.IMAGE.ID, false); + } + notifyCustom(tr("Image created"), " ID: " + response.IMAGE.ID, false) }, error: onError }, @@ -1020,6 +1022,8 @@ function initialize_create_image_dialog(dialog) { }); $('#create_image_submit',dialog).click(function(){ + $create_image_dialog = dialog; + var exit = false; var upload = false; $('.img_man',this).each(function(){ diff --git a/src/sunstone/public/js/plugins/marketplace-tab.js b/src/sunstone/public/js/plugins/marketplace-tab.js index 54a23fa8d6..6e9ea6af5c 100644 --- a/src/sunstone/public/js/plugins/marketplace-tab.js +++ b/src/sunstone/public/js/plugins/marketplace-tab.js @@ -60,7 +60,6 @@ var market_actions = { 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.foundation().foundation('reveal', 'open'); var tab_id = 1; @@ -110,8 +109,8 @@ var market_actions = { }) image_dialog.on("close", function(){ - a_image_dialog.html(""); - image_dialog.html(""); + 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 { @@ -125,7 +124,19 @@ var market_actions = { }) if (response['opennebula_template'] && response['opennebula_template'] !== "CPU=1") { - $create_template_dialog.html(""); + var opennebula_template; + + 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 = $('
'+ @@ -137,17 +148,15 @@ var market_actions = { ").appendTo($("dl#marketplace_import_dialog_tabs")); initialize_create_template_dialog(template_dialog); - fillTemplatePopUp( - JSON.parse(response['opennebula_template']), - 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.html(""); - template_dialog.html(""); + 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 { @@ -159,7 +168,13 @@ var market_actions = { $("a[href='#manual']", template_dialog).closest('dl').remove(); } + $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; + }) }, error: onError }, @@ -325,10 +340,9 @@ function updateMarketInfo(request,app){ function infoListenerMarket(dataTable){ $('tbody tr',dataTable).live("click",function(e){ - - if ($(e.target).is('input') || - $(e.target).is('select') || - $(e.target).is('option')) return true; + if ($(e.target).is('input') || + $(e.target).is('select') || + $(e.target).is('option')) return true; var aData = dataTable.fnGetData(this); var id =aData["_id"]["$oid"]; diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index f7e568ed19..1b414959e9 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -15,7 +15,7 @@ /* -------------------------------------------------------------------------- */ var create_template_tmpl = '\ -
'+ +
'+ '
'+ '

'+tr("Create VM Template")+'

'+tr("Update VM Template")+'

'+ '
'+ @@ -226,8 +226,11 @@ var template_actions = { type: "create", call: OpenNebula.Template.create, callback: function(request, response){ - $create_template_dialog.foundation('reveal', 'close') - $create_template_dialog.empty(); + if ($appmarket_import_dialog || $marketplace_import_dialog) { + $create_template_dialog.trigger('close'); + } else { + $create_template_dialog.foundation('reveal', 'close'); + } addTemplateElement(request, response); notifyCustom(tr("Template created"), " ID: " + response.VMTEMPLATE.ID, false) }, @@ -3250,16 +3253,16 @@ function setup_context_tab_content(context_section) { $("td", this).removeClass('markrowchecked'); $('div#selected_files_spans span#tag_file_'+file_id, context_section).remove(); } - + if ($.isEmptyObject(selected_files)) { $('#files_selected', context_section).hide(); $('#select_files', context_section).show(); } - + $('.alert-box', $('#contextTab')).hide(); - + generate_context_files(); - + return true; }); @@ -3772,6 +3775,7 @@ function initialize_create_template_dialog(dialog) { //Process form $('button#create_template_form_easy',dialog).click(function(){ + $create_template_dialog = dialog; //wrap it in the "vmtemplate" object var vm_json = build_template(); vm_json = {vmtemplate: vm_json}; diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index c4a694f7b8..4a3c469d21 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -1242,6 +1242,7 @@ function updateView(item_list,dataTable){ //replaces an element with id 'tag' in a dataTable with a new one function updateSingleElement(element,dataTable,tag){ + // fnGetData should be used instead, otherwise it depends on the visible columns var nodes = dataTable.fnGetNodes(); var tr = $(tag,nodes).parents('tr')[0]; var checked_val = $('input.check_item',tr).attr('checked');