diff --git a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb index 99a0bdf04b..6224ef063c 100644 --- a/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/ImageJSON.rb @@ -58,6 +58,7 @@ module OpenNebulaJSON when "chown" then self.chown(action_hash['params']) when "chmod" then self.chmod_octet(action_hash['params']) when "chtype" then self.chtype(action_hash['params']) + when "clone" then self.clone(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -84,5 +85,9 @@ module OpenNebulaJSON def chtype(params=Hash.new) super(params['type']) end + + def clone(params=Hash.new) + super(params['name']) + end end end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 716a1ebdda..893772121b 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -816,6 +816,11 @@ var OpenNebula = { OpenNebula.Image.resource, "chtype", action_obj); + }, + "clone" : function(params) { + var name = params.data.extra_param ? params.data.extra_param : ""; + var action_obj = { "name" : name }; + OpenNebula.Action.simple_action(params,OpenNebula.Image.resource, "clone", action_obj); } }, diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 0aea6334dd..dc55758419 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -436,6 +436,16 @@ var image_actions = { error: onError, notify: true }, + "Image.clone_dialog" : { + type: "custom", + call: popUpImageCloneDialog + }, + "Image.clone" : { + type: "single", + call: OpenNebula.Image.clone, + error: onError, + notify: true + }, "Image.help" : { type: "custom", call: function() { @@ -496,6 +506,10 @@ var image_buttons = { } } }, + "Image.clone_dialog" : { + type: "action", + text: tr("Clone"), + }, "Image.delete" : { type: "confirm", text: tr("Delete") @@ -1136,6 +1150,78 @@ function setupImageActionCheckboxes(){ } +function setupImageCloneDialog(){ + //Append to DOM + dialogs_context.append('
'); + var dialog = $('#image_clone_dialog',dialogs_context); + + //Put HTML in place + + var html = '
\ +
'+tr("Choose a new name for the image")+':
\ +
'+tr("Several image are selected, please choose prefix to name the new copies")+':
\ +
\ +\ +\ +\ +
\ + \ +
\ +'; + + dialog.html(html); + + //Convert into jQuery + dialog.dialog({ + autoOpen:false, + width:375, + modal:true, + resizable:false, + }); + + $('button',dialog).button(); + + $('form',dialog).submit(function(){ + var name = $('input', this).val(); + var sel_elems = imageElements(); + if (!name || !sel_elems.length) + notifyError('A name or prefix is needed!'); + if (sel_elems.length > 1){ + for (var i=0; i< sel_elems.length; i++) + Sunstone.runAction('Image.clone', + sel_elems[i], + name+getImageName(sel_elems[i])); + } else { + Sunstone.runAction('Image.clone',sel_elems[0],name) + }; + dialog.dialog('close'); + setTimeout(function(){ + Sunstone.runAction('Image.refresh'); + }, 1500); + return false; + }); +} + +function popUpImageCloneDialog(){ + var dialog = $('#image_clone_dialog'); + var sel_elems = imageElements(); + //show different text depending on how many elements are selected + if (sel_elems.length > 1){ + $('.clone_one',dialog).hide(); + $('.clone_several',dialog).show(); + $('input',dialog).val('Copy of '); + } + else { + $('.clone_one',dialog).show(); + $('.clone_several',dialog).hide(); + $('input',dialog).val('Copy of '+getImageName(sel_elems[0])); + }; + + $(dialog).dialog('open'); +} + //The DOM is ready at this point $(document).ready(function(){ @@ -1172,6 +1258,7 @@ $(document).ready(function(){ setupImageTemplateUpdateDialog(); setupTips($create_image_dialog); setupImageActionCheckboxes(); + setupImageCloneDialog(); setImageAutorefresh(); initCheckAllBoxes(dataTable_images);