From 94d320304994f46389807235616585f81e34f631 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 22 Feb 2016 13:56:17 +0100 Subject: [PATCH] Feature #4352: Show ID of the new resource in clone actions --- src/sunstone/models/OpenNebulaJSON/ImageJSON.rb | 10 ++++++++-- src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb | 8 +++++++- src/sunstone/public/app/tabs/images-tab/actions.js | 7 ++++++- src/sunstone/public/app/tabs/templates-tab/actions.js | 4 ++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb index fa399acf87..66a37cf4d8 100644 --- a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb @@ -108,9 +108,15 @@ module OpenNebulaJSON def clone(params=Hash.new) if params['target_ds'] - super(params['name'], params['target_ds'].to_i) + rc = super(params['name'], params['target_ds'].to_i) else - super(params['name']) + rc = super(params['name']) + end + + if OpenNebula.is_error?(rc) + return rc + else + return ImageJSON.new_with_id(rc, @client) end end diff --git a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb index c6a2b6fb68..d251a35552 100644 --- a/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb @@ -118,7 +118,13 @@ module OpenNebulaJSON end def clone(params=Hash.new) - super(params['name']) + rc = super(params['name']) + + if OpenNebula.is_error?(rc) + return rc + else + return TemplateJSON.new_with_id(rc, @client) + end end def rename(params=Hash.new) diff --git a/src/sunstone/public/app/tabs/images-tab/actions.js b/src/sunstone/public/app/tabs/images-tab/actions.js index 8ae81d3f23..cfad322b30 100644 --- a/src/sunstone/public/app/tabs/images-tab/actions.js +++ b/src/sunstone/public/app/tabs/images-tab/actions.js @@ -19,6 +19,7 @@ define(function(require) { var Notifier = require('utils/notifier'); var Locale = require('utils/locale'); var OpenNebulaResource = require('opennebula/image'); + var OpenNebulaAction = require('opennebula/action'); var CommonActions = require('utils/common-actions'); var RESOURCE = "Image"; @@ -61,7 +62,7 @@ define(function(require) { function(formPanelInstance, context) { var selectedNodes = Sunstone.getDataTable(TAB_ID).elements(); if (selectedNodes.length !== 1) { - Notifier.notifyMessage('Please select one (and just one) Image to export.'); + Notifier.notifyMessage(Locale.tr("Please select one (and just one) Image to export.")); return false; } @@ -80,6 +81,10 @@ define(function(require) { "Image.clone" : { type: "single", call: OpenNebulaResource.clone, + callback: function(request, response) { + OpenNebulaAction.clear_cache("IMAGE"); + Notifier.notifyCustom(Locale.tr("Image created"), " ID: " + response.IMAGE.ID, false); + }, error: Notifier.onError, notify: true } diff --git a/src/sunstone/public/app/tabs/templates-tab/actions.js b/src/sunstone/public/app/tabs/templates-tab/actions.js index 0bf8689b68..c1a30eaf42 100644 --- a/src/sunstone/public/app/tabs/templates-tab/actions.js +++ b/src/sunstone/public/app/tabs/templates-tab/actions.js @@ -106,6 +106,10 @@ define(function(require) { "Template.clone" : { type: "single", call: OpenNebulaResource.clone, + callback: function(request, response) { + OpenNebulaAction.clear_cache("VMTEMPLATE"); + Notifier.notifyCustom(Locale.tr("VM Template created"), " ID: " + response.VMTEMPLATE.ID, false); + }, error: Notifier.onError, notify: true }