From 70f680914bbe7922ba7e6abcd4d459578c1f86da Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 13 Jan 2014 16:12:02 +0100 Subject: [PATCH] feature #2589: Close the image/template creation dialog only if the call succeeds --- src/sunstone/public/js/plugins/images-tab.js | 9 +++--- .../public/js/plugins/templates-tab.js | 29 +++++++------------ 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index d09bfe3be9..7444a0d4e5 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -344,7 +344,10 @@ var image_actions = { "Image.create" : { type: "create", call: OpenNebula.Image.create, - callback: addImageElement, + callback: function(request, response){ + addImageElement(request, response); + $create_image_dialog.trigger("reveal:close") + }, error: onError, notify:true }, @@ -1128,8 +1131,6 @@ function initialize_create_image_dialog(dialog) { Sunstone.runAction("Image.create", img_obj); }; - dialog.trigger("reveal:close") - return false; }); @@ -1150,7 +1151,7 @@ function initialize_create_image_dialog(dialog) { "ds_id" : ds_id }; Sunstone.runAction("Image.create",img_obj); - dialog.trigger("reveal:close") + return false; }); diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index cf6800027d..0c7246d29a 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -311,9 +311,10 @@ var template_actions = { "Template.create" : { type: "create", call: OpenNebula.Template.create, - callback: function(){ + callback: function(request, response){ + $create_template_dialog.trigger("reveal:close") $create_template_dialog.empty(); - addTemplateElement(); + addTemplateElement(request, response); }, error: onError, notify:true @@ -371,10 +372,9 @@ var template_actions = { type: "single", call: OpenNebula.Template.show, callback: function(request, response) { - $create_template_dialog.remove(); - setupCreateTemplateDialog(); + template_to_update_id = response.VMTEMPLATE.ID; + fillTemplatePopUp( - response.VMTEMPLATE.ID, response.VMTEMPLATE.TEMPLATE, $create_template_dialog); popUpUpdateTemplateDialog(); @@ -402,7 +402,8 @@ var template_actions = { "Template.update" : { type: "single", call: OpenNebula.Template.update, - callback: function() { + callback: function(request, response){ + $create_template_dialog.trigger("reveal:close") notifyMessage(tr("Template updated correctly")); }, error: onError @@ -4098,9 +4099,6 @@ function initialize_create_template_dialog(dialog) { //validate form Sunstone.runAction("Template.create",vm_json); - - dialog.trigger("reveal:close") - return false; }); @@ -4110,9 +4108,6 @@ function initialize_create_template_dialog(dialog) { vm_json =JSON.stringify(vm_json); Sunstone.runAction("Template.update",template_to_update_id,vm_json); - - dialog.trigger("reveal:close") - return false; }); @@ -4124,9 +4119,6 @@ function initialize_create_template_dialog(dialog) { var vm_json = JSON.stringify(template); Sunstone.runAction("Template.update",template_to_update_id,vm_json); - - dialog.trigger("reveal:close") - return false; }); @@ -4138,13 +4130,12 @@ function initialize_create_template_dialog(dialog) { template = {"vmtemplate": {"template_raw": template}}; Sunstone.runAction("Template.create",template); - dialog.trigger("reveal:close") return false; }); } function popUpUpdateTemplateDialog(){ - $appmarket_import_dialog.remove(); + $create_template_dialog.remove(); // TODO do not recreate if it exists setupCreateTemplateDialog(); @@ -4165,7 +4156,7 @@ function popUpUpdateTemplateDialog(){ }; function popUpCreateTemplateDialog(){ - $appmarket_import_dialog.remove(); + $create_template_dialog.remove(); // TODO do not recreate if it exists setupCreateTemplateDialog(); @@ -4208,7 +4199,7 @@ function popUpTemplateTemplateUpdateDialog(){ Sunstone.runAction("Template.show_to_update", template_id); }; -function fillTemplatePopUp(template_to_update_id, template, dialog){ +function fillTemplatePopUp(template, dialog){ var use_advanced_template = false; function autoFillInputs(template_json, context){