1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Add update template support for hosts.

Also Refactored a bit of related code affecting the popup of the dialog.
This commit is contained in:
Hector Sanjuan 2011-06-22 18:12:38 +02:00 committed by Ruben S. Montero
parent a991817a3a
commit ee42e1bce1
6 changed files with 119 additions and 20 deletions

View File

@ -49,11 +49,17 @@ module OpenNebulaJSON
rc = case action_hash['perform']
when "enable" then self.enable
when "disable" then self.disable
when "update" then self.update(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
OpenNebula::Error.new(error_msg)
end
end
def update(params=Hash.new)
super(params['template_raw'])
end
end
end

View File

@ -509,6 +509,72 @@ var OpenNebula = {
});
},
"fetch_template" : function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var method = "fetch_template";
var resource = OpenNebula.Host.resource;
var request = OpenNebula.Helper.request(resource,method, id);
$.ajax({
url: "host/" + id + "/template",
type: "GET",
dataType:"json",
success: function(response)
{
if (callback)
{
callback(request,response);
}
},
error: function(response)
{
if(callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"update": function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var template_raw = params.data.extra_param;
var template_obj = {"template_raw": template_raw}
var method = "update";
var action = OpenNebula.Helper.action(method, template_obj);
var resource = OpenNebula.Host.resource;
var request = OpenNebula.Helper.request(resource,method, [id, template_obj]);
$.ajax({
url: "host/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function(response)
{
if (callback)
{
callback(request, response);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"monitor" : function(params){
var callback = params.success;
var callback_error = params.error;

View File

@ -207,6 +207,33 @@ var host_actions = {
plot_global_graph(response,info);
},
error: onError
},
"Host.fetch_template" : {
type: "single",
call: OpenNebula.Host.fetch_template,
callback: function (request,response) {
$('#template_update_dialog #template_update_textarea').val(response.template);
},
error: onError,
notify: false
},
"Host.update_dialog" : {
type: "custom",
call: function() {
popUpTemplateUpdateDialog("Host",hosts_select);
}
},
"Host.update" : {
type: "single",
call: OpenNebula.Host.update,
callback: function() {
notifyMessage("Template updated correctly");
},
error: onError,
notify: false
}
};
@ -222,6 +249,12 @@ var host_buttons = {
text: "+ New",
condition :True
},
"Host.update_dialog" : {
type: "action",
text: "Update a template",
condition: True,
alwaysActive: true
},
"Host.enable" : {
type: "action",
text: "Enable",

View File

@ -222,7 +222,9 @@ var image_actions = {
"Image.update_dialog" : {
type: "custom",
call: popUpImageTemplateUpdateDialog
call: function() {
popUpTemplateUpdateDialog("Image",images_select);
}
},
"Image.update" : {
@ -510,15 +512,6 @@ function updateImagesView(request, images_list){
}
function popUpImageTemplateUpdateDialog(){
$('#template_update_dialog #template_update_button').val("Image");
$('#template_update_dialog #template_update_select').html(images_select);
$('#template_update_dialog #template_update_textarea').val("");
$('#template_update_dialog').dialog('open');
return false;
}
// Callback to update the information panel tabs and pop it up
function updateImageInfo(request,img){
var img_info = img.IMAGE;

View File

@ -590,7 +590,9 @@ var template_actions = {
"Template.update_dialog" : {
type: "custom",
call: popUpTemplateTemplateUpdateDialog
call: function() {
popUpTemplateUpdateDialog("Template",templates_select);
}
},
"Template.update" : {
@ -832,15 +834,6 @@ function updateTemplatesView(request, templates_list){
}
// Popup a dialog to add/update an attribute
function popUpTemplateTemplateUpdateDialog(){
$('#template_update_dialog #template_update_button').val("Template");
$('#template_update_dialog #template_update_select').html(templates_select);
$('#template_update_dialog #template_update_textarea').val("");
$('#template_update_dialog').dialog('open');
return false;
}
// Callback to update the information panel tabs and pop it up
function updateTemplateInfo(request,template){
var template_info = template.VMTEMPLATE;

View File

@ -613,6 +613,14 @@ function setupTemplateUpdateDialog(){
});
}
function popUpTemplateUpdateDialog(elem_str,select_items){
$('#template_update_dialog #template_update_button').val(elem_str);
$('#template_update_dialog #template_update_select').html(select_items);
$('#template_update_dialog #template_update_textarea').val("");
$('#template_update_dialog').dialog('open');
return false;
}
//functions that used as true and false conditions for testing mainly
function True(){
return true;