From 26630d9fd120c4e55efaa0118fd46e1669d98c8b Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Thu, 31 Jan 2013 16:09:08 +0100 Subject: [PATCH] =?UTF-8?q?feature=20=C2#1664:=20Add=20change=20owner=20&?= =?UTF-8?q?=20group=20in=20permissions=20table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sunstone/public/js/plugins/vms-tab.js | 33 ++--- src/sunstone/public/js/plugins/vnets-tab.js | 12 +- src/sunstone/public/js/sunstone-util.js | 147 ++++++++++++++------ src/sunstone/public/js/sunstone.js | 4 +- 4 files changed, 122 insertions(+), 74 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index ac0472de66..8b3dfbef5b 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -384,7 +384,10 @@ var vm_actions = { "VM.chown" : { type: "multiple", call: OpenNebula.VM.chown, - callback: vmShow, + callback: function(request) { + Sunstone.runAction('VM.showinfo',request.request.data[0]); + Sunstone.runAction("VM.show",request.request.data[0]); + }, elements: vmElements, error: onError, notify: true @@ -392,7 +395,10 @@ var vm_actions = { "VM.chgrp" : { type: "multiple", call: OpenNebula.VM.chgrp, - callback: vmShow, + callback: function(request) { + Sunstone.runAction('VM.showinfo',request.request.data[0]); + Sunstone.runAction("VM.show",request.request.data[0]); + }, elements: vmElements, error: onError, notify: true @@ -466,22 +472,6 @@ var vm_buttons = { alwaysActive: true }, - "VM.chown" : { - type: "confirm_with_select", - text: tr("Change owner"), - select: users_sel, - tip: tr("Select the new owner")+":", - condition: mustBeAdmin - }, - - "VM.chgrp" : { - type: "confirm_with_select", - text: tr("Change group"), - select: groups_sel, - tip: tr("Select the new group")+":", - condition: mustBeAdmin - }, - "VM.shutdown" : { type: "confirm", text: tr("Shutdown"), @@ -969,7 +959,7 @@ function updateVMInfo(request,vm){ ' + insert_extended_template_table(vm_info.USER_TEMPLATE, "VM", vm_info.ID) + - insert_permissions_table("VM",vm_info.ID) + + insert_permissions_table("VM",vm_info.ID, vm_info.UNAME, vm_info.GNAME, vm_info.UID, vm_info.GID) + '\ \ \ @@ -1034,7 +1024,7 @@ function updateVMInfo(request,vm){ // Listener for key,value pair edit action $("#div_edit_rename_link").live("click", function() { var value_str = $(".value_td_rename").text(); - $(".value_td_rename").html(''); + $(".value_td_rename").html(''); }); $(".input_edit_value_rename").live("change", function() { @@ -1065,6 +1055,9 @@ function updateVMInfo(request,vm){ var $hotplugging_tab = $('div#vm_hotplugging_tab', $info_panel); $('tr.at_volatile',$hotplugging_tab).hide(); $('tr.at_image',$hotplugging_tab).show(); + + // Populate permissions grid + setPermissionsTable(vm_info,''); } // Generates the HTML for the hotplugging tab diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 153c5b0e04..65e1ae118b 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -367,16 +367,6 @@ var vnet_actions = { notify: true }, - "Network.fetch_permissions" : { - type: "single", - call: OpenNebula.Network.show, - callback: function(request,vnet_json){ - var vnet = vnet_json.VNET; - setPermissionsTable(vnet,$(".network_permissions_table")); - }, - error: onError - }, - "Network.update_template" : { type: "single", call: OpenNebula.Network.update, @@ -646,7 +636,7 @@ function updateVNetworkInfo(request,vn){ Sunstone.popUpInfoPanel("vnet_info_panel"); - Sunstone.runAction("Network.fetch_permissions",vn_info.ID); + setPermissionsTable(vn_info,''); } diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 00f1deb3b5..6e9f486ff9 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -965,37 +965,6 @@ function setPermissionsTable(resource,context){ $('.other_a',context).attr('checked','checked'); }; -//Returns an octet given a permission table with checkboxes -function buildOctet(permTable){ - var owner=0; - var group=0; - var other=0; - - if ($('.owner_u',permTable).is(':checked')) - owner+=4; - if ($('.owner_m',permTable).is(':checked')) - owner+=2; - if ($('.owner_a',permTable).is(':checked')) - owner+=1; - - if ($('.group_u',permTable).is(':checked')) - group+=4; - if ($('.group_m',permTable).is(':checked')) - group+=2; - if ($('.group_a',permTable).is(':checked')) - group+=1; - - if ($('.other_u',permTable).is(':checked')) - other+=4; - if ($('.other_m',permTable).is(':checked')) - other+=2; - if ($('.other_a',permTable).is(':checked')) - other+=1; - - return ""+owner+group+other; -}; - - // Sets up a dialog to edit and update user and group quotas // Called from user/group plugins function setupQuotasDialog(dialog){ @@ -1405,8 +1374,39 @@ function fromJSONtoHTMLRow(field,value,template_json,resource_type,resource_id){ return str; } +//Returns an octet given a permission table with checkboxes +function buildOctet(permTable){ + var owner=0; + var group=0; + var other=0; + + if ($('.owner_u',permTable).is(':checked')) + owner+=4; + if ($('.owner_m',permTable).is(':checked')) + owner+=2; + if ($('.owner_a',permTable).is(':checked')) + owner+=1; + + if ($('.group_u',permTable).is(':checked')) + group+=4; + if ($('.group_m',permTable).is(':checked')) + group+=2; + if ($('.group_a',permTable).is(':checked')) + group+=1; + + if ($('.other_u',permTable).is(':checked')) + other+=4; + if ($('.other_m',permTable).is(':checked')) + other+=2; + if ($('.other_a',permTable).is(':checked')) + other+=1; + + return ""+owner+group+other; +}; + + // Returns HTML with listeners to control permissions -function insert_permissions_table(resource_type,resource_id){ +function insert_permissions_table(resource_type,resource_id, owner, group, uid, gid){ var str ='
'+tr("Monitoring information")+'
\ \ \ @@ -1415,21 +1415,40 @@ function insert_permissions_table(resource_type,resource_id){ \ \ \ - \ - \ - \ + \ + \ + \ \ \ \ - \ - \ - \ + \ + \ + \ \ \ \ - \ - \ - \ + \ + \ + \ + \ + \\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ \
'+tr("Permissions")+':'+tr("Admin")+'
'+tr("Owner")+'
'+tr("Group")+'
'+tr("Other")+'
'+tr("Ownership")+'
'+tr("Owner")+''+owner+'
\ + e\ +
\ +
'+tr("Group")+''+group+'
\ + e\ +
\ +
' @@ -1441,6 +1460,52 @@ function insert_permissions_table(resource_type,resource_id){ Sunstone.runAction(resource_type+".chmod",resource_id,permissions_octect); }); + // Handlers for chown + $("#div_edit_chg_owner_link").die(); + $("#user_confirm_select").die(); + + // Listener for key,value pair edit action + $("#div_edit_chg_owner_link").live("click", function() { + var value_str = $("#value_td_owner").text(); + var select_str='"; + $("#value_td_owner").html(select_str); + $("select#user_confirm_select").val(uid); + }); + + $("#user_confirm_select").live("change", function() { + var value_str = $('select#user_confirm_select').val(); + if(value_str!="") + { + // Let OpenNebula know + Sunstone.runAction(resource_type+".chown",resource_id,value_str); + } + }); + + // Handlers for chgrp + $("#div_edit_chg_group_link").die(); + $("#group_confirm_select").die(); + + // Listener for key,value pair edit action + $("#div_edit_chg_group_link").live("click", function() { + var value_str = $("#value_td_group").text(); + var select_str='"; + $("#value_td_group").html(select_str); + $("select#group_confirm_select").val(gid); + }); + + $("#group_confirm_select").live("change", function() { + var value_str = $('select#group_confirm_select').val(); + if(value_str!="") + { + // Let OpenNebula know + Sunstone.runAction(resource_type+".chgrp",resource_id,value_str); + } + }); + return str; } \ No newline at end of file diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index 0003aa3b9c..d3daa3f7b0 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -73,7 +73,7 @@ var Sunstone = { "updateMainTabContent" : function(tab_id,content_arg,refresh){ SunstoneCfg["tabs"][tab_id]["content"]=content_arg; //if not present it will not be updated - if (refresh){ + if (refresh){ $('div#'+tab_id, main_tabs_context).html(content_arg); } }, @@ -393,7 +393,7 @@ function readCookie(){ }); } -//sets the user info in the top bar and creates a listner in the +//sets the user info in the top bar and creates a listener in the //signout button function setLogin(){ //This variables can be used anywhere