From c4d43909847f3d8a679490da677d9be863cbbdb7 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Sun, 23 Oct 2011 19:02:05 +0200 Subject: [PATCH] Task #900: Add specific update template dialog for Virtual Networks. Along with it, server/client support for update action has been added. --- .../OpenNebulaJSON/VirtualNetworkJSON.rb | 7 +- src/sunstone/public/js/opennebula.js | 12 +- src/sunstone/public/js/plugins/images-tab.js | 4 +- src/sunstone/public/js/plugins/vnets-tab.js | 164 +++++++++++++++++- 4 files changed, 181 insertions(+), 6 deletions(-) diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb index 7a4669a5d5..b18230f2ac 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb @@ -31,7 +31,7 @@ module OpenNebulaJSON else template = template_to_str(vnet_hash) end - + self.allocate(template) end @@ -46,6 +46,7 @@ module OpenNebulaJSON when "rmleases" then self.rmleases(action_hash['params']) when "publish" then self.publish when "unpublish" then self.unpublish + when "update" then self.update(action_hash['params']) when "chown" then self.chown(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << @@ -62,6 +63,10 @@ module OpenNebulaJSON super(params['ip']) end + def update(params=Hash.new) + super(params['template_raw']) + end + def chown(params=Hash.new) super(params['owner_id'].to_i,params['group_id'].to_i) end diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 12ea698981..8a7224d161 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -510,7 +510,17 @@ var OpenNebula = { OpenNebula.Network.resource, "rmleases", action_obj); - } + }, + "update": function(params){ + var action_obj = {"template_raw" : params.data.extra_param }; + OpenNebula.Action.simple_action(params, + OpenNebula.Network.resource, + "update", + action_obj); + }, + "fetch_template" : function(params){ + OpenNebula.Action.show(params,OpenNebula.Network.resource,"template"); + }, }, "VM": { diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index 5cfe1edf97..b2bb396b1a 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -173,7 +173,7 @@ var update_image_tmpl = '
\

Please, choose and modify the image you want to update:

\
\ - \ + \ \
\
\ @@ -900,7 +900,7 @@ function popUpImageTemplateUpdateDialog(){ if (sel_elems.length >= 1){ //several items in the list are selected //grep them var new_select= sel_elems.length > 1? '' : ""; - $('option','').each(function(){ + $('option','').each(function(){ var val = $(this).val(); if ($.inArray(val,sel_elems) >= 0){ new_select+=''; diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 2151858d4c..84c7735406 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -135,6 +135,30 @@ var create_vn_tmpl =
\ '; +var update_vnet_tmpl = + '\ +

Please, choose and modify the virtual network you want to update:

\ +
\ + \ + \ +
\ +
\ + \ + \ +
\ + \ +
\ + \ +
\ +
\ +
\ + \ +
\ +
\ +'; + var vnetworks_select=""; var dataTable_vNetworks; var $create_vn_dialog; @@ -272,8 +296,34 @@ var vnet_actions = { elements: vnElements, error:onError, notify: true - } -} + }, + + "Network.fetch_template" : { + type: "single", + call: OpenNebula.Network.fetch_template, + callback: function (request,response) { + $('#vnet_template_update_dialog #vnet_template_update_textarea').val(response.template); + }, + error: onError + }, + + "Network.update_dialog" : { + type: "custom", + call: function() { + popUpVNetTemplateUpdateDialog(); + } + }, + + "Network.update" : { + type: "single", + call: OpenNebula.Network.update, + callback: function() { + notifyMessage("Template updated correctly"); + }, + error: onError + }, + +}; var vnet_buttons = { @@ -288,6 +338,12 @@ var vnet_buttons = { text: "+ New" }, + "Network.update_dialog" : { + type: "action", + text: "Update a template", + alwaysActive: true + }, + "Network.publish" : { type: "action", text: "Publish" @@ -684,6 +740,109 @@ function popUpCreateVnetDialog() { $create_vn_dialog.dialog('open'); } + +function setupVNetTemplateUpdateDialog(){ + //Append to DOM + dialogs_context.append('
'); + var dialog = $('#vnet_template_update_dialog',dialogs_context); + + //Put HTML in place + dialog.html(update_vnet_tmpl); + + //Convert into jQuery + dialog.dialog({ + autoOpen:false, + width:700, + modal:true, + height:480, + resizable:false, + }); + + $('button',dialog).button(); + + $('#vnet_template_update_select',dialog).change(function(){ + var id = $(this).val(); + if (id && id.length){ + var dialog = $('#vnet_template_update_dialog'); + $('#vnet_template_update_textarea',dialog).val("Loading..."); + + var data = getElementData(id,"#vnetwork",dataTable_vNetworks); + var is_public = data[7] == "yes"; + + if (is_public){ + $('#vnet_template_update_public',dialog).attr("checked","checked") + } else { + $('#vnet_template_update_public',dialog).removeAttr("checked") + } + + Sunstone.runAction("Network.fetch_template",id); + } else { + $('#vnet_template_update_textarea',dialog).val(""); + }; + }); + + $('#vnet_template_update_button',dialog).click(function(){ + var dialog = $('#vnet_template_update_dialog'); + var new_template = $('#vnet_template_update_textarea',dialog).val(); + var id = $('#vnet_template_update_select',dialog).val(); + if (!id || !id.length) { + dialog.dialog('close'); + return false; + }; + + var data = getElementData(id,"#vnetwork",dataTable_vNetworks); + var is_public = data[7] == "yes"; + + var new_public = $('#vnet_template_update_public:checked',dialog).length; + + if (is_public != new_public){ + if (new_public) Sunstone.runAction("Network.publish",id); + else Sunstone.runAction("Network.unpublish",id); + }; + + Sunstone.runAction("Network.update",id,new_template); + dialog.dialog('close'); + return false; + }); +}; + +function popUpVNetTemplateUpdateDialog(){ + var select = makeSelectOptions(dataTable_vNetworks, + 1,//id_col + 4,//name_col + [], + [] + ); + var sel_elems = getSelectedNodes(dataTable_vNetworks); + + + var dialog = $('#vnet_template_update_dialog'); + $('#vnet_template_update_select',dialog).html(select); + $('#vnet_template_update_textarea',dialog).val(""); + $('#vnet_template_update_public',dialog).removeAttr("checked") + + if (sel_elems.length >= 1){ //several items in the list are selected + //grep them + var new_select= sel_elems.length > 1? '' : ""; + $('option','').each(function(){ + var val = $(this).val(); + if ($.inArray(val,sel_elems) >= 0){ + new_select+=''; + }; + }); + $('#vnet_template_update_select',dialog).html(new_select); + if (sel_elems.length == 1) { + $('#vnet_template_update_select option',dialog).attr("selected","selected"); + $('#vnet_template_update_select',dialog).trigger("change"); + } + + }; + + dialog.dialog('open'); + return false; + +} + function setupAddRemoveLeaseDialog() { dialogs_context.append('
'); $lease_vn_dialog = $('#lease_vn_dialog',dialogs_context) @@ -786,6 +945,7 @@ $(document).ready(function(){ Sunstone.runAction("Network.list"); setupCreateVNetDialog(); + setupVNetTemplateUpdateDialog(); setupAddRemoveLeaseDialog(); setVNetAutorefresh();