' +
'
' + Locale.tr("MAC") +
' ' +
' ' +
@@ -216,7 +269,7 @@ define(function(require) {
break;
}
- $('.net_options', network_context).html(net_form_str);
+ $('.net_options', row_context).html(net_form_str);
});
}
});
@@ -228,20 +281,52 @@ define(function(require) {
});
}
+ function _recountCheckboxes(table) {
+ // Counters for the whole table, all pages
+ var dt = $(table).DataTable();
+ var total = dt.$(".check_item").length;
+ var selected = dt.$(".check_item:checked").length;
+
+ if (selected == total){
+ $(".vcenter-table-header-text").text(Locale.tr("All %1$s Networks selected.", selected));
+
+ $(".vcenter-table-header-text").show();
+ $("a.vcenter-table-select-all").hide();
+ $("a.vcenter-table-deselect-all").show();
+ } else if (selected == 0){
+ $(".vcenter-table-header-text").hide();
+ $("a.vcenter-table-select-all").show();
+ $("a.vcenter-table-deselect-all").hide();
+ } else {
+ $(".vcenter-table-header-text").text(Locale.tr("%1$s Networks selected.", selected));
+
+ $(".vcenter-table-header-text").show();
+ $("a.vcenter-table-select-all").show();
+ $("a.vcenter-table-deselect-all").hide();
+ }
+
+ // Counters for the current visible page
+ var total_length = $('input.check_item', table).length;
+ var checked_length = $('input.check_item:checked', table).length;
+ $('.check_all', table).prop('checked', (total_length == checked_length));
+ }
+
function _import(context) {
- $.each($(".vcenter_network_table", context), function() {
- $.each($(".check_item:checked", this), function() {
- var network_context = $(this).closest(".vcenter_row");
+ $.each($(".vcenter_import_table", context), function() {
+ $.each($(this).DataTable().$(".check_item:checked"), function() {
+ var row_context = $(this).closest("tr");
- $(".vcenter_network_result:not(.success)", network_context).html(
- '
' +
- ' ' +
- ' ' +
- ' ');
+ $(".vcenter_import_result:not(.success)", row_context).html(
+ '
' +
+ ' ' +
+ ' ' +
+ ' ');
- var network_size = $(".netsize", network_context).val();
- var network_tmpl = $(this).data("one_network");
- var type = $('.type_select', network_context).val();
+ $(".vcenter_import_result_row", row_context).show();
+
+ var network_size = $(".netsize", row_context).val();
+ var network_tmpl = $(this).data("import_data").one;
+ var type = $('.type_select', row_context).val();
var ar_array = [];
ar_array.push("TYPE=" + type);
@@ -249,7 +334,7 @@ define(function(require) {
switch (type) {
case 'ETHER':
- var mac = $('.eth_mac_net', network_context).val();
+ var mac = $('.eth_mac_net', row_context).val();
if (mac) {
ar_array.push("MAC=" + mac);
@@ -257,8 +342,8 @@ define(function(require) {
break;
case 'IP4':
- var mac = $('.four_mac_net', network_context).val();
- var ip = $('.four_ip_net', network_context).val();
+ var mac = $('.four_mac_net', row_context).val();
+ var ip = $('.four_ip_net', row_context).val();
if (mac) {
ar_array.push("MAC=" + mac);
@@ -269,9 +354,9 @@ define(function(require) {
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();
+ var mac = $('.six_mac_net', row_context).val();
+ var gp = $('.six_global_net', row_context).val();
+ var ula = $('.six_mac_net', row_context).val();
if (mac) {
ar_array.push("MAC=" + mac);
@@ -290,7 +375,7 @@ define(function(require) {
network_tmpl += ar_array.join(",\n")
network_tmpl += "]"
- var vlaninfo = $(".vlaninfo", network_context).text();
+ var vlaninfo = $(".vlaninfo", row_context).text();
if ( vlaninfo != undefined && vlaninfo != "" ) {
network_tmpl += "\nVLAN_ID=" + vlaninfo + "\n";
@@ -306,25 +391,24 @@ define(function(require) {
timeout: true,
data: vnet_json,
success: function(request, response) {
- $(".vcenter_network_result", network_context).addClass("success").html(
- '
' +
- ' ' +
- ' ' +
- ' ');
+ $(".vcenter_import_result", row_context).addClass("success").html(
+ '
' +
+ ' ' +
+ ' ' +
+ ' ');
- $(".vcenter_network_response", network_context).html('
' +
- Locale.tr("Virtual Network created successfully") + ' ID:' + response.VNET.ID +
- '
');
+ $(".vcenter_import_response", row_context).html(
+ Locale.tr("Virtual Network created successfully") + '. ID: ' + response.VNET.ID);
},
error: function (request, error_json) {
- $(".vcenter_network_result", network_context).html('
' +
- ' ' +
- ' ' +
- ' ');
+ $(".vcenter_import_result", row_context).html(
+ '
' +
+ ' ' +
+ ' ' +
+ ' ');
- $(".vcenter_network_response", network_context).html('
' +
- (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) +
- '
');
+ $(".vcenter_import_response", row_context).addClass("error-color").html(
+ (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")));
}
});
});
diff --git a/src/sunstone/public/app/utils/vcenter/networks/empty-table.hbs b/src/sunstone/public/app/utils/vcenter/networks/empty-table.hbs
deleted file mode 100644
index ed64b1a025..0000000000
--- a/src/sunstone/public/app/utils/vcenter/networks/empty-table.hbs
+++ /dev/null
@@ -1,20 +0,0 @@
-{{! -------------------------------------------------------------------------- }}
-{{! Copyright 2002-2016, OpenNebula Project, OpenNebula Systems }}
-{{! }}
-{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }}
-{{! not use this file except in compliance with the License. You may obtain }}
-{{! a copy of the License at }}
-{{! }}
-{{! http://www.apache.org/licenses/LICENSE-2.0 }}
-{{! }}
-{{! Unless required by applicable law or agreed to in writing, software }}
-{{! distributed under the License is distributed on an "AS IS" BASIS, }}
-{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }}
-{{! See the License for the specific language governing permissions and }}
-{{! limitations under the License. }}
-{{! -------------------------------------------------------------------------- }}
-
-
\ No newline at end of file
diff --git a/src/sunstone/public/app/utils/vcenter/networks/row.hbs b/src/sunstone/public/app/utils/vcenter/networks/row.hbs
index 0ee94f6b02..75691036dd 100644
--- a/src/sunstone/public/app/utils/vcenter/networks/row.hbs
+++ b/src/sunstone/public/app/utils/vcenter/networks/row.hbs
@@ -16,58 +16,49 @@
-
+
+
+
+ {{data.name}}
+ - {{data.type}}
+ {{#if data.vlan}} - VLAN: {{data.vlan}} {{/if}}
+
-
-
-
-
-
-
- {{tr "Size"}}
-
-
-
-
-
- {{tr "Type"}}
-
- eth
- ipv4
- ipv6
-
-
-
-
-
-
- {{tr "MAC"}}
-
-
-
-
+
+
+
+ {{tr "Size"}}
+
+
+
+
+
+ {{tr "Type"}}
+
+ eth
+ ipv4
+ ipv6
+
+
+
+
-
\ No newline at end of file
diff --git a/src/sunstone/public/app/utils/vcenter/templates.js b/src/sunstone/public/app/utils/vcenter/templates.js
index e9f81327e7..bda8685aa6 100644
--- a/src/sunstone/public/app/utils/vcenter/templates.js
+++ b/src/sunstone/public/app/utils/vcenter/templates.js
@@ -20,13 +20,11 @@ define(function(require) {
var OpenNebulaTemplate = require('opennebula/template');
var OpenNebulaError = require('opennebula/error');
var DomDataTable = require('utils/dom-datatable');
- var CustomLayoutDataTable = require('utils/custom-layout-table');
var UserInputs = require('utils/user-inputs');
var Notifier = require('utils/notifier');
var UniqueId = require('utils/unique-id');
var TemplateHTML = require('hbs!./templates/html');
- var EmptyTableTemplate = require('hbs!./templates/empty-table');
var RowTemplate = require('hbs!./templates/row');
function VCenterTemplates() {
@@ -43,7 +41,7 @@ define(function(require) {
return VCenterTemplates;
function _html() {
- return '
';
+ return '
';
}
/*
@@ -61,7 +59,7 @@ define(function(require) {
function _fillVCenterTemplates(opts) {
var path = '/vcenter/templates';
- var context = $(".vcenter_templates", opts.container);
+ var context = $(".vcenter_import", opts.container);
context.html(TemplateHTML());
context.show();
@@ -78,9 +76,9 @@ define(function(require) {
success: function(response){
$(".vcenter_datacenter_list", context).html("");
- $.each(response, function(datacenter_name, templates){
+ $.each(response, function(datacenter_name, elements){
var content;
- if (templates.length == 0) {
+ if (elements.length == 0) {
content =
'
' +
'' +
@@ -99,7 +97,7 @@ define(function(require) {
$(".vcenter_datacenter_list", context).append(content);
} else {
- var tableId = "vcenter_template_table_" + UniqueId.id();
+ var tableId = "vcenter_import_table_" + UniqueId.id();
content =
' ' +
'' +
@@ -107,18 +105,6 @@ define(function(require) {
' ' +
datacenter_name + ' ' + Locale.tr("DataCenter") +
' ' +
- ' ' +
- '' +
- ' ' +
- Locale.tr("Select All") +
- ' ' +
- ' ' +
- ' ' +
- '' +
- ' ' +
- Locale.tr("Expand Advanced Sections") +
- ' ' +
- ' ' +
' ' +
'' +
Locale.tr("Clear Imported Templates") +
@@ -126,11 +112,30 @@ define(function(require) {
' ' +
'' +
' ' +
+ '' +
'' +
'
' +
- '
' +
+ '' +
@@ -138,38 +143,87 @@ define(function(require) {
'';
'';
- $(".vcenter_datacenter_list", context).append(content);
+ var newdiv = $(content).appendTo($(".vcenter_datacenter_list", context));
+ var tbody = $('#' + tableId + ' tbody', context);
- var preDrawCallback = function (settings) {
- $('#' + tableId).html(EmptyTableTemplate());
- }
- var rowCallback = function(row, data, index) {
- var opts = {};
- if (data.ds && data.ds !== '') {
- opts.datastore = UserInputs.unmarshall(data.ds);
- }
-
- if (data.rp && data.rp !== '') {
- opts.resourcePool = UserInputs.unmarshall(data.rp);
- }
-
- opts.data = data;
-
- var templateRow = $(RowTemplate(opts)).appendTo($('#' + tableId));
- $('.check_item', templateRow).data("template_name", data.name)
- $('.check_item', templateRow).data("one_template", data.one);
-
- return row;
+ $.each(elements, function(id, element) {
+ var opts = {};
+ if (element.ds && element.ds !== '') {
+ opts.datastore = UserInputs.unmarshall(element.ds);
}
- var templatesTable = new CustomLayoutDataTable({
- tableId: '#' + tableId,
- columns: ['name'],
- preDrawCallback: preDrawCallback,
- rowCallback: rowCallback
+ if (element.rp && element.rp !== '') {
+ opts.resourcePool = UserInputs.unmarshall(element.rp);
+ }
+
+ opts.data = element;
+
+ var trow = $(
+ '' +
+ ' ' +
+ ''+RowTemplate(opts)+' ' +
+ ' ').appendTo(tbody);
+
+ $('.check_item', trow).data("import_data", element);
+ });
+
+ var elementsTable = new DomDataTable(
+ tableId,
+ {
+ actions: false,
+ info: false,
+ dataTableOptions: {
+ "bAutoWidth": false,
+ "bSortClasses" : false,
+ "bDeferRender": false,
+ "ordering": false,
+ "aoColumnDefs": [
+ {"sWidth": "35px", "aTargets": [0]},
+ ],
+ },
+ "customTrListener": function(tableObj, tr){ return false; }
});
- templatesTable.addData(templates);
+ elementsTable.initialize();
+
+ $("a.vcenter-table-select-all").text(Locale.tr("Select all %1$s Templates", elements.length));
+
+ _recountCheckboxes($('table', newdiv));
+
+ newdiv.on("change", '.check_all', function() {
+ var table = $(this).closest('table');
+ if ($(this).is(":checked")) { //check all
+ $('tbody input.check_item', table).prop('checked', true).change();
+ } else { //uncheck all
+ $('tbody input.check_item', table).prop('checked', false).change();
+ }
+ });
+
+ $('table', newdiv).on('draw.dt', function() {
+ _recountCheckboxes(this);
+ });
+
+ $(newdiv).on('change', ".check_item", function() {
+ _recountCheckboxes($('table', newdiv));
+ });
+
+ $(".vcenter-table-select-all", newdiv).on("click", function(){
+ $("table.vcenter_import_table", newdiv).DataTable().$(".check_item").prop("checked", true).change();
+ });
+
+ $(".vcenter-table-deselect-all", newdiv).on("click", function(){
+ $("table.vcenter_import_table", newdiv).DataTable().$(".check_item").prop("checked", false).change();
+ });
+
+ $(".vcenter-table-toggle-advanced", newdiv).on("click", function(){
+ var unactive_n = $(".accordion_advanced_toggle:not(.active)", newdiv).length;
+
+ if (unactive_n > 0){
+ $(".accordion_advanced_toggle:not(.active)", newdiv).click();
+ } else {
+ $(".accordion_advanced_toggle", newdiv).click();
+ }
+ });
context.off('click', '.clear_imported');
context.on('click', '.clear_imported', function() {
@@ -187,28 +241,53 @@ define(function(require) {
}
function _recountCheckboxes(table) {
+ // Counters for the whole table, all pages
+ var dt = $(table).DataTable();
+ var total = dt.$(".check_item").length;
+ var selected = dt.$(".check_item:checked").length;
+
+ if (selected == total){
+ $(".vcenter-table-header-text").text(Locale.tr("All %1$s Templates selected.", selected));
+
+ $(".vcenter-table-header-text").show();
+ $("a.vcenter-table-select-all").hide();
+ $("a.vcenter-table-deselect-all").show();
+ } else if (selected == 0){
+ $(".vcenter-table-header-text").hide();
+ $("a.vcenter-table-select-all").show();
+ $("a.vcenter-table-deselect-all").hide();
+ } else {
+ $(".vcenter-table-header-text").text(Locale.tr("%1$s Templates selected.", selected));
+
+ $(".vcenter-table-header-text").show();
+ $("a.vcenter-table-select-all").show();
+ $("a.vcenter-table-deselect-all").hide();
+ }
+
+ // Counters for the current visible page
var total_length = $('input.check_item', table).length;
var checked_length = $('input.check_item:checked', table).length;
$('.check_all', table).prop('checked', (total_length == checked_length));
}
function _import(context) {
- $.each($(".vcenter_template_table", context), function() {
- $.each($(".check_item:checked", this), function() {
- var template_context = $(this).closest(".vcenter_row");
+ $.each($(".vcenter_import_table", context), function() {
+ $.each($(this).DataTable().$(".check_item:checked"), function() {
+ var row_context = $(this).closest("tr");
- $(".vcenter_template_result:not(.success)", template_context).html(
- '' +
- ' ' +
- ' ' +
- ' ');
+ $(".vcenter_import_result:not(.success)", row_context).html(
+ '' +
+ ' ' +
+ ' ' +
+ ' ');
+ $(".vcenter_import_result_row", row_context).show();
var attrs = [];
var userInputs = [];
// Retrieve Datastore Attribute
- var dsInput = $(".vcenter_datastore_input", template_context);
+ var dsInput = $(".vcenter_datastore_input", row_context);
if (dsInput.length > 0) {
var dsModify = $('.modify_datastore', dsInput).val();
var dsInitial = $('.initial_datastore', dsInput).val();
@@ -229,7 +308,7 @@ define(function(require) {
}
// Retrieve Resource Pool Attribute
- var rpInput = $(".vcenter_rp_input", template_context);
+ var rpInput = $(".vcenter_rp_input", row_context);
if (rpInput.length > 0) {
var rpModify = $('.modify_rp', rpInput).val();
var rpInitial = $('.initial_rp', rpInput).val();
@@ -250,7 +329,7 @@ define(function(require) {
}
// Append new attrs and user inputs if necessary
- var template = $(this).data("one_template");
+ var template = $(this).data("import_data").one;
if (attrs.length > 0) {
template += "\n" + attrs.join("\n");
@@ -270,25 +349,24 @@ define(function(require) {
timeout: true,
data: template_json,
success: function(request, response) {
- $(".vcenter_template_result", template_context).addClass("success").html(
- '' +
- ' ' +
- ' ' +
- ' ');
+ $(".vcenter_import_result", row_context).addClass("success").html(
+ '' +
+ ' ' +
+ ' ' +
+ ' ');
- $(".vcenter_template_response", template_context).html('' +
- Locale.tr("Template created successfully") + ' ID:' + response.VMTEMPLATE.ID +
- '
');
+ $(".vcenter_import_response", row_context).html(
+ Locale.tr("Template created successfully") + '. ID: ' + response.VMTEMPLATE.ID);
},
error: function (request, error_json) {
- $(".vcenter_template_result", template_context).html('' +
- ' ' +
- ' ' +
- ' ');
+ $(".vcenter_import_result", row_context).html(
+ '' +
+ ' ' +
+ ' ' +
+ ' ');
- $(".vcenter_template_response", template_context).html('' +
- (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) +
- '
');
+ $(".vcenter_import_response", row_context).addClass("error-color").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/empty-table.hbs b/src/sunstone/public/app/utils/vcenter/templates/empty-table.hbs
deleted file mode 100644
index ed64b1a025..0000000000
--- a/src/sunstone/public/app/utils/vcenter/templates/empty-table.hbs
+++ /dev/null
@@ -1,20 +0,0 @@
-{{! -------------------------------------------------------------------------- }}
-{{! Copyright 2002-2016, OpenNebula Project, OpenNebula Systems }}
-{{! }}
-{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }}
-{{! not use this file except in compliance with the License. You may obtain }}
-{{! a copy of the License at }}
-{{! }}
-{{! http://www.apache.org/licenses/LICENSE-2.0 }}
-{{! }}
-{{! Unless required by applicable law or agreed to in writing, software }}
-{{! distributed under the License is distributed on an "AS IS" BASIS, }}
-{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }}
-{{! See the License for the specific language governing permissions and }}
-{{! limitations under the License. }}
-{{! -------------------------------------------------------------------------- }}
-
-
\ No newline at end of file
diff --git a/src/sunstone/public/app/utils/vcenter/templates/row.hbs b/src/sunstone/public/app/utils/vcenter/templates/row.hbs
index 03cbb4d006..a54bb9dfa3 100644
--- a/src/sunstone/public/app/utils/vcenter/templates/row.hbs
+++ b/src/sunstone/public/app/utils/vcenter/templates/row.hbs
@@ -16,16 +16,11 @@
-
+
+
+
+ {{data.name}}
+