diff --git a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb index a6086ab99e..d4395231bb 100644 --- a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb @@ -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 diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 2171cf5eeb..09885d3188 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -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; diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index a5b2c3964a..0ae4eae897 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -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", diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index afa12f35f4..191fb0c5be 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -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; diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 4e2dd92c08..3fc9d0d659 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -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; diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 1709736362..8c43b26883 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -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;