diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js index f25710fa2c..5c2342bbe1 100644 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ b/src/sunstone/public/js/plugins/clusters-tab.js @@ -18,23 +18,6 @@ /* ------------ Cluster creation dialog ------------ */ -var vnet_datatable_table_tmpl='\ - \ - \ - '+tr("ID")+'\ - '+tr("Owner")+'\ - '+tr("Group")+'\ - '+tr("Name")+'\ - '+tr("Reservation")+'\ - '+tr("Cluster")+'\ - '+tr("Bridge")+'\ - '+tr("Leases")+'\ - '+tr("VLAN ID")+'\ - \ - \ - \ - ' - var datastore_datatable_table_tmpl='\ \ \ @@ -80,26 +63,7 @@ var create_cluster_tmpl ='
\ '+generateHostTableSelect("cluster_wizard_hosts")+'\
\
\ -
\ -
\ - \ -
\ -
\ - \ -
\ -
\ -
\ -
\ - ' + vnet_datatable_table_tmpl + '
\ -
\ -
\ -
\ -
\ -
\ - '+tr("Please select one or more vnets from the list")+'\ - \ -
\ -
\ + '+generateVNetTableSelect("cluster_wizard_vnets")+'\
\
\
\ @@ -135,10 +99,8 @@ var create_cluster_tmpl ='
\ // Common utils for datatatables // Holds the selected items -selected_vnets_list = {}; selected_datastore_list = {}; -vnet_row_hash = {}; datastore_row_hash = {}; // Prepares the cluster creation dialog @@ -163,24 +125,7 @@ function setupCreateClusterDialog(){ setupHostTableSelect(dialog, "cluster_wizard_hosts", opts); - - dataTable_cluster_vnets = $("#datatable_cluster_vnets", dialog).dataTable({ - "sDom" : '<"H">t<"F"p>', - "oColVis": { - "aiExclude": [ 0 ] - }, - "bSortClasses" : false, - "bDeferRender": true, - "aoColumnDefs": [ - { "sWidth": "35px", "aTargets": [1] }, - { "bVisible": false, "aTargets": [0,7]} - ] - }); - - - $('#cluster_vnets_search', dialog).keyup(function(){ - dataTable_cluster_vnets.fnFilter( $(this).val() ); - }) + setupVNetTableSelect(dialog, "cluster_wizard_vnets", opts); dataTable_cluster_datastores = $("#datatable_cluster_datastores", dialog).dataTable({ "sDom" : '<"H">t<"F"p>', @@ -203,43 +148,6 @@ function setupCreateClusterDialog(){ // ------- End of create the dialog datatables ------------ - $('#datatable_cluster_vnets tbody', dialog).delegate("tr", "click", function(e){ - if ($(e.target).is('input') || - $(e.target).is('select') || - $(e.target).is('option')) return true; - - var aData = dataTable_cluster_vnets.fnGetData(this); - var vnet_id = aData[1]; - var name = aData[4]; - - if ($.isEmptyObject(selected_vnets_list)) { - $('#cluster_vnets_selected', dialog).show(); - $('#select_cluster_vnets', dialog).hide(); - } - - if(!$("td:first", this).hasClass('markrowchecked')) - { - selected_vnets_list[vnet_id]=1; - vnet_row_hash[vnet_id]=this; - $(this).children().each(function(){$(this).addClass('markrowchecked');}); - $('div#selected_vnets_div', dialog).append(''+name+' '); - } - else - { - delete selected_vnets_list[vnet_id]; - $(this).children().each(function(){$(this).removeClass('markrowchecked');}); - $('div#selected_vnets_div span#tag_vnets_'+vnet_id, dialog).remove(); - } - - if ($.isEmptyObject(selected_vnets_list)) { - $('#cluster_vnets_selected', dialog).hide(); - $('#select_cluster_vnets', dialog).show(); - } - - return false; - }); - - $('#datatable_cluster_datastores tbody', dialog).delegate("tr", "click", function(e){ if ($(e.target).is('input') || $(e.target).is('select') || @@ -285,19 +193,7 @@ function setupCreateClusterDialog(){ // Unselect row var id = $(this).parent().attr("ID"); - if (id.match(/vnet/g)) - { - var vnet_id=id.substring(10,id.length); - delete selected_vnets_list[vnet_id]; - $("td:first", vnet_row_hash[vnet_id]).parent().children().each(function(){$(this).removeClass('markrowchecked');}); - - if ($.isEmptyObject(selected_vnets_list)) { - $('#cluster_vnets_selected', dialog).hide(); - $('#select_cluster_vnets', dialog).show(); - } - - } - else if (id.match(/datastore/g)) + if (id.match(/datastore/g)) { var datastore_id=id.substring(15,id.length); delete selected_datastore_list[datastore_id]; @@ -310,12 +206,6 @@ function setupCreateClusterDialog(){ } }); - $("#refresh_vnet_table_button_class", dialog).click( function(){ - Sunstone.runAction("ClusterVN.list"); - return false; - } - ); - $("#refresh_datastore_table_button_class", dialog).click( function(){ Sunstone.runAction("ClusterDS.list"); return false; @@ -332,13 +222,19 @@ function setupCreateClusterDialog(){ } var selected_hosts_arr = retrieveHostTableSelect(dialog, "cluster_wizard_hosts"); - var selected_hosts_list = {}; $.each(selected_hosts_arr, function(i,e){ selected_hosts_list[e] = 1; }); + var selected_vnets_arr = retrieveVNetTableSelect(dialog, "cluster_wizard_vnets"); + var selected_vnets_list = {}; + + $.each(selected_vnets_arr, function(i,e){ + selected_vnets_list[e] = 1; + }); + var cluster_json = { "cluster": { "name": $('#name',dialog).val(), @@ -355,13 +251,10 @@ function setupCreateClusterDialog(){ } function reset_counters(){ - selected_vnets_list = {}; selected_datastore_list = {}; - original_vnets_list = {}; original_datastores_list = {}; - vnet_row_hash = {}; datastore_row_hash = {}; } @@ -380,7 +273,7 @@ function popUpCreateClusterDialog(){ $('#update_cluster_header',$create_cluster_dialog).hide(); refreshHostTableSelect($create_cluster_dialog, "cluster_wizard_hosts"); - Sunstone.runAction("ClusterVN.list"); + refreshVNetTableSelect($create_cluster_dialog, "cluster_wizard_vnets"); Sunstone.runAction("ClusterDS.list"); $create_cluster_dialog.foundation().foundation('reveal', 'open'); @@ -468,60 +361,19 @@ function fillPopPup(request,response){ } selectHostTableSelect(dialog, "cluster_wizard_hosts", opts); - -/* - dataTable_cluster_hosts.on('draw', function(){ - dataTable_cluster_hosts.unbind('draw'); - var rows = dataTable_cluster_hosts.fnGetNodes(); - - for (var i = 0; i < host_ids.length; i++) - { - for(var j=0;j\
\ - ' + - vnet_datatable_table_tmpl + - '
\ + '+generateVNetTableSelect("cluster_info_vnets")+'\
\
' } @@ -1159,20 +958,22 @@ function updateClusterInfo(request,cluster){ // Virtual networks datatable - dataTable_cluster_vnets_panel = $("#datatable_cluster_vnets_info_panel").dataTable({ - "sDom" : "<'H'>t<'row'<'large-6 columns'i><'large-6 columns'p>>", - "oColVis": { - "aiExclude": [ 0 ] - }, - "bSortClasses" : false, - "bDeferRender": true, - "aoColumnDefs": [ - { "sWidth": "35px", "aTargets": [1] }, - { "bVisible": false, "aTargets": [0,5,6,7]} - ] - }); + var vnet_ids = cluster_info.VNETS.ID; - infoListener(dataTable_cluster_vnets_panel,'Network.show','vnets-tab'); + if (typeof vnet_ids == 'string'){ + vnet_ids = [vnet_ids]; + } else if (vnet_ids == undefined){ + vnet_ids = []; + } + + var opts = { + read_only: true, + fixed_ids: vnet_ids + } + + setupVNetTableSelect($("#cluster_info_panel"), "cluster_info_vnets", opts); + + refreshVNetTableSelect($("#cluster_info_panel"), "cluster_info_vnets"); // Datastores datatable @@ -1192,7 +993,6 @@ function updateClusterInfo(request,cluster){ infoListener(dataTable_cluster_datastores_panel,'Datastore.show','datastores-tab'); // initialize datatables values - Sunstone.runAction("ClusterVNInfo.list"); Sunstone.runAction("ClusterDSInfo.list"); } diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index 5e924368cd..62dbb48c2b 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -5576,7 +5576,9 @@ function generateVNetTableSelect(context_id){ "name_index": 4, "uname_index": 2, "select_resource": tr("Please select a network from the list"), - "you_selected": tr("You selected the following network:") + "you_selected": tr("You selected the following network:"), + "select_resource_multiple": tr("Please select one or more networks from the list"), + "you_selected_multiple": tr("You selected the following networks:") }; return generateResourceTableSelect(context_id, columns, options); @@ -5585,6 +5587,11 @@ function generateVNetTableSelect(context_id){ // 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 setupVNetTableSelect(section, context_id, opts){ if(opts == undefined){ @@ -5603,6 +5610,18 @@ function setupVNetTableSelect(section, context_id, opts){ 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, @@ -5618,6 +5637,10 @@ function setupVNetTableSelect(section, context_id, opts){ ] }, + "multiple_choice": opts.multiple_choice, + "read_only": opts.read_only, + "fixed_ids": opts.fixed_ids, + "id_index": 1, "name_index": 4, "uname_index": 2, @@ -5628,6 +5651,8 @@ function setupVNetTableSelect(section, context_id, opts){ success: function (request, networks_list){ var network_list_array = []; + var fixed_ids_map = $.extend({}, fixed_ids_map_orig); + $.each(networks_list,function(){ var add = true; @@ -5635,11 +5660,31 @@ function setupVNetTableSelect(section, context_id, opts){ add = opts.filter_fn(this.VNET); } + if(opts.fixed_ids != undefined){ + add = (add && fixed_ids_map[this.VNET.ID]); + } + if(add){ network_list_array.push(vNetworkElementArray(this)); + + delete fixed_ids_map[this.VNET.ID]; } }); + var n_columns = 10; // 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(network_list_array, datatable); }, error: onError