mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-17 18:33:32 +09:00
feature #1664: Generic exteded template table
Advance on permissions table
This commit is contained in:
1 parent
8b80531d58
commit
bc3e2eca95
3 files changed
+203
-63
No files matched your search
@@ -341,7 +341,7 @@ function setupCreateClusterDialog(datatable_filter){
|
||||
});
|
||||
|
||||
// Add tag listeners
|
||||
$( "#cluster_create_tabs span.ui-icon-close",$create_cluster_dialog).die('click');
|
||||
$( "#cluster_create_tabs span.ui-icon-close",$create_cluster_dialog).die();
|
||||
$( "#cluster_create_tabs span.ui-icon-close" ).live( "click", function() {
|
||||
// Remove the tag
|
||||
$(this).parent().remove();
|
||||
@@ -999,14 +999,15 @@ var cluster_actions = {
|
||||
notify:true
|
||||
},
|
||||
|
||||
/* "Cluster.update_template" : { // Update template
|
||||
"Cluster.update_template" : { // Update template
|
||||
type: "single",
|
||||
call: OpenNebula.Cluster.update,
|
||||
callback: function(){
|
||||
notifyMessage(tr("Template updated correctly"));
|
||||
callback: function(request,response){
|
||||
notifyMessage(tr("Template updated correctly"));
|
||||
Sunstone.runAction('Cluster.showinfo',request.request.data[0]);
|
||||
},
|
||||
error: onError
|
||||
},*/
|
||||
},
|
||||
|
||||
"Cluster.fetch_template" : {
|
||||
type: "single",
|
||||
@@ -1301,9 +1302,11 @@ function updateClustersView (request,list){
|
||||
updateInfraDashboard("clusters",list);
|
||||
};
|
||||
|
||||
|
||||
// Updates the cluster info panel tab content and pops it up
|
||||
function updateClusterInfo(request,cluster){
|
||||
cluster_info = cluster.CLUSTER;
|
||||
cluster_info = cluster.CLUSTER;
|
||||
cluster_template = cluster_info.TEMPLATE;
|
||||
|
||||
//Information tab
|
||||
var info_tab = {
|
||||
@@ -1311,7 +1314,9 @@ function updateClusterInfo(request,cluster){
|
||||
content :
|
||||
'<table id="info_cluster_table" class="info_table">\
|
||||
<thead>\
|
||||
<tr><th colspan="2">' + tr("Information for cluster") + ' - '+cluster_info.NAME+'</th></tr>\
|
||||
<tr><th colspan="2">' +
|
||||
tr("Information for cluster") +
|
||||
' - '+cluster_info.NAME+'</th></tr>\
|
||||
</thead>\
|
||||
<tbody>\
|
||||
<tr>\
|
||||
@@ -1323,13 +1328,10 @@ function updateClusterInfo(request,cluster){
|
||||
<td class="value_td">'+cluster_info.NAME+'</td>\
|
||||
</tr>\
|
||||
</tbody>\
|
||||
</table>\
|
||||
<table id="cluster_template_table" class="info_table">\
|
||||
<thead><tr><th colspan="2">' + tr("Cluster template") + '</th></tr></thead>'+
|
||||
prettyPrintJSON(cluster_info.TEMPLATE)+
|
||||
'</table>'+
|
||||
'<hr/>'
|
||||
|
||||
</table>' +
|
||||
insert_extended_template_table(cluster_template,
|
||||
"Cluster",
|
||||
cluster_info.ID)
|
||||
}
|
||||
|
||||
var cluster_host_tab = {
|
||||
@@ -1449,8 +1451,7 @@ function updateClusterInfo(request,cluster){
|
||||
spinner,
|
||||
'','','','','','','','','','','',''],dataTable_cluster_datastores_panel);
|
||||
|
||||
// initializa datatables values
|
||||
|
||||
// initialize datatables values
|
||||
Sunstone.runAction("ClusterHostInfo.list");
|
||||
Sunstone.runAction("ClusterVNInfo.list");
|
||||
Sunstone.runAction("ClusterDSInfo.list");
|
||||
|
||||
@@ -368,9 +368,8 @@ var vnet_actions = {
|
||||
type: "single",
|
||||
call: OpenNebula.Network.show,
|
||||
callback: function(request,vnet_json){
|
||||
var dialog = $('#vnet_template_update_dialog form');
|
||||
var vnet = vnet_json.VNET;
|
||||
setPermissionsTable(vnet,dialog);
|
||||
setPermissionsTable(vnet,$(".network_permissions_table"));
|
||||
},
|
||||
error: onError
|
||||
},
|
||||
@@ -380,11 +379,12 @@ var vnet_actions = {
|
||||
call: popUpVNetTemplateUpdateDialog
|
||||
},
|
||||
|
||||
"Network.update" : {
|
||||
"Network.update_template" : {
|
||||
type: "single",
|
||||
call: OpenNebula.Network.update,
|
||||
callback: function() {
|
||||
callback: function(request) {
|
||||
notifyMessage("Template updated correctly");
|
||||
Sunstone.runAction('Network.showinfo',request.request.data[0]);
|
||||
},
|
||||
error: onError
|
||||
},
|
||||
@@ -560,14 +560,54 @@ function updateVNetworksView(request, network_list){
|
||||
|
||||
}
|
||||
|
||||
function insert_permissions_table(resource_type,resource_id){
|
||||
var str ='<table class="'+resource_type.toLowerCase()+'_permissions_table" style="padding:0 10px;">\
|
||||
<thead><tr>\
|
||||
<td style="width:130px">'+tr("Permissions")+':</td>\
|
||||
<td style="width:40px;text-align:center;">'+tr("Use")+'</td>\
|
||||
<td style="width:40px;text-align:center;">'+tr("Manage")+'</td>\
|
||||
<td style="width:40px;text-align:center;">'+tr("Admin")+'</td></tr></thead>\
|
||||
<tr>\
|
||||
<td>'+tr("Owner")+'</td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_owner_u" class="permission_check owner_u" /></td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_owner_m" class="permission_check owner_m" /></td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_owner_a" class="permission_check owner_a" /></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td>'+tr("Group")+'</td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_owner_u" class="permission_check group_u" /></td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_group_m" class="permission_check group_m" /></td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_group_a" class="permission_check group_a" /></td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td>'+tr("Other")+'</td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_other_u" class="permission_check other_u" /></td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_other_m" class="permission_check other_m" /></td>\
|
||||
<td style="text-align:center"><input type="checkbox" name="vnet_other_a" class="permission_check other_a" /></td>\
|
||||
</tr>\
|
||||
</table>'
|
||||
|
||||
$(".permission_check").die();
|
||||
$(".permission_check").live('change',function(){
|
||||
var permissions_table = $("."+resource_type.toLowerCase()+"_permissions_table");
|
||||
var permissions_octect = { octet : buildOctet(permissions_table) };
|
||||
|
||||
Sunstone.runAction("Network.chmod",resource_id,permissions_octect);
|
||||
});
|
||||
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//updates the information panel tabs and pops the panel up
|
||||
function updateVNetworkInfo(request,vn){
|
||||
var vn_info = vn.VNET;
|
||||
var info_tab_content =
|
||||
'<table id="info_vn_table" class="info_table">\
|
||||
<thead>\
|
||||
<tr><th colspan="2">'+tr("Virtual Network")+' '+vn_info.ID+' '+
|
||||
tr("information")+'</th></tr>\
|
||||
<tr><th colspan="2">'+tr("Information for Virtual Network")+' '+vn_info.NAME+' '+
|
||||
'</th></tr>\
|
||||
</thead>\
|
||||
<tr>\
|
||||
<td class="key_td">'+tr("ID")+'</td>\
|
||||
@@ -605,30 +645,18 @@ function updateVNetworkInfo(request,vn){
|
||||
<td class="key_td">'+tr("VLAN ID")+'</td>\
|
||||
<td class="value_td">'+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +'</td>\
|
||||
</tr>\
|
||||
<tr><td class="key_td">'+tr("Permissions")+'</td><td></td></tr>\
|
||||
<tr>\
|
||||
<td class="key_td"> '+tr("Owner")+'</td>\
|
||||
<td class="value_td" style="font-family:monospace;">'+ownerPermStr(vn_info)+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td"> '+tr("Group")+'</td>\
|
||||
<td class="value_td" style="font-family:monospace;">'+groupPermStr(vn_info)+'</td>\
|
||||
</tr>\
|
||||
<tr>\
|
||||
<td class="key_td"> '+tr("Other")+'</td>\
|
||||
<td class="value_td" style="font-family:monospace;">'+otherPermStr(vn_info)+'</td>\
|
||||
</tr>\
|
||||
</table>';
|
||||
|
||||
info_tab_content += '\
|
||||
<table id="vn_template_table" class="info_table">\
|
||||
<thead><tr><th colspan="2">'+tr("Virtual Network template (attributes)")+'</th></tr></thead>'+
|
||||
prettyPrintJSON(vn_info.TEMPLATE)+
|
||||
'</table>';
|
||||
info_tab_content += insert_extended_template_table(vn_info.TEMPLATE,
|
||||
"Network",
|
||||
vn_info.ID);
|
||||
|
||||
info_tab_content += '<table class="info_table"><thead><tr><th colspan="2"></th></tr></thead>\
|
||||
<tr></tr></table>'+insert_permissions_table("Network",vn_info.ID);
|
||||
|
||||
|
||||
var info_tab = {
|
||||
title: tr("Virtual Network information"),
|
||||
title: tr("Information"),
|
||||
content: info_tab_content
|
||||
};
|
||||
|
||||
@@ -642,6 +670,8 @@ function updateVNetworkInfo(request,vn){
|
||||
|
||||
Sunstone.popUpInfoPanel("vnet_info_panel");
|
||||
|
||||
Sunstone.runAction("Network.fetch_permissions",vn_info.ID);
|
||||
|
||||
}
|
||||
|
||||
// Prints the lis of leases depending on the Vnet TYPE
|
||||
@@ -1063,27 +1093,7 @@ function setupVNetTemplateUpdateDialog(){
|
||||
$(this).parents('table').attr('update','update');
|
||||
});
|
||||
|
||||
$('form',dialog).submit(function(){
|
||||
var dialog = $(this);
|
||||
var new_template = $('#vnet_template_update_textarea',dialog).val();
|
||||
var id = $('#vnet_template_update_select',dialog).val();
|
||||
if (!id || !id.length) {
|
||||
$(this).parents('#vnet_template_update_dialog').dialog('close');
|
||||
return false;
|
||||
};
|
||||
|
||||
var permissions = $('.permissions_table',dialog);
|
||||
if (permissions.attr('update')){
|
||||
var perms = {
|
||||
octet : buildOctet(permissions)
|
||||
};
|
||||
Sunstone.runAction("Network.chmod",id,perms);
|
||||
};
|
||||
|
||||
Sunstone.runAction("Network.update",id,new_template);
|
||||
$(this).parents('#vnet_template_update_dialog').dialog('close');
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ function notifyMessage(msg){
|
||||
// Returns an HTML string with the json keys and values
|
||||
// Attempts to css format output, giving different values to
|
||||
// margins etc. according to depth level etc.
|
||||
// See exapmle of use in plugins.
|
||||
// See example of use in plugins.
|
||||
function prettyPrintJSON(template_json,padding,weight, border_bottom,padding_top_bottom){
|
||||
var str = ""
|
||||
if (!template_json){ return "Not defined";}
|
||||
@@ -1217,7 +1217,7 @@ function quotaListItem(quota_json){
|
||||
*/
|
||||
function progressBar(value, opts){
|
||||
if (value > 100) value = 100;
|
||||
|
||||
|
||||
if (!opts) opts = {};
|
||||
|
||||
if (!opts.width) opts.width = 'auto';
|
||||
@@ -1261,4 +1261,133 @@ function loadAccounting(resource, id, graphs, options){
|
||||
graph_cfg.show_date = (end - start) > (3600 * 24)? true : false;
|
||||
Sunstone.runAction(resource+".accounting", id, graph_cfg);
|
||||
};
|
||||
}
|
||||
|
||||
function insert_extended_template_table(template_json,resource_type,resource_id)
|
||||
{
|
||||
var str = '<table id="'+resource_type.toLowerCase()+'_template_table" class="info_table">\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th colspan="2">' +
|
||||
tr("Extended Template") +
|
||||
'</th>\
|
||||
</tr>\
|
||||
</thead>' + fromJSONtoHTMLTable(template_json,
|
||||
resource_type,
|
||||
resource_id) +
|
||||
'<tr>\
|
||||
<td class="key_td"><input type="text" name="new_key" id="new_key" /></td>\
|
||||
<td class="value_td"><input type="text" name="new_value" id="new_value" /></td>\
|
||||
</tr>\
|
||||
</table>'
|
||||
|
||||
// Remove previous listeners
|
||||
$("#new_key").die();
|
||||
$("#new_value").die();
|
||||
$("#div_minus").die();
|
||||
|
||||
// Add listener for add key and add value for Extended Template
|
||||
$("#new_key").live("change", function() {
|
||||
if ( $('#new_value').val() != "" )
|
||||
{
|
||||
template_json[$('#new_key').val()] = $('#new_value').val();
|
||||
|
||||
var template_str = "";
|
||||
for(var key in template_json)
|
||||
template_str=template_str+key+"="+ template_json[key]+"\n";
|
||||
|
||||
Sunstone.runAction(resource_type+".update_template",resource_id,template_str);
|
||||
}
|
||||
});
|
||||
|
||||
$("#new_value").live("change", function() {
|
||||
if ( $('#new_key').val() != "" )
|
||||
{
|
||||
template_json[$('#new_key').val()] = $('#new_value').val();
|
||||
|
||||
var template_str = "";
|
||||
for(var key in template_json)
|
||||
template_str=template_str+key+"="+ template_json[key]+"\n";
|
||||
|
||||
Sunstone.runAction(resource_type+".update_template",resource_id,template_str);
|
||||
}
|
||||
});
|
||||
|
||||
// Listener for key,value pair remove action
|
||||
$("#div_minus").live("click", function() {
|
||||
// Remove div_minus_ from the id
|
||||
field=this.firstElementChild.id.substring(10,this.firstElementChild.id.length);
|
||||
// Erase the value from the template
|
||||
delete template_json[tr(field)];
|
||||
|
||||
// Convert from hash to string
|
||||
var template_str = "\n";
|
||||
for(var key in template_json)
|
||||
template_str=template_str+key+"="+ template_json[key]+"\n";
|
||||
|
||||
// Let OpenNebula know
|
||||
Sunstone.runAction(resource_type+".update_template",resource_id,template_str);
|
||||
});
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// Returns an HTML string with the json keys and values
|
||||
function fromJSONtoHTMLTable(template_json,resource_type,resource_id){
|
||||
var str = ""
|
||||
if (!template_json){ return "Not defined";}
|
||||
var field = null;
|
||||
|
||||
if (template_json.constructor == Array){
|
||||
for (field = 0; field < template_json.length; ++field){
|
||||
str += fromJSONtoHTMLRow(field,
|
||||
template_json[field],
|
||||
template_json,
|
||||
resource_type,
|
||||
resource_id);
|
||||
}
|
||||
} else {
|
||||
for (field in template_json) {
|
||||
str += fromJSONtoHTMLRow(field,
|
||||
template_json[field],
|
||||
template_json,
|
||||
resource_type,
|
||||
resource_id);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function fromJSONtoHTMLRow(field,value,template_json,resource_type,resource_id){
|
||||
var str="";
|
||||
|
||||
if (typeof value == 'object'){
|
||||
//name of field row
|
||||
str += '<tr>\
|
||||
<td class="key_td">'+tr(field)+'</td>\
|
||||
<td class="value_td"></td>\
|
||||
<td class="value_td"></td>\
|
||||
</tr>';
|
||||
//attributes rows
|
||||
//empty row - prettyprint - empty row
|
||||
str += '<tr>\
|
||||
<td class="key_td" style="border-bottom:0"></td>\
|
||||
<td class="value_td" style="border-bottom:0"></td>\
|
||||
</tr>' + fromJSONtoHTMLTable(value) +
|
||||
'<tr>\
|
||||
<td class="key_td"></td>\
|
||||
<td class="value_td"></td>\
|
||||
</tr>';
|
||||
} else {
|
||||
str += '<tr>\
|
||||
<td class="key_td">'+tr(field)+'</td>\
|
||||
<td class="value_td">'+value+'</td>\
|
||||
<td><div id="div_minus">\
|
||||
<a id="div_minus_'+tr(field)+'" class="remove_x" href="#">x</a>\
|
||||
</div>\
|
||||
</td>\
|
||||
</tr>';
|
||||
};
|
||||
|
||||
return str;
|
||||
}
|
||||
Reference in new issue
Block a user