diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js
index 311d8e989d..8bf85bd912 100644
--- a/src/sunstone/public/js/plugins/clusters-tab.js
+++ b/src/sunstone/public/js/plugins/clusters-tab.js
@@ -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 :
'
\
\
- | ' + tr("Information for cluster") + ' - '+cluster_info.NAME+' |
\
+ | ' +
+ tr("Information for cluster") +
+ ' - '+cluster_info.NAME+' |
\
\
\
\
@@ -1323,13 +1328,10 @@ function updateClusterInfo(request,cluster){
| '+cluster_info.NAME+' | \
\
\
-
\
- \
- | ' + tr("Cluster template") + ' |
'+
- prettyPrintJSON(cluster_info.TEMPLATE)+
- '
'+
- '
'
-
+ ' +
+ 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");
diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js
index f11aa4a365..c3c761fcad 100644
--- a/src/sunstone/public/js/plugins/vnets-tab.js
+++ b/src/sunstone/public/js/plugins/vnets-tab.js
@@ -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 =''
+
+ $(".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 =
'\
\
- | '+tr("Virtual Network")+' '+vn_info.ID+' '+
- tr("information")+' |
\
+ | '+tr("Information for Virtual Network")+' '+vn_info.NAME+' '+
+ ' |
\
\
\
| '+tr("ID")+' | \
@@ -605,30 +645,18 @@ function updateVNetworkInfo(request,vn){
'+tr("VLAN ID")+' | \
'+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +' | \
\
- | '+tr("Permissions")+' | |
\
- \
- | '+tr("Owner")+' | \
- '+ownerPermStr(vn_info)+' | \
-
\
- \
- | '+tr("Group")+' | \
- '+groupPermStr(vn_info)+' | \
-
\
- \
- | '+tr("Other")+' | \
- '+otherPermStr(vn_info)+' | \
-
\
';
- info_tab_content += '\
- \
- | '+tr("Virtual Network template (attributes)")+' |
'+
- prettyPrintJSON(vn_info.TEMPLATE)+
- '
';
+ info_tab_content += insert_extended_template_table(vn_info.TEMPLATE,
+ "Network",
+ vn_info.ID);
+
+ info_tab_content += ''+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;
- });
};
diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js
index c2bc9fb84b..5e656305e5 100644
--- a/src/sunstone/public/js/sunstone-util.js
+++ b/src/sunstone/public/js/sunstone-util.js
@@ -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 = ''
+
+ // 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(field)+' | \
+ | \
+ | \
+
';
+ //attributes rows
+ //empty row - prettyprint - empty row
+ str += '\
+ | \
+ | \
+
' + fromJSONtoHTMLTable(value) +
+ '\
+ | \
+ | \
+
';
+ } else {
+ str += '\
+ | '+tr(field)+' | \
+ '+value+' | \
+ \
+ | \
+
';
+ };
+
+ return str;
}
\ No newline at end of file