1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-25 23:21:29 +03:00

Feature #2570: Retrieve zone pool, select clusters for each zone in group wizard

This commit is contained in:
Carlos Martín 2013-12-20 15:30:46 +01:00
parent 2e09c94eb9
commit 0609e38dce

View File

@ -732,7 +732,7 @@ function updateGroupInfo(request,group){
} }
function setup_group_resource_tab_content(zone_section, str_zone_tab_id, str_datatable_id) { function setup_group_resource_tab_content(zone_id, zone_section, str_zone_tab_id, str_datatable_id) {
// Show the clusters dataTable when the radio button is selected // Show the clusters dataTable when the radio button is selected
$("input[name='"+str_zone_tab_id+"']", zone_section).change(function(){ $("input[name='"+str_zone_tab_id+"']", zone_section).change(function(){
if ($("input[name='"+str_zone_tab_id+"']:checked").val() == "cluster") { if ($("input[name='"+str_zone_tab_id+"']:checked").val() == "cluster") {
@ -773,7 +773,7 @@ function setup_group_resource_tab_content(zone_section, str_zone_tab_id, str_dat
var cluster_id = aData[1]; var cluster_id = aData[1];
if ($.isEmptyObject(selected_group_clusters)) { if ($.isEmptyObject(selected_group_clusters[zone_id])) {
$('#you_selected_group_clusters'+str_zone_tab_id, zone_section).show(); $('#you_selected_group_clusters'+str_zone_tab_id, zone_section).show();
$("select_group_clusters"+str_zone_tab_id, zone_section).hide(); $("select_group_clusters"+str_zone_tab_id, zone_section).hide();
} }
@ -781,8 +781,8 @@ function setup_group_resource_tab_content(zone_section, str_zone_tab_id, str_dat
if(!$("td:first", this).hasClass('markrowchecked')) if(!$("td:first", this).hasClass('markrowchecked'))
{ {
$('input.check_item', this).attr('checked','checked'); $('input.check_item', this).attr('checked','checked');
selected_group_clusters[cluster_id]=1; selected_group_clusters[zone_id][cluster_id] = 1;
group_clusters_row_hash[cluster_id]=this; group_clusters_row_hash[zone_id][cluster_id] = this;
$(this).children().each(function(){$(this).addClass('markrowchecked');}); $(this).children().each(function(){$(this).addClass('markrowchecked');});
if ($('#tag_cluster_'+aData[1], $('div#selected_group_clusters', zone_section)).length == 0 ) { if ($('#tag_cluster_'+aData[1], $('div#selected_group_clusters', zone_section)).length == 0 ) {
$('div#selected_group_clusters', zone_section).append('<span id="tag_cluster_'+aData[1]+'" class="radius label">'+aData[2]+' <span class="icon-remove blue"></span></span> '); $('div#selected_group_clusters', zone_section).append('<span id="tag_cluster_'+aData[1]+'" class="radius label">'+aData[2]+' <span class="icon-remove blue"></span></span> ');
@ -791,12 +791,12 @@ function setup_group_resource_tab_content(zone_section, str_zone_tab_id, str_dat
else else
{ {
$('input.check_item', this).removeAttr('checked'); $('input.check_item', this).removeAttr('checked');
delete selected_group_clusters[cluster_id]; delete selected_group_clusters[zone_id][cluster_id];
$(this).children().each(function(){$(this).removeClass('markrowchecked');}); $(this).children().each(function(){$(this).removeClass('markrowchecked');});
$('div#selected_group_clusters span#tag_cluster_'+cluster_id, zone_section).remove(); $('div#selected_group_clusters span#tag_cluster_'+cluster_id, zone_section).remove();
} }
if ($.isEmptyObject(selected_group_clusters)) { if ($.isEmptyObject(selected_group_clusters[zone_id])) {
$('#you_selected_group_clusters'+str_zone_tab_id, zone_section).hide(); $('#you_selected_group_clusters'+str_zone_tab_id, zone_section).hide();
$('#select_group_clusters'+str_zone_tab_id, zone_section).show(); $('#select_group_clusters'+str_zone_tab_id, zone_section).show();
} }
@ -811,11 +811,11 @@ function setup_group_resource_tab_content(zone_section, str_zone_tab_id, str_dat
var id = $(this).parent().attr("ID"); var id = $(this).parent().attr("ID");
var cluster_id=id.substring(12,id.length); var cluster_id=id.substring(12,id.length);
delete selected_group_clusters[cluster_id]; delete selected_group_clusters[zone_id][cluster_id];
$('td', group_clusters_row_hash[cluster_id]).removeClass('markrowchecked'); $('td', group_clusters_row_hash[zone_id][cluster_id]).removeClass('markrowchecked');
$('input.check_item', group_clusters_row_hash[cluster_id]).removeAttr('checked'); $('input.check_item', group_clusters_row_hash[zone_id][cluster_id]).removeAttr('checked');
if ($.isEmptyObject(selected_group_clusters)) { if ($.isEmptyObject(selected_group_clusters[zone_id])) {
$('#you_selected_group_clusters'+str_zone_tab_id, zone_section).hide(); $('#you_selected_group_clusters'+str_zone_tab_id, zone_section).hide();
$('#select_group_clusters'+str_zone_tab_id, zone_section).show(); $('#select_group_clusters'+str_zone_tab_id, zone_section).show();
} }
@ -909,10 +909,13 @@ function update_datatable_group_clusters(datatable, fnDrawCallback) {
var selected_group_clusters = {}; var selected_group_clusters = {};
var group_clusters_row_hash = {}; var group_clusters_row_hash = {};
var add_resource_tab = function(zone_id, dialog) { var add_resource_tab = function(zone_id, zone_name, dialog) {
var str_zone_tab_id = 'zone' + zone_id; var str_zone_tab_id = 'zone' + zone_id;
var str_datatable_id = 'datatable_group_clusters_zone' + zone_id; var str_datatable_id = 'datatable_group_clusters_zone' + zone_id;
selected_group_clusters[zone_id] = {};
group_clusters_row_hash[zone_id] = {};
// Append the new div containing the tab and add the tab to the list // Append the new div containing the tab and add the tab to the list
var html_tab_content = '<li id="'+str_zone_tab_id+'Tab">'+ var html_tab_content = '<li id="'+str_zone_tab_id+'Tab">'+
generate_group_resource_tab_content(str_zone_tab_id, str_datatable_id) + generate_group_resource_tab_content(str_zone_tab_id, str_datatable_id) +
@ -920,13 +923,13 @@ var add_resource_tab = function(zone_id, dialog) {
$(html_tab_content).appendTo($("ul#group_zones_tabs_content")); $(html_tab_content).appendTo($("ul#group_zones_tabs_content"));
var a = $("<dd>\ var a = $("<dd>\
<a id='zone_tab"+str_zone_tab_id+"' href='#"+str_zone_tab_id+"'>"+tr("Zone")+" "+zone_id+"</a>\ <a id='zone_tab"+str_zone_tab_id+"' href='#"+str_zone_tab_id+"'>"+zone_name+"</a>\
</dd>").appendTo($("dl#group_zones_tabs")); </dd>").appendTo($("dl#group_zones_tabs"));
$(document).foundationTabs("set_tab", a); $(document).foundationTabs("set_tab", a);
var zone_section = $('li#' +str_zone_tab_id+'Tab', dialog); var zone_section = $('li#' +str_zone_tab_id+'Tab', dialog);
setup_group_resource_tab_content(zone_section, str_zone_tab_id, str_datatable_id); setup_group_resource_tab_content(zone_id, zone_section, str_zone_tab_id, str_datatable_id);
}; };
function disableAdminUser(dialog){ function disableAdminUser(dialog){
@ -993,8 +996,22 @@ function setupCreateGroupDialog(){
$('#admin_user',dialog).attr('disabled','disabled'); $('#admin_user',dialog).attr('disabled','disabled');
disableAdminUser(dialog); disableAdminUser(dialog);
// TODO: Retrieve list of zones and create a tab for each one OpenNebula.Zone.list({
add_resource_tab(0, dialog); timeout: true,
success: function (request, obj_list){
$.each(obj_list,function(){
add_resource_tab(this.ZONE.ID, this.ZONE.NAME, dialog);
});
// =================================================================
// TODO: Development, one zone added if zone pool is empty
if (obj_list.length == 0){
add_resource_tab(0, "Local Zone", dialog);
}
// =================================================================
},
error: onError
});
$('#create_group_form',dialog).submit(function(){ $('#create_group_form',dialog).submit(function(){
var name = $('#name',this).val(); var name = $('#name',this).val();
@ -1029,30 +1046,28 @@ function setupCreateGroupDialog(){
group_json["group"]["user"] = user_json["user"]; group_json["group"]["user"] = user_json["user"];
} }
var clusters = new Array(); group_json['group']['resource_providers'] = [];
// TODO: one zone hardcoded $.each(selected_group_clusters, function(zone_id, zone_clusters) {
var zone_id = 0; var str_zone_tab_id = 'zone' + zone_id;
var str_zone_tab_id = 'zone' + zone_id;
var resource_selection = $("input[name='"+str_zone_tab_id+"']:checked").val(); var resource_selection = $("input[name='"+str_zone_tab_id+"']:checked").val();
switch (resource_selection){ switch (resource_selection){
case "all": case "all":
// TODO // TODO
break; break;
case "cluster": case "cluster":
$.each(selected_group_clusters, function(key, value) { $.each(selected_group_clusters[zone_id], function(key, value) {
clusters.push(key); group_json['group']['resource_providers'].push(
}); {"zone_id" : zone_id, "cluster_id" : key}
);
});
break; break;
default: // "none" default: // "none"
// TODO // TODO
} }
});
if (clusters.length > 0){
group_json['group']['cluster_ids'] = clusters;
}
Sunstone.runAction("Group.create",group_json); Sunstone.runAction("Group.create",group_json);
$create_group_dialog.trigger("reveal:close"); $create_group_dialog.trigger("reveal:close");