1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

Feature #1356: Add clone action to Self-Service

(cherry picked from commit d2937b218e3cc0d9af1ad6c7f3d8db538ec0e5ce)
This commit is contained in:
Hector Sanjuan 2012-09-03 16:28:14 +02:00 committed by Ruben S. Montero
parent fa12d01445
commit 6bab124c84
2 changed files with 142 additions and 63 deletions

View File

@ -66,16 +66,14 @@ var OCCI = {
"Helper": {
"action": function(action, params)
{
obj = {
"action": {
"perform": action
}
action = {
"perform": action
}
if (params)
{
obj.action.params = params;
action.params = params;
}
return obj;
return action;
},
"request": function(resource, method, data) {
@ -257,6 +255,37 @@ var OCCI = {
});
},
"simple_action" : function(params, resource, method, action_obj){
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var action,request;
if (action_obj) {
action = OCCI.Helper.action(method, action_obj);
request = OCCI.Helper.request(resource,method, [id, action_obj]);
} else {
action = OCCI.Helper.action(method);
request = OCCI.Helper.request(resource,method, id);
};
$.ajax({
url: resource.toLowerCase() + "/" + id + '/action',
type: "POST",
data: json2xml(action,'ACTION'),
dataType: "xml ONEjson",
success: function(response){
var res = {};
res[resource] = response;
return callback ? callback(request,res) : null;
},
error: function(response){
return callback_error ?
callback_error(request, OCCI.Error(response)) : null;
}
});
},
"accounting": function(params, resource){
var callback = params.success;
var callback_error = params.error;
@ -455,7 +484,6 @@ var OCCI = {
var resource = OCCI.VM.resource;
var method = startstop;
var action = OCCI.Helper.action(method);
var request = OCCI.Helper.request(resource,method, id);
$.ajax({
url: "ui/" + method + "/" + id,
@ -532,52 +560,11 @@ var OCCI = {
"nonpersistent": function(params){
params.data.body = { "PERSISTENT":"NO" };
OCCI.Action.update(params,OCCI.Image.resource,"nonpersistent");
}
},
"Template" : {
"resource" : "VMTEMPLATE",
"create" : function(params){
OCCI.Action.create(params,OCCI.Template.resource);
},
"del" : function(params){
OCCI.Action.del(params,OCCI.Template.resource);
},
"list" : function(params){
OCCI.Action.list(params,OCCI.Template.resource);
},
"show" : function(params){
OCCI.Action.show(params,OCCI.Template.resource);
},
"chown" : function(params){
OCCI.Action.chown(params,OCCI.Template.resource);
},
"chgrp" : function(params){
OCCI.Action.chgrp(params,OCCI.Template.resource);
},
"update" : function(params){
var action_obj = {"template_raw" : params.data.extra_param };
OCCI.Action.simple_action(params,
OCCI.Template.resource,
"update",
action_obj);
},
"fetch_template" : function(params){
OCCI.Action.show(params,OCCI.Template.resource,"template");
},
"publish" : function(params){
OCCI.Action.simple_action(params,OCCI.Template.resource,"publish");
},
"unpublish" : function(params){
OCCI.Action.simple_action(params,OCCI.Template.resource,"unpublish");
},
"instantiate" : function(params) {
var vm_name = params.data.extra_param ? params.data.extra_param : "";
var action_obj = { "vm_name" : vm_name };
OCCI.Action.simple_action(params,OCCI.Template.resource,
"instantiate",action_obj);
"clone" : function(params){
var action_obj = { 'NAME' : params.data.extra_param };
OCCI.Action.simple_action(params, OCCI.Image.resource,
"clone", action_obj)
}
},

View File

@ -100,13 +100,27 @@ var create_image_tmpl =
</div>\
</div>';
var clone_image_tmpl = '<form><fieldset>\
<div class="clone_one">'+tr("Choose a new name for the image")+':</div>\
<div class="clone_several">'+tr("Several image are selected, please choose prefix to name the new copies")+':</div>\
<br />\
<label class="clone_one">'+tr("Name")+':</label>\
<label class="clone_several">'+tr("Prefix")+':</label>\
<input type="text" name="name"></input>\
<br /><br />\
<div class="form_buttons">\
<button type="button" class="image_close_dialog_link">'+tr("Close")+'</button>\
<button class="button" id="clone_image" value="Image.clone">\
'+tr("Clone")+'\
</button>\
</div></fieldset></form>'
var image_dashboard = '<div class="dashboard_p">\
<img src="'+storage_dashboard_image+'" alt="one-storage" />'+
storage_dashboard_html +
'</div>';
var dataTable_images;
var $create_image_dialog;
var image_actions = {
@ -175,6 +189,18 @@ var image_actions = {
notify: true
},
"Image.clone_dialog" : {
type: "custom",
call: popUpImageCloneDialog
},
"Image.clone" : {
type: "single",
call: OCCI.Image.clone,
error: onError,
notify: true
},
// "Image.publish" : {
// type: "multiple",
// call: OCCI.Image.publish,
@ -239,6 +265,10 @@ var image_buttons = {
// },
// }
// },
"Image.clone_dialog" : {
type: "action",
text: tr("Clone")
},
"Image.delete" : {
type: "action",
text: tr("Delete")
@ -259,6 +289,13 @@ var image_create_panel = {
}
};
var image_clone_panel = {
"image_clone_panel" : {
title: tr("Clone image"),
content: clone_image_tmpl
}
}
var images_tab = {
title: '<i class="icon-folder-open"></i>'+tr("Storage"),
content: images_tab_content,
@ -269,6 +306,7 @@ Sunstone.addActions(image_actions);
Sunstone.addMainTab('images_tab',images_tab);
Sunstone.addInfoPanel('image_info_panel',image_info_panel);
Sunstone.addInfoPanel('image_create_panel',image_create_panel);
Sunstone.addInfoPanel('image_clone_panel',image_clone_panel);
function imageElements() {
@ -390,7 +428,6 @@ function updateImageInfo(request,img){
function popUpCreateImageDialog(){
Sunstone.popUpInfoPanel("image_create_panel");
var dialog = $('#dialog');
$create_image_dialog = dialog;
$('#create_image',dialog).button({
icons: {
@ -429,13 +466,13 @@ function popUpCreateImageDialog(){
*/
$('#img_type',dialog).change(function(){
if ($(this).val() == "DATABLOCK"){
$('#img_fstype',$create_image_dialog).parents('div.img_param').show();
$('#img_size',$create_image_dialog).parents('div.img_param').show();
$('#upload_div',$create_image_dialog).hide();
$('#img_fstype',dialog).parents('div.img_param').show();
$('#img_size',dialog).parents('div.img_param').show();
$('#upload_div',dialog).hide();
} else {
$('#img_fstype',$create_image_dialog).parents('div.img_param').hide();
$('#img_size',$create_image_dialog).parents('div.img_param').hide();
$('#upload_div',$create_image_dialog).show();
$('#img_fstype',dialog).parents('div.img_param').hide();
$('#img_size',dialog).parents('div.img_param').hide();
$('#upload_div',dialog).show();
};
});
@ -454,7 +491,7 @@ function popUpCreateImageDialog(){
var img_obj;
var uploader = new qq.FileUploaderBasic({
button: $('#file-uploader',$create_image_dialog)[0],
button: $('#file-uploader',dialog)[0],
action: 'ui/upload',
multiple: false,
params: {},
@ -493,8 +530,6 @@ function popUpCreateImageDialog(){
$('#file-uploader input').attr('style','margin:0;width:256px!important');
var processCreateImageForm = function(){
var dialog = $create_image_dialog;
var img_json = {};
var name = $('#img_name',dialog).val();
@ -551,6 +586,63 @@ function popUpCreateImageDialog(){
});
}
function popUpImageCloneDialog(){
Sunstone.popUpInfoPanel("image_clone_panel");
var dialog = $('#dialog');
$('#clone_image',dialog).button({
icons: {
primary: "ui-icon-check"
},
text: true
});
$('.image_close_dialog_link',dialog).button({
icons: {
primary: "ui-icon-closethick"
},
text: true
});
$('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++)
//If we are cloning several images we
//use the name as prefix
Sunstone.runAction('Image.clone',
sel_elems[i],
name+getName(sel_elems[i],
dataTable_images, 2));
} else {
Sunstone.runAction('Image.clone',sel_elems[0],name)
};
setTimeout(function(){
Sunstone.runAction('Image.refresh');
}, 1500);
popUpImageDashboard();
return false;
});
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 '+getName(sel_elems[0],
dataTable_images, 2));
};
}
function popUpImageDashboard(){
var count = dataTable_images.fnGetNodes().length;
popDialog(image_dashboard);