From 22b70b7ebe2b5241d887277061dae2e7cd690413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 2 Oct 2015 18:05:01 +0200 Subject: [PATCH] Feature #3893: Add pagination to vcenter import dialog --- .../public/app/utils/tab-datatable.js | 2 +- .../public/app/utils/vcenter/networks.js | 206 ++++++++++-------- .../public/app/utils/vcenter/templates.js | 135 ++++++++---- 3 files changed, 209 insertions(+), 134 deletions(-) diff --git a/src/sunstone/public/app/utils/tab-datatable.js b/src/sunstone/public/app/utils/tab-datatable.js index 334d05eff4..ac78287e23 100644 --- a/src/sunstone/public/app/utils/tab-datatable.js +++ b/src/sunstone/public/app/utils/tab-datatable.js @@ -255,7 +255,7 @@ define(function(require) { $('.check_item', this).trigger('click'); } - return false; + return true; }); } diff --git a/src/sunstone/public/app/utils/vcenter/networks.js b/src/sunstone/public/app/utils/vcenter/networks.js index 656a9849b0..e07b7bfd95 100644 --- a/src/sunstone/public/app/utils/vcenter/networks.js +++ b/src/sunstone/public/app/utils/vcenter/networks.js @@ -19,6 +19,8 @@ define(function(require) { var Locale = require('utils/locale'); var OpenNebulaNetwork = require('opennebula/network'); var OpenNebulaError = require('opennebula/error'); + var DomDataTable = require('utils/dom-datatable'); + var Notifier = require('utils/notifier'); var TemplateHTML = require('hbs!./networks/html'); @@ -99,6 +101,18 @@ define(function(require) { '' + '').appendTo($(".content", context)) } else { + var newdiv = $( + '
' + + '
' + + '' + + '' + + '' + + '
' + + '
' + + '
').appendTo($(".content", context)); + + var tbody = $('tbody', newdiv); + $.each(networks, function(id, network){ var netname = network.name.replace(" ","_"); var vlan_info = "" @@ -113,7 +127,9 @@ define(function(require) { ''; } - var trow = $('
' + + var trow = $( + '' + + '' + '
' + '
' + '
' + @@ -150,7 +166,8 @@ define(function(require) { '
'+ '
'+ '
'+ - '
').appendTo($(".content", context)) + '' + + '').appendTo(tbody); $('.type_select', trow).on("change",function(){ @@ -207,7 +224,24 @@ define(function(require) { $(".network_name", trow).data("network_name", netname) $(".network_name", trow).data("one_network", network.one) }); - }; + + var networkDataTable = new DomDataTable( + 'vcenter_network_table_' + datacenter_name, + { + actions: false, + info: false, + dataTableOptions: { + "bAutoWidth": false, + "bSortClasses" : false, + "bDeferRender": false, + "ordering": false, + "aoColumnDefs": [ + ] + } + }); + + networkDataTable.initialize(); + } }); }, error: function(response){ @@ -218,102 +252,104 @@ define(function(require) { } function _import(context) { - $.each($(".network_name:checked", context), function() { - var network_context = $(this).closest(".vcenter_network"); + $.each($("table.vcenter_network_table", context), function() { + $.each($(this).DataTable().$(".network_name:checked"), function() { + var network_context = $(this).closest(".vcenter_network"); - $(".vcenter_network_result:not(.success)", network_context).html( - '' + - '' + - '' + - ''); + $(".vcenter_network_result:not(.success)", network_context).html( + '' + + '' + + '' + + ''); - var network_size = $(".netsize", network_context).val(); - var network_tmpl = $(this).data("one_network"); - var netname = $(this).data("network_name"); - var type = $('.type_select', network_context).val(); + var network_size = $(".netsize", network_context).val(); + var network_tmpl = $(this).data("one_network"); + var netname = $(this).data("network_name"); + var type = $('.type_select', network_context).val(); - var ar_array = []; - ar_array.push("TYPE=" + type); - ar_array.push("SIZE=" + network_size); + var ar_array = []; + ar_array.push("TYPE=" + type); + ar_array.push("SIZE=" + network_size); - switch (type) { - case 'ETHER': - var mac = $('.eth_mac_net', network_context).val(); + switch (type) { + case 'ETHER': + var mac = $('.eth_mac_net', network_context).val(); - if (mac) { - ar_array.push("MAC=" + mac); - } + if (mac) { + ar_array.push("MAC=" + mac); + } - break; - case 'IP4': - var mac = $('.four_mac_net', network_context).val(); - var ip = $('.four_ip_net', network_context).val(); + break; + case 'IP4': + var mac = $('.four_mac_net', network_context).val(); + var ip = $('.four_ip_net', network_context).val(); - if (mac) { - ar_array.push("MAC=" + mac); - } - if (ip) { - ar_array.push("IP=" + ip); - } + if (mac) { + ar_array.push("MAC=" + mac); + } + if (ip) { + ar_array.push("IP=" + ip); + } - break; - case 'IP6': - var mac = $('.six_mac_net', network_context).val(); - var gp = $('.six_global_net', network_context).val(); - var ula = $('.six_mac_net', network_context).val(); + break; + case 'IP6': + var mac = $('.six_mac_net', network_context).val(); + var gp = $('.six_global_net', network_context).val(); + var ula = $('.six_mac_net', network_context).val(); - if (mac) { - ar_array.push("MAC=" + mac); - } - if (gp) { - ar_array.push("GLOBAL_PREFIX=" + gp); - } - if (ula) { - ar_array.push("ULA_PREFIX=" + ula); - } + if (mac) { + ar_array.push("MAC=" + mac); + } + if (gp) { + ar_array.push("GLOBAL_PREFIX=" + gp); + } + if (ula) { + ar_array.push("ULA_PREFIX=" + ula); + } - break; - } - - network_tmpl += "\nAR=[" - network_tmpl += ar_array.join(",\n") - network_tmpl += "]" - - if ($(".vlaninfo", network_context)) { - network_tmpl += "VLAN=\"YES\"\n"; - network_tmpl += "VLAN_ID=" + $(".vlaninfo", network_context).val() + "\n"; - } - - var vnet_json = { - "vnet": { - "vnet_raw": network_tmpl + break; } - }; - OpenNebulaNetwork.create({ - timeout: true, - data: vnet_json, - success: function(request, response) { - $(".vcenter_network_result", network_context).addClass("success").html( - '' + - '' + - '' + - ''); + network_tmpl += "\nAR=[" + network_tmpl += ar_array.join(",\n") + network_tmpl += "]" - $(".vcenter_network_response", network_context).html('

' + - Locale.tr("Virtual Network created successfully") + ' ID:' + response.VNET.ID + - '

'); - }, - error: function (request, error_json) { - $(".vcenter_network_result", network_context).html('' + - '' + - '' + - ''); - - $(".vcenter_network_response", network_context).html('

' + - (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) + - '

'); + if ($(".vlaninfo", network_context)) { + network_tmpl += "VLAN=\"YES\"\n"; + network_tmpl += "VLAN_ID=" + $(".vlaninfo", network_context).val() + "\n"; } + + var vnet_json = { + "vnet": { + "vnet_raw": network_tmpl + } + }; + + OpenNebulaNetwork.create({ + timeout: true, + data: vnet_json, + success: function(request, response) { + $(".vcenter_network_result", network_context).addClass("success").html( + '' + + '' + + '' + + ''); + + $(".vcenter_network_response", network_context).html('

' + + Locale.tr("Virtual Network created successfully") + ' ID:' + response.VNET.ID + + '

'); + }, + error: function (request, error_json) { + $(".vcenter_network_result", network_context).html('' + + '' + + '' + + ''); + + $(".vcenter_network_response", network_context).html('

' + + (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) + + '

'); + } + }); }); }); diff --git a/src/sunstone/public/app/utils/vcenter/templates.js b/src/sunstone/public/app/utils/vcenter/templates.js index 770e11d87c..75542e3519 100644 --- a/src/sunstone/public/app/utils/vcenter/templates.js +++ b/src/sunstone/public/app/utils/vcenter/templates.js @@ -19,6 +19,8 @@ define(function(require) { var Locale = require('utils/locale'); var OpenNebulaTemplate = require('opennebula/template'); var OpenNebulaError = require('opennebula/error'); + var DomDataTable = require('utils/dom-datatable'); + var Notifier = require('utils/notifier'); var TemplateHTML = require('hbs!./templates/html'); @@ -99,25 +101,60 @@ define(function(require) { '
' + '
').appendTo($(".content", context)) } else { + var newdiv = $( + '
' + + '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + Locale.tr("Name") + '' + Locale.tr("Datacenter") + '' + + '' + + '
' + + '
' + + '
').appendTo($(".content", context)); + + var tbody = $('tbody', newdiv); + $.each(templates, function(id, template){ - var trow = $('
' + - '
' + - '
' + - '' + - '
'+ - '
'+ - '
' + - '
'+ - '
'+ - '
'+ - '
').appendTo($(".content", context)) + var trow = $( + '' + + '' + + '' + template.name + '' + + '' + template.host + '' + + '
' + + '
' + + '').appendTo(tbody); $(".template_name", trow).data("template_name", template.name) $(".template_name", trow).data("one_template", template.one) }); + + var tmplDataTable = new DomDataTable( + 'vcenter_template_table_' + datacenter_name, + { + actions: false, + info: false, + dataTableOptions: { + "bAutoWidth": false, + "bSortClasses" : false, + "bDeferRender": false, + //"ordering": true, + "order": [], + "aoColumnDefs": [ + {"bSortable": true, "aTargets": [1,2]}, + {"sWidth": "35px", "aTargets": [0]}, + ] + }, + customTrListener: function(tableObj, tr){ + $("input.template_name", tr).click(); + } + }); + + tmplDataTable.initialize(); }; }); }, @@ -129,45 +166,47 @@ define(function(require) { } function _import(context) { - $.each($(".template_name:checked", context), function() { - var template_context = $(this).closest(".vcenter_template"); + $.each($("table.vcenter_template_table", context), function() { + $.each($(this).DataTable().$(".template_name:checked"), function() { + var template_context = $(this).closest(".vcenter_template"); - $(".vcenter_template_result:not(.success)", template_context).html( - '' + - '' + - '' + - ''); + $(".vcenter_template_result:not(.success)", template_context).html( + '' + + '' + + '' + + ''); - var template_json = { - "vmtemplate": { - "template_raw": $(this).data("one_template") - } - }; + var template_json = { + "vmtemplate": { + "template_raw": $(this).data("one_template") + } + }; - OpenNebulaTemplate.create({ - timeout: true, - data: template_json, - success: function(request, response) { - $(".vcenter_template_result", template_context).addClass("success").html( - '' + - '' + - '' + - ''); + OpenNebulaTemplate.create({ + timeout: true, + data: template_json, + success: function(request, response) { + $(".vcenter_template_result", template_context).addClass("success").html( + '' + + '' + + '' + + ''); - $(".vcenter_template_response", template_context).html('

' + - Locale.tr("Template created successfully") + ' ID:' + response.VMTEMPLATE.ID + - '

'); - }, - error: function (request, error_json) { - $(".vcenter_template_result", template_context).html('' + - '' + - '' + - ''); + $(".vcenter_template_response", template_context).html('

' + + Locale.tr("Template created successfully") + ' ID:' + response.VMTEMPLATE.ID + + '

'); + }, + error: function (request, error_json) { + $(".vcenter_template_result", template_context).html('' + + '' + + '' + + ''); - $(".vcenter_template_response", template_context).html('

' + - (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) + - '

'); - } + $(".vcenter_template_response", template_context).html('

' + + (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) + + '

'); + } + }); }); }); }