1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-30 22:50:10 +03:00

Feature #3471: Add groups and resources to create and update dialogs

This commit is contained in:
Carlos Martín 2015-01-13 16:29:31 +01:00
parent 7fbc724180
commit ee9629cf0a
3 changed files with 954 additions and 98 deletions

View File

@ -744,6 +744,9 @@ var OpenNebula = {
"list": function(params){
OpenNebula.Action.list(params,OpenNebula.Host.resource);
},
"list_in_zone" : function(params){
OpenNebula.Action.list_in_zone(params,OpenNebula.Host.resource);
},
"show": function(params){
OpenNebula.Action.show(params,OpenNebula.Host.resource);
},
@ -790,6 +793,9 @@ var OpenNebula = {
"list": function(params){
OpenNebula.Action.list(params,OpenNebula.Network.resource);
},
"list_in_zone" : function(params){
OpenNebula.Action.list_in_zone(params,OpenNebula.Network.resource);
},
"show": function(params){
OpenNebula.Action.show(params,OpenNebula.Network.resource);
},
@ -1459,6 +1465,9 @@ var OpenNebula = {
"list" : function(params){
OpenNebula.Action.list(params,OpenNebula.Datastore.resource);
},
"list_in_zone" : function(params){
OpenNebula.Action.list_in_zone(params,OpenNebula.Datastore.resource);
},
"show" : function(params){
OpenNebula.Action.show(params,OpenNebula.Datastore.resource);
},

View File

@ -19,6 +19,8 @@ var create_vdc_wizard_html =
<div>\
<dl id="vdc_create_tabs" class="tabs right-info-tabs text-center" data-tab>\
<dd class="active"><a href="#vdcCreateGeneralTab"><i class="fa fa-globe"></i><br>'+tr("General")+'</a></dd>\
<dd><a href="#vdcCreateGroupsTab"><i class="fa fa-users"></i><br>'+tr("Groups")+'</a></dd>\
<dd><a href="#vdcCreateResourcesTab"><i class="fa fa-hdd-o"></i><br>'+tr("Resources")+'</a></dd>\
</dl>\
<div id="vdc_create_tabs_content" class="tabs-content">\
<div class="content active" id="vdcCreateGeneralTab">\
@ -48,6 +50,22 @@ var create_vdc_wizard_html =
</div>'+
customTagsHtml()+'\
</div>\
<div id="vdcCreateGroupsTab" class="content">\
'+generateGroupTableSelect("vdc_wizard_groups")+'\
</div>\
<div id="vdcCreateResourcesTab" class="content">\
<div class="row">\
<div class="large-12 columns">\
<h5>' + tr("Zones") +'</h5>\
</div>\
</div>\
<div class="row">\
<div class="large-12 columns">\
<dl class="tabs" id="vdc_zones_tabs" data-tab></dl>\
<div class="tabs-content vdc_zones_tabs_content"></div>\
</div>\
</div>\
</div>\
</div>\
</div>\
</form>';
@ -79,6 +97,43 @@ var vdc_actions = {
$("a[href=back]", $("#vdcs-tab")).trigger("click");
popFormDialog("create_vdc_form", $("#vdcs-tab"));
var group_ids = request.request.data[0].group_ids;
$.each(group_ids,function(){
Sunstone.runAction("Vdc.add_group",
response.VDC.ID,
{ group_id : parseInt(this)});
});
var clusters = request.request.data[0].clusters;
$.each(clusters,function(){
Sunstone.runAction("Vdc.add_cluster",
response.VDC.ID,
this);
});
var hosts = request.request.data[0].hosts;
$.each(hosts,function(){
Sunstone.runAction("Vdc.add_host",
response.VDC.ID,
this);
});
var vnets = request.request.data[0].vnets;
$.each(vnets,function(){
Sunstone.runAction("Vdc.add_vnet",
response.VDC.ID,
this);
});
var datastores = request.request.data[0].datastores;
$.each(datastores,function(){
Sunstone.runAction("Vdc.add_datastore",
response.VDC.ID,
this);
});
Sunstone.runAction('Vdc.show',request.request.data[0][0]);
addVdcElement(request, response);
notifyCustom(tr("Virtual Data Center created"), " ID: " + response.VDC.ID, false);
},
@ -89,9 +144,26 @@ var vdc_actions = {
type: "custom",
call: function(){
Sunstone.popUpFormPanel("create_vdc_form", "vdcs-tab", "create", true, function(context){
refreshSecurityGroupTableSelect(context, "vdc_create");
refreshGroupTableSelect(context, "vdc_wizard_groups");
var zone_ids = [];
OpenNebula.Zone.list({
timeout: true,
success: function (request, obj_list){
$.each(obj_list,function(){
zone_ids.push(this.ZONE.ID);
addVdcResourceTab(this.ZONE.ID,
this.ZONE.NAME,
context);
});
context.data("zone_ids", zone_ids);
},
error: onError
});
$("#default_sg_warning").show();
$("input#name",context).focus();
});
}
@ -169,8 +241,6 @@ var vdc_actions = {
Sunstone.popUpFormPanel("create_vdc_form", "vdcs-tab", "update", true, function(context){
fillVdcUpdateFormPanel(response.VDC, context);
$("#default_sg_warning").hide();
});
},
error: onError
@ -199,6 +269,96 @@ var vdc_actions = {
Sunstone.runAction('Vdc.show',request.request.data[0][0]);
},
error: onError
},
"Vdc.add_group" : {
type: "single",
call : OpenNebula.Vdc.add_group,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.del_group" : {
type: "single",
call : OpenNebula.Vdc.del_group,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.add_cluster" : {
type: "single",
call : OpenNebula.Vdc.add_cluster,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.del_cluster" : {
type: "single",
call : OpenNebula.Vdc.del_cluster,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.add_host" : {
type: "single",
call : OpenNebula.Vdc.add_host,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.del_host" : {
type: "single",
call : OpenNebula.Vdc.del_host,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.add_vnet" : {
type: "single",
call : OpenNebula.Vdc.add_vnet,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.del_vnet" : {
type: "single",
call : OpenNebula.Vdc.del_vnet,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.add_datastore" : {
type: "single",
call : OpenNebula.Vdc.add_datastore,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
},
"Vdc.del_datastore" : {
type: "single",
call : OpenNebula.Vdc.del_datastore,
callback : function (req) {
//Sunstone.runAction('Vdc.show',req.request.data[0][0]);
},
error : onError
}
};
@ -382,6 +542,8 @@ function initialize_create_vdc_dialog(dialog) {
setupCustomTags($("#vdcCreateGeneralTab", dialog));
setupGroupTableSelect(dialog, "vdc_wizard_groups", {multiple_choice: true});
dialog.foundation();
//Process form
@ -396,14 +558,159 @@ function initialize_create_vdc_dialog(dialog) {
retrieveCustomTags($("#vdcCreateGeneralTab", dialog), vdc_json);
var group_ids = retrieveGroupTableSelect(dialog, "vdc_wizard_groups");
if ($('#create_vdc_form_wizard',dialog).attr("action") == "create") {
var zone_ids = dialog.data("zone_ids");
var clusters = [];
var hosts = [];
var vnets = [];
var datastores = [];
$.each(zone_ids,function(i,zone_id){
var selected_clusters = retrieveClusterTableSelect(dialog, "vdc_wizard_clusters_zone_"+this);
$.each(selected_clusters,function(j,cluster_id){
clusters.push({zone_id: zone_id, cluster_id: cluster_id});
});
var selected_hosts = retrieveHostTableSelect(dialog, "vdc_wizard_hosts_zone_"+this);
$.each(selected_hosts,function(j,host_id){
hosts.push({zone_id: zone_id, host_id: host_id});
});
var selected_vnets = retrieveVNetTableSelect(dialog, "vdc_wizard_vnets_zone_"+this);
$.each(selected_vnets,function(j,vnet_id){
vnets.push({zone_id: zone_id, vnet_id: vnet_id});
});
var selected_datastores = retrieveDatastoreTableSelect(dialog, "vdc_wizard_datastores_zone_"+this);
$.each(selected_datastores,function(j,ds_id){
datastores.push({zone_id: zone_id, ds_id: ds_id});
});
});
vdc_json = {
"vdc" : vdc_json
"vdc" : vdc_json,
"group_ids" : group_ids,
"clusters" : clusters,
"hosts" : hosts,
"vnets" : vnets,
"datastores" : datastores
};
Sunstone.runAction("Vdc.create",vdc_json);
return false;
} else if ($('#create_vdc_form_wizard',dialog).attr("action") == "update") {
// Add/delete groups
var selected_groups_list = retrieveGroupTableSelect(dialog, "vdc_wizard_groups");
var original_groups_list = dialog.data("original_groups_list");
$.each(selected_groups_list, function(i,group_id){
if (original_groups_list.indexOf(group_id) == -1){
Sunstone.runAction("Vdc.add_group",
vdc_to_update_id, {group_id : group_id});
}
});
$.each(original_groups_list, function(i,group_id){
if (selected_groups_list.indexOf(group_id) == -1){
Sunstone.runAction("Vdc.del_group",
vdc_to_update_id, {group_id : group_id});
}
});
// Add/delete resources
original_resources = dialog.data("original_resources")
for (var zone_id in original_resources){
var selected_clusters = retrieveClusterTableSelect(dialog, "vdc_wizard_clusters_zone_"+zone_id);
var selected_hosts = retrieveHostTableSelect(dialog, "vdc_wizard_hosts_zone_"+zone_id);
var selected_vnets = retrieveVNetTableSelect(dialog, "vdc_wizard_vnets_zone_"+zone_id);
var selected_datastores = retrieveDatastoreTableSelect(dialog, "vdc_wizard_datastores_zone_"+zone_id);
var original_clusters = original_resources[zone_id].clusters_list;
var original_hosts = original_resources[zone_id].hosts_list;
var original_vnets = original_resources[zone_id].vnets_list;
var original_datastores = original_resources[zone_id].datastores_list;
$.each(selected_clusters, function(i,cluster_id){
if (original_clusters.indexOf(cluster_id) == -1){
Sunstone.runAction(
"Vdc.add_cluster",
vdc_to_update_id,
{zone_id: zone_id, cluster_id: cluster_id});
}
});
$.each(original_clusters, function(i,cluster_id){
if (selected_clusters.indexOf(cluster_id) == -1){
Sunstone.runAction(
"Vdc.del_cluster",
vdc_to_update_id,
{zone_id: zone_id, cluster_id: cluster_id});
}
});
$.each(selected_hosts, function(i,host_id){
if (original_hosts.indexOf(host_id) == -1){
Sunstone.runAction(
"Vdc.add_host",
vdc_to_update_id,
{zone_id: zone_id, host_id: host_id});
}
});
$.each(original_hosts, function(i,host_id){
if (selected_hosts.indexOf(host_id) == -1){
Sunstone.runAction(
"Vdc.del_host",
vdc_to_update_id,
{zone_id: zone_id, host_id: host_id});
}
});
$.each(selected_vnets, function(i,vnet_id){
if (original_vnets.indexOf(vnet_id) == -1){
Sunstone.runAction(
"Vdc.add_vnet",
vdc_to_update_id,
{zone_id: zone_id, vnet_id: vnet_id});
}
});
$.each(original_vnets, function(i,vnet_id){
if (selected_vnets.indexOf(vnet_id) == -1){
Sunstone.runAction(
"Vdc.del_vnet",
vdc_to_update_id,
{zone_id: zone_id, vnet_id: vnet_id});
}
});
$.each(selected_datastores, function(i,ds_id){
if (original_datastores.indexOf(ds_id) == -1){
Sunstone.runAction(
"Vdc.add_datastore",
vdc_to_update_id,
{zone_id: zone_id, ds_id: ds_id});
}
});
$.each(original_datastores, function(i,ds_id){
if (selected_datastores.indexOf(ds_id) == -1){
Sunstone.runAction(
"Vdc.del_datastore",
vdc_to_update_id,
{zone_id: zone_id, ds_id: ds_id});
}
});
}
Sunstone.runAction("Vdc.update", vdc_to_update_id, convert_template_to_string(vdc_json));
return false;
}
@ -454,6 +761,192 @@ function fillVdcUpdateFormPanel(vdc, dialog){
});
fillCustomTags($("#vdcCreateGeneralTab", dialog), vdc.TEMPLATE);
// Fill groups table
var group_ids = vdc.GROUPS.ID;
if (typeof group_ids == 'string')
{
group_ids = [group_ids];
}
var original_groups_list = [];
if (group_ids)
{
original_groups_list = group_ids;
selectGroupTableSelect(dialog, "vdc_wizard_groups", { ids : group_ids });
}
dialog.data("original_groups_list", original_groups_list);
// Fill resource tables
var clusters_array = [];
var hosts_array = [];
var vnets_array = [];
var datastores_array = [];
if (vdc != undefined){
if (vdc.CLUSTERS.CLUSTER){
clusters_array = vdc.CLUSTERS.CLUSTER;
if (!$.isArray(clusters_array)){
clusters_array = [clusters_array];
}
}
if (vdc.HOSTS.HOST){
hosts_array = vdc.HOSTS.HOST;
if (!$.isArray(hosts_array)){
hosts_array = [hosts_array];
}
}
if (vdc.VNETS.VNET){
vnets_array = vdc.VNETS.VNET;
if (!$.isArray(vnets_array)){
vnets_array = [vnets_array];
}
}
if (vdc.DATASTORES.DATASTORE){
datastores_array = vdc.DATASTORES.DATASTORE;
if (!$.isArray(datastores_array)){
datastores_array = [datastores_array];
}
}
}
var zone_ids = [];
OpenNebula.Zone.list({
timeout: true,
success: function (request, obj_list){
var resources = {};
$.each(obj_list,function(){
var zone_id = this.ZONE.ID;
zone_ids.push(zone_id);
addVdcResourceTab(zone_id,
this.ZONE.NAME,
dialog);
// Filter the resources for this zone only
var cluster_ids = [];
$.each(clusters_array, function(i,e){
if(e.ZONE_ID == zone_id){
cluster_ids.push(e.CLUSTER_ID);
}
});
var host_ids = [];
$.each(hosts_array, function(i,e){
if(e.ZONE_ID == zone_id){
host_ids.push(e.HOST_ID);
}
});
var vnet_ids = [];
$.each(vnets_array, function(i,e){
if(e.ZONE_ID == zone_id){
vnet_ids.push(e.VNET_ID);
}
});
var datastore_ids = [];
$.each(datastores_array, function(i,e){
if(e.ZONE_ID == zone_id){
datastore_ids.push(e.DATASTORE_ID);
}
});
resources[zone_id] = {
clusters_list : cluster_ids,
hosts_list : host_ids,
vnets_list : vnet_ids,
datastores_list : datastore_ids
};
selectClusterTableSelect(dialog, "vdc_wizard_clusters_zone_"+zone_id, { ids : cluster_ids });
selectHostTableSelect(dialog, "vdc_wizard_hosts_zone_"+zone_id, { ids : host_ids });
selectVNetTableSelect(dialog, "vdc_wizard_vnets_zone_"+zone_id, { ids : vnet_ids });
selectDatastoreTableSelect(dialog, "vdc_wizard_datastores_zone_"+zone_id, { ids : datastore_ids });
});
dialog.data("original_resources", resources);
dialog.data("zone_ids", zone_ids);
},
error: onError
});
}
function addVdcResourceTab(zone_id, zone_name, dialog, vdc) {
var str_zone_tab_id = dialog.attr('id') + '_zone' + zone_id;
// Append the new div containing the tab and add the tab to the list
var html_tab_content = '<div id="'+str_zone_tab_id+'Tab" class="content">'+
generateVdcResourceTabContent(str_zone_tab_id, zone_id) +
'</div>'
$(html_tab_content).appendTo($(".vdc_zones_tabs_content", dialog));
var a = $("<dd>\
<a id='zone_tab"+str_zone_tab_id+"' href='#"+str_zone_tab_id+"Tab'>"+zone_name+"</a>\
</dd>").appendTo($("dl#vdc_zones_tabs", dialog));
var zone_section = $('#' +str_zone_tab_id+'Tab', dialog);
zone_section.foundation();
$("dl#vdc_zones_tabs", dialog).children("dd").first().children("a").click();
setupClusterTableSelect(zone_section, "vdc_wizard_clusters_zone_"+zone_id, {multiple_choice: true, zone_id: zone_id});
setupHostTableSelect(zone_section, "vdc_wizard_hosts_zone_"+zone_id, {multiple_choice: true, zone_id: zone_id});
setupVNetTableSelect(zone_section, "vdc_wizard_vnets_zone_"+zone_id, {multiple_choice: true, zone_id: zone_id});
setupDatastoreTableSelect(zone_section, "vdc_wizard_datastores_zone_"+zone_id, {multiple_choice: true, zone_id: zone_id});
refreshClusterTableSelect(zone_section, "vdc_wizard_clusters_zone_"+zone_id);
refreshHostTableSelect(zone_section, "vdc_wizard_hosts_zone_"+zone_id);
refreshVNetTableSelect(zone_section, "vdc_wizard_vnets_zone_"+zone_id);
refreshDatastoreTableSelect(zone_section, "vdc_wizard_datastores_zone_"+zone_id);
}
function generateVdcResourceTabContent(str_zone_tab_id, zone_id){
var html =
'<div class="row">\
<div class="large-12 columns">\
<dl class="tabs right-info-tabs text-center" data-tab>\
<dd class="active"><a href="#vdcCreateClustersTab_'+zone_id+'"><i class="fa fa-hdd-o"></i><br>'+tr("Clusters")+'</a></dd>\
<dd><a href="#vdcCreateHostsTab_'+zone_id+'"><i class="fa fa-hdd-o"></i><br>'+tr("Hosts")+'</a></dd>\
<dd><a href="#vdcCreateVnetsTab_'+zone_id+'"><i class="fa fa-upload"></i><br>'+tr("VNets")+'</a></dd>\
<dd><a href="#vdcCreateDatastoresTab_'+zone_id+'"><i class="fa fa-folder-open"></i><br>'+tr("Datastores")+'</a></dd>\
</dl>\
<div class="tabs-content">\
<div class="content active" id="vdcCreateClustersTab_'+zone_id+'" class="content">\
'+generateClusterTableSelect("vdc_wizard_clusters_zone_"+zone_id)+'\
</div>\
<div id="vdcCreateHostsTab_'+zone_id+'" class="content">\
'+generateHostTableSelect("vdc_wizard_hosts_zone_"+zone_id)+'\
</div>\
<div id="vdcCreateVnetsTab_'+zone_id+'" class="content">\
'+generateVNetTableSelect("vdc_wizard_vnets_zone_"+zone_id)+'\
</div>\
<div id="vdcCreateDatastoresTab_'+zone_id+'" class="content">\
'+generateDatastoreTableSelect("vdc_wizard_datastores_zone_"+zone_id)+'\
</div>\
</div>\
</div>\
</div>';
return html;
}
//The DOM is ready and the ready() from sunstone.js

View File

@ -5978,6 +5978,7 @@ function generateVNetTableSelect(context_id){
// opts.fixed_ids: Array of IDs to show. Any other ID will be filtered out. If
// an ID is not returned by the pool, it will be included as a
// blank row
// opts.zone_id: Retrieves elements from this zone, instead of the current one
function setupVNetTableSelect(section, context_id, opts){
if(opts == undefined){
@ -6032,49 +6033,60 @@ function setupVNetTableSelect(section, context_id, opts){
"uname_index": 2,
"update_fn": function(datatable){
OpenNebula.Network.list({
timeout: true,
success: function (request, networks_list){
var network_list_array = [];
var success_func = function (request, networks_list){
var network_list_array = [];
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
$.each(networks_list,function(){
var add = true;
$.each(networks_list,function(){
var add = true;
if(opts.filter_fn){
add = opts.filter_fn(this.VNET);
}
if(opts.filter_fn){
add = opts.filter_fn(this.VNET);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.VNET.ID]);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.VNET.ID]);
}
if(add){
network_list_array.push(vNetworkElementArray(this));
if(add){
network_list_array.push(vNetworkElementArray(this));
delete fixed_ids_map[this.VNET.ID];
}
});
delete fixed_ids_map[this.VNET.ID];
}
});
var n_columns = 10; // SET FOR EACH RESOURCE
var n_columns = 10; // SET FOR EACH RESOURCE
$.each(fixed_ids_map, function(id,v){
var empty = [];
$.each(fixed_ids_map, function(id,v){
var empty = [];
for(var i=0; i<=n_columns; i++){
empty.push("");
}
for(var i=0; i<=n_columns; i++){
empty.push("");
}
empty[1] = id; // SET FOR EACH RESOURCE, id_index
empty[1] = id; // SET FOR EACH RESOURCE, id_index
list_array.push(empty);
});
network_list_array.push(empty);
});
updateView(network_list_array, datatable);
},
error: onError
});
updateView(network_list_array, datatable);
}
if (opts.zone_id == undefined) {
OpenNebula.Network.list({
timeout: true,
success: success_func,
error: onError
});
} else {
OpenNebula.Network.list_in_zone({
data: { zone_id: opts.zone_id },
timeout: true,
success: success_func,
error: onError
});
}
},
"select_callback": opts.select_callback
@ -6230,6 +6242,7 @@ function generateHostTableSelect(context_id){
// opts.fixed_ids: Array of IDs to show. Any other ID will be filtered out. If
// an ID is not returned by the pool, it will be included as a
// blank row
// opts.zone_id: Retrieves elements from this zone, instead of the current one
function setupHostTableSelect(section, context_id, opts){
if(opts == undefined){
@ -6283,49 +6296,60 @@ function setupHostTableSelect(section, context_id, opts){
"name_index": 2,
"update_fn": function(datatable){
OpenNebula.Host.list({
timeout: true,
success: function (request, resource_list){
var list_array = [];
var success_func = function (request, resource_list){
var list_array = [];
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
$.each(resource_list,function(){
var add = true;
$.each(resource_list,function(){
var add = true;
if(opts.filter_fn){
add = opts.filter_fn(this.HOST);
}
if(opts.filter_fn){
add = opts.filter_fn(this.HOST);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.HOST.ID]);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.HOST.ID]);
}
if(add){
list_array.push(hostElementArray(this));
if(add){
list_array.push(hostElementArray(this));
delete fixed_ids_map[this.HOST.ID];
}
});
delete fixed_ids_map[this.HOST.ID];
}
});
var n_columns = 13; // SET FOR EACH RESOURCE
var n_columns = 13; // SET FOR EACH RESOURCE
$.each(fixed_ids_map, function(id,v){
var empty = [];
$.each(fixed_ids_map, function(id,v){
var empty = [];
for(var i=0; i<=n_columns; i++){
empty.push("");
}
for(var i=0; i<=n_columns; i++){
empty.push("");
}
empty[1] = id; // SET FOR EACH RESOURCE, id_index
empty[1] = id; // SET FOR EACH RESOURCE, id_index
list_array.push(empty);
});
list_array.push(empty);
});
updateView(list_array, datatable);
},
error: onError
});
updateView(list_array, datatable);
}
if (opts.zone_id == undefined) {
OpenNebula.Host.list({
timeout: true,
success: success_func,
error: onError
});
} else {
OpenNebula.Host.list_in_zone({
data: { zone_id: opts.zone_id },
timeout: true,
success: success_func,
error: onError
});
}
},
"select_callback": opts.select_callback
@ -6388,6 +6412,7 @@ function generateDatastoreTableSelect(context_id){
// opts.fixed_ids: Array of IDs to show. Any other ID will be filtered out. If
// an ID is not returned by the pool, it will be included as a
// blank row
// opts.zone_id: Retrieves elements from this zone, instead of the current one
function setupDatastoreTableSelect(section, context_id, opts){
if(opts == undefined){
@ -6443,49 +6468,60 @@ function setupDatastoreTableSelect(section, context_id, opts){
"uname_index": 2,
"update_fn": function(datatable){
OpenNebula.Datastore.list({
timeout: true,
success: function (request, resource_list){
var list_array = [];
var success_func = function (request, resource_list){
var list_array = [];
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
$.each(resource_list,function(){
var add = true;
$.each(resource_list,function(){
var add = true;
if(opts.filter_fn){
add = opts.filter_fn(this.DATASTORE);
}
if(opts.filter_fn){
add = opts.filter_fn(this.DATASTORE);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.DATASTORE.ID]);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.DATASTORE.ID]);
}
if(add){
list_array.push(datastoreElementArray(this));
if(add){
list_array.push(datastoreElementArray(this));
delete fixed_ids_map[this.DATASTORE.ID];
}
});
delete fixed_ids_map[this.DATASTORE.ID];
}
});
var n_columns = 11; // SET FOR EACH RESOURCE
var n_columns = 11; // SET FOR EACH RESOURCE
$.each(fixed_ids_map, function(id,v){
var empty = [];
$.each(fixed_ids_map, function(id,v){
var empty = [];
for(var i=0; i<=n_columns; i++){
empty.push("");
}
for(var i=0; i<=n_columns; i++){
empty.push("");
}
empty[1] = id; // SET FOR EACH RESOURCE, id_index
empty[1] = id; // SET FOR EACH RESOURCE, id_index
list_array.push(empty);
});
list_array.push(empty);
});
updateView(list_array, datatable);
},
error: onError
});
updateView(list_array, datatable);
}
if (opts.zone_id == undefined) {
OpenNebula.Datastore.list({
timeout: true,
success: success_func,
error: onError
});
} else {
OpenNebula.Datastore.list_in_zone({
data: { zone_id: opts.zone_id },
timeout: true,
success: success_func,
error: onError
});
}
},
"select_callback": opts.select_callback
@ -6778,6 +6814,324 @@ function selectSecurityGroupTableSelect(section, context_id, opts){
return selectResourceTableSelect(section, context_id, opts);
}
function generateGroupTableSelect(context_id){
var columns = [
"",
tr("ID"),
tr("Name"),
tr("Users"),
tr("VMs"),
tr("Memory"),
tr("CPU")
];
var options = {
"id_index": 1,
"name_index": 2,
"select_resource": tr("Please select a Group from the list"),
"you_selected": tr("You selected the following Group:"),
"select_resource_multiple": tr("Please select one or more groups from the list"),
"you_selected_multiple": tr("You selected the following groups:")
};
return generateResourceTableSelect(context_id, columns, options);
}
// opts.bVisible: dataTable bVisible option. If not set, the .yaml visibility will be used
// opts.filter_fn: boolean function to filter which elements to show
// opts.select_callback(aData, options): function called after a row is selected
// opts.multiple_choice: boolean true to enable multiple element selection
// opts.read_only: boolean true so user is not asked to select elements
// opts.fixed_ids: Array of IDs to show. Any other ID will be filtered out. If
// an ID is not returned by the pool, it will be included as a
// blank row
function setupGroupTableSelect(section, context_id, opts){
if(opts == undefined){
opts = {};
}
if(opts.bVisible == undefined){
// Use the settings in the conf, but removing the checkbox
var config = Config.tabTableColumns('groups-tab').slice(0);
var i = config.indexOf(0);
if(i != -1){
config.splice(i,1);
}
opts.bVisible = config;
}
if(opts.multiple_choice == undefined){
opts.multiple_choice = false;
}
var fixed_ids_map_orig = {};
if(opts.fixed_ids != undefined){
$.each(opts.fixed_ids,function(){
fixed_ids_map_orig[this] = true;
});
}
var options = {
"dataTable_options": {
"bAutoWidth":false,
"iDisplayLength": 4,
"sDom" : '<"H">t<"F"p>',
"bRetrieve": true,
"bSortClasses" : false,
"bDeferRender": true,
"aoColumnDefs": [
{ "sWidth": "35px", "aTargets": [0] },
{ "bVisible": true, "aTargets": opts.bVisible},
{ "bVisible": false, "aTargets": ['_all']}
]
},
"multiple_choice": opts.multiple_choice,
"read_only": opts.read_only,
"fixed_ids": opts.fixed_ids,
"id_index": 1,
"name_index": 2,
"update_fn": function(datatable){
OpenNebula.Group.list({
timeout: true,
success: function (request, resource_list){
var list_array = [];
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
$.each(resource_list,function(){
var add = true;
if(opts.filter_fn){
add = opts.filter_fn(this.GROUP);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.GROUP.ID]);
}
if(add){
list_array.push(groupElementArray(this));
delete fixed_ids_map[this.GROUP.ID];
}
});
var n_columns = 7; // SET FOR EACH RESOURCE
$.each(fixed_ids_map, function(id,v){
var empty = [];
for(var i=0; i<=n_columns; i++){
empty.push("");
}
empty[1] = id; // SET FOR EACH RESOURCE, id_index
list_array.push(empty);
});
updateView(list_array, datatable);
},
error: onError
});
},
"select_callback": opts.select_callback
};
return setupResourceTableSelect(section, context_id, options);
}
// Clicks the refresh button
function refreshGroupTableSelect(section, context_id){
return refreshResourceTableSelect(section, context_id);
}
// Returns an ID, or an array of IDs for opts.multiple_choice
function retrieveGroupTableSelect(section, context_id){
return retrieveResourceTableSelect(section, context_id);
}
// Clears the current selection, and selects the given IDs
// opts.ids must be a single ID, or an array of IDs for options.multiple_choice
// opts.names must be an array of {name, uname}
function selectGroupTableSelect(section, context_id, opts){
return selectResourceTableSelect(section, context_id, opts);
}
function generateClusterTableSelect(context_id){
var columns = [
"",
tr("ID"),
tr("Name"),
tr("Hosts"),
tr("VNets"),
tr("Datastores")
];
var options = {
"id_index": 1,
"name_index": 2,
"select_resource": tr("Please select a Cluster from the list"),
"you_selected": tr("You selected the following Cluster:"),
"select_resource_multiple": tr("Please select one or more clusters from the list"),
"you_selected_multiple": tr("You selected the following clusters:")
};
return generateResourceTableSelect(context_id, columns, options);
}
// opts.bVisible: dataTable bVisible option. If not set, the .yaml visibility will be used
// opts.filter_fn: boolean function to filter which elements to show
// opts.select_callback(aData, options): function called after a row is selected
// opts.multiple_choice: boolean true to enable multiple element selection
// opts.read_only: boolean true so user is not asked to select elements
// opts.fixed_ids: Array of IDs to show. Any other ID will be filtered out. If
// an ID is not returned by the pool, it will be included as a
// blank row
// opts.zone_id: Retrieves elements from this zone, instead of the current one
function setupClusterTableSelect(section, context_id, opts){
if(opts == undefined){
opts = {};
}
if(opts.bVisible == undefined){
// Use the settings in the conf, but removing the checkbox
var config = Config.tabTableColumns('clusters-tab').slice(0);
var i = config.indexOf(0);
if(i != -1){
config.splice(i,1);
}
opts.bVisible = config;
}
if(opts.multiple_choice == undefined){
opts.multiple_choice = false;
}
var fixed_ids_map_orig = {};
if(opts.fixed_ids != undefined){
$.each(opts.fixed_ids,function(){
fixed_ids_map_orig[this] = true;
});
}
var options = {
"dataTable_options": {
"bAutoWidth":false,
"iDisplayLength": 4,
"sDom" : '<"H">t<"F"p>',
"bRetrieve": true,
"bSortClasses" : false,
"bDeferRender": true,
"aoColumnDefs": [
{ "sWidth": "35px", "aTargets": [0] },
{ "bVisible": true, "aTargets": opts.bVisible},
{ "bVisible": false, "aTargets": ['_all']}
]
},
"multiple_choice": opts.multiple_choice,
"read_only": opts.read_only,
"fixed_ids": opts.fixed_ids,
"id_index": 1,
"name_index": 2,
"update_fn": function(datatable){
var success_func = function (request, resource_list){
var list_array = [];
var fixed_ids_map = $.extend({}, fixed_ids_map_orig);
$.each(resource_list,function(){
var add = true;
if(opts.filter_fn){
add = opts.filter_fn(this.CLUSTER);
}
if(opts.fixed_ids != undefined){
add = (add && fixed_ids_map[this.CLUSTER.ID]);
}
if(add){
list_array.push(clusterElementArray(this));
delete fixed_ids_map[this.CLUSTER.ID];
}
});
var n_columns = 6; // SET FOR EACH RESOURCE
$.each(fixed_ids_map, function(id,v){
var empty = [];
for(var i=0; i<=n_columns; i++){
empty.push("");
}
empty[1] = id; // SET FOR EACH RESOURCE, id_index
list_array.push(empty);
});
updateView(list_array, datatable);
}
if (opts.zone_id == undefined) {
OpenNebula.Cluster.list({
timeout: true,
success: success_func,
error: onError
});
} else {
OpenNebula.Cluster.list_in_zone({
data: { zone_id: opts.zone_id },
timeout: true,
success: success_func,
error: onError
});
}
},
"select_callback": opts.select_callback
};
return setupResourceTableSelect(section, context_id, options);
}
// Clicks the refresh button
function refreshClusterTableSelect(section, context_id){
return refreshResourceTableSelect(section, context_id);
}
// Returns an ID, or an array of IDs for opts.multiple_choice
function retrieveClusterTableSelect(section, context_id){
return retrieveResourceTableSelect(section, context_id);
}
// Clears the current selection, and selects the given IDs
// opts.ids must be a single ID, or an array of IDs for options.multiple_choice
// opts.names must be an array of {name, uname}
function selectClusterTableSelect(section, context_id, opts){
return selectResourceTableSelect(section, context_id, opts);
}
function generateResourceTableSelect(context_id, columns, options){
if (!options.select_resource){
options.select_resource = tr("Please select a resource from the list");