diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js index 3e4ca24887..6ebf501774 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create-common.js @@ -174,6 +174,20 @@ define(function(require) { delete templateJSON["VCENTER_PUBLIC_CLOUD"]; } + // PCI with TYPE=NIC is not defined in the 'other' tab. Because it is + // part of an array, and it is filled in different tabs, the $.extend deep + // merge can't work. We define an auxiliary attribute for it. + + if (templateJSON["NIC_PCI"] != undefined) { + if (templateJSON['PCI'] == undefined) { + templateJSON['PCI'] = []; + } + + templateJSON['PCI'] = templateJSON['PCI'].concat(templateJSON["NIC_PCI"]); + + delete templateJSON["NIC_PCI"]; + } + return templateJSON; } diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js index d7549470bd..fa23fe92cf 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general.js @@ -75,11 +75,15 @@ define(function(require) { function _onShow(context, panelForm) { if (panelForm.action == 'create') { - $('#NAME', context).removeAttr('disabled'); - $('#NAME', context).attr("required", ""); + $('#NAME', context) + .removeAttr('disabled') + .attr("required", "") + .prop('wizard_field_disabled', false); } else if (panelForm.action == 'update') { - $('#NAME', context).attr("disabled", "disabled"); - $('#NAME', context).removeAttr("required"); + $('#NAME', context) + .attr("disabled", "disabled") + .removeAttr("required") + .prop('wizard_field_disabled', true); } if (panelForm.resource == "VirtualRouterTemplate"){ diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js index 6297c90d3b..e9b76d4aee 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network.js @@ -113,13 +113,24 @@ define(function(require) { function _retrieve(context) { var templateJSON = {} var nicsJSON = []; - var nicJSON; + var pcisJSON = []; + + var tmpJSON; $.each(this.nicTabObjects, function(id, nicTab) { - nicJSON = nicTab.retrieve($('#' + nicTab.nicTabId, context)) - if (!$.isEmptyObject(nicJSON)) {nicsJSON.push(nicJSON)}; + tmpJSON = nicTab.retrieve($('#' + nicTab.nicTabId, context)) + if (!$.isEmptyObject(tmpJSON)) { + if (tmpJSON["NIC_PCI"] == true){ + delete tmpJSON["NIC_PCI"]; + tmpJSON["TYPE"] = "NIC"; + pcisJSON.push(tmpJSON); + } else { + nicsJSON.push(tmpJSON); + } + }; }) if (nicsJSON.length > 0) { templateJSON['NIC'] = nicsJSON; }; + if (pcisJSON.length > 0) { templateJSON['NIC_PCI'] = pcisJSON; }; var nicDefault = WizardFields.retrieveInput($('#DEFAULT_MODEL', context)); if (nicDefault) { @@ -133,27 +144,64 @@ define(function(require) { function _fill(context, templateJSON) { var that = this; - var nics = templateJSON.NIC; - if (nics instanceof Array) { - $.each(nics, function(nicId, nicJSON) { - if (nicId > 0) { - that.addNicTab(context); - } + var nics = []; - var nicTab = that.nicTabObjects[that.numberOfNics]; - var nicContext = $('#' + nicTab.nicTabId, context); - nicTab.fill(nicContext, nicJSON); + if (templateJSON.NIC != undefined){ + nics = templateJSON.NIC; + } + + if (!(nics instanceof Array)) { + nics = [nics]; + } + + if (templateJSON.PCI != undefined){ + var pcis = templateJSON.PCI; + + if (!(pcis instanceof Array)) { + pcis = [pcis]; + } + + $.each(pcis, function(){ + if (this["TYPE"] == "NIC"){ + nics.push(this); + } }); - } else if (nics instanceof Object) { + } + + $.each(nics, function(nicId, nicJSON) { + if (nicId > 0) { + that.addNicTab(context); + } + var nicTab = that.nicTabObjects[that.numberOfNics]; var nicContext = $('#' + nicTab.nicTabId, context); - nicTab.fill(nicContext, nics); - } + nicTab.fill(nicContext, nicJSON); + }); if (templateJSON.NIC) { delete templateJSON.NIC; } + if (templateJSON.PCI != undefined) { + var pcis = templateJSON.PCI; + + if (!(pcis instanceof Array)) { + pcis = [pcis]; + } + + pcis = pcis.filter(function(pci){ + return pci["TYPE"] != "NIC" + }); + + delete templateJSON.PCI; + + if (pcis.length == 1){ + templateJSON.PCI = pcis[0]; + } else if (pcis.length > 1) { + templateJSON.PCI = pcis; + } + } + var nicDefault = templateJSON.NIC_DEFAULT if (nicDefault != undefined) { if (nicDefault.MODEL) { diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js index f3a786ba91..0a08e3c008 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab.js @@ -26,6 +26,7 @@ define(function(require) { var SecgroupsTable = require('tabs/secgroups-tab/datatable'); var WizardFields = require('utils/wizard-fields'); var UniqueId = require('utils/unique-id'); + var CreateUtils = require('../utils'); /* TEMPLATES @@ -41,7 +42,7 @@ define(function(require) { CONSTRUCTOR */ - function DiskTab(nicTabId) { + function NicTab(nicTabId) { this.nicTabId = 'nicTab' + nicTabId + UniqueId.id(); this.vnetsTable = new VNetsTable(this.nicTabId + 'Table', {'select': true}); @@ -55,14 +56,14 @@ define(function(require) { this.secgroupsTable = new SecgroupsTable(this.nicTabId + 'SGTable', secgroupSelectOptions); } - DiskTab.prototype.constructor = DiskTab; - DiskTab.prototype.html = _html; - DiskTab.prototype.setup = _setup; - DiskTab.prototype.onShow = _onShow; - DiskTab.prototype.retrieve = _retrieve; - DiskTab.prototype.fill = _fill; + NicTab.prototype.constructor = NicTab; + NicTab.prototype.html = _html; + NicTab.prototype.setup = _setup; + NicTab.prototype.onShow = _onShow; + NicTab.prototype.retrieve = _retrieve; + NicTab.prototype.fill = _fill; - return DiskTab; + return NicTab; /* FUNCTION DEFINITIONS @@ -99,6 +100,30 @@ define(function(require) { that.secgroupsTable.initialize(); that.secgroupsTable.refreshResourceTableSelect(); + + $("input.pci-type-nic", context).on("change", function(){ + var tbody = $(".pci-row tbody", context); + + if ($(this).prop('checked')){ + $("input[wizard_field=MODEL]", context).prop("disabled", true).prop('wizard_field_disabled', true); + $(".nic-model-row", context).hide(); + $(".pci-row", context).show(); + + tbody.html( CreateUtils.pciRowHTML() ); + + CreateUtils.fillPCIRow({tr: $('tr', tbody), remove: false}); + } else { + $("input[wizard_field=MODEL]", context).removeAttr('disabled').prop('wizard_field_disabled', false); + $(".nic-model-row", context).show(); + $(".pci-row", context).hide(); + + tbody.html(""); + } + }); + + CreateUtils.setupPCIRows($(".pci-row", context)); + + $("input.pci-type-nic", context).change(); } function _retrieve(context) { @@ -123,6 +148,10 @@ define(function(require) { nicJSON["SECURITY_GROUPS"] = secgroups.join(","); } + if ($("input.pci-type-nic", context).prop("checked")){ + nicJSON["NIC_PCI"] = true; + } + return nicJSON; } @@ -182,6 +211,10 @@ define(function(require) { this.secgroupsTable.refreshResourceTableSelect(); } + if (templateJSON["TYPE"] == "NIC"){ + $("input.pci-type-nic", context).click(); + } + WizardFields.fill(context, templateJSON); } }); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs index 869e41037f..990b28f6e0 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/network/nic-tab/html.hbs @@ -130,6 +130,14 @@
-