diff --git a/src/sunstone/public/app/tabs/vnets-tab.js b/src/sunstone/public/app/tabs/vnets-tab.js index 4c08ba3c94..a24b345136 100644 --- a/src/sunstone/public/app/tabs/vnets-tab.js +++ b/src/sunstone/public/app/tabs/vnets-tab.js @@ -7,9 +7,9 @@ define(function(require) { var TAB_ID = require('./vnets-tab/tabId'); var DATATABLE_ID = "dataTableVNets"; - var _dialogs = [ - require('./vnets-tab/dialogs/create') - ]; + //var _dialogs = [ + // require('./vnets-tab/dialogs/create') + //]; var _panels = [ require('./vnets-tab/panels/info'), @@ -18,6 +18,10 @@ define(function(require) { require('./vnets-tab/panels/secgroups') ]; + var _formPanels = [ + require('./vnets-tab/form-panels/create') + ] + var VNetsTab = { tabId: TAB_ID, title: Locale.tr("Virtual Networks"), @@ -32,7 +36,8 @@ define(function(require) { actions: Actions, dataTable: new Table(DATATABLE_ID, {actions: true, info: true}), panels: _panels, - dialogs: _dialogs + formPanels: _formPanels, + //dialogs: _dialogs }; return VNetsTab; diff --git a/src/sunstone/public/app/tabs/vnets-tab/actions.js b/src/sunstone/public/app/tabs/vnets-tab/actions.js index 6f37756328..f8e14f90fb 100644 --- a/src/sunstone/public/app/tabs/vnets-tab/actions.js +++ b/src/sunstone/public/app/tabs/vnets-tab/actions.js @@ -6,16 +6,16 @@ define(function(require) { var OpenNebulaNetwork = require('opennebula/network'); var TAB_ID = require('./tabId'); - var CREATE_DIALOG_ID = require('./dialogs/create/dialogId'); + var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); var _actions = { "Network.create" : { type: "create", call: OpenNebulaNetwork.create, callback: function(request, response) { - Sunstone.getDialog(CREATE_DIALOG_ID).hide(); - Sunstone.getDialog(CREATE_DIALOG_ID).reset(); - DataTable.addElement(request, response); + $("a[href=back]", $("#"+TAB_ID)).trigger("click"); + Sunstone.hideFormPanelLoading($("#"+TAB_ID)); + Sunstone.getDataTable(TAB_ID).addElement(request, response); }, error: Notifier.onError, notify: true @@ -24,7 +24,7 @@ define(function(require) { "Network.create_dialog" : { type: "custom", call: function(){ - Sunstone.getDialog(CREATE_DIALOG_ID).show(); + Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create"); } }, @@ -236,14 +236,12 @@ define(function(require) { notify: true }, - // TODO: update - /* "Network.update_dialog" : { type: "custom", call: function(){ - var selected_nodes = getSelectedNodes(dataTable_vNetworks); + var selected_nodes = Sunstone.getDataTable(TAB_ID).elements(); if ( selected_nodes.length != 1 ) { - notifyMessage("Please select one (and just one) Virtual Network to update."); + Notifier.notifyMessage("Please select one (and just one) Virtual Network to update."); return false; } @@ -256,37 +254,26 @@ define(function(require) { type: "single", call: OpenNebulaNetwork.show, callback: function(request, response) { - // TODO: global var, better use jquery .data - vnet_to_update_id = response.VNET.ID; - - Sunstone.popUpFormPanel("create_vnet_form", "vnets-tab", "update", true, function(context){ - fillVNetUpdateFormPanel(response.VNET, context); - - $("#default_sg_warning").hide(); - }); + Sunstone.resetFormPanel(TAB_ID, CREATE_DIALOG_ID); + Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "update", response.VNET); }, error: Notifier.onError }, - */ - // TODO: update - /* "Network.update" : { type: "single", call: OpenNebulaNetwork.update, callback: function(request, response){ - $("a[href=back]", $("#vnets-tab")).trigger("click"); - popFormDialog("create_vnet_form", $("#vnets-tab")); - - notifyMessage(tr("Virtual Network updated correctly")); + $("a[href=back]", $("#"+TAB_ID)).trigger("click"); + Sunstone.hideFormPanelLoading($("#"+TAB_ID)); + Notifier.notifyMessage(tr("Virtual Network updated correctly")); }, error: function(request, response){ - popFormDialog("create_vnet_form", $("#vnets-tab")); - - onError(request, response); + Sunstone.hideFormPanelLoading($("#"+TAB_ID)); + Notifier.onError(request, response); } }, - */ + "Network.update_template" : { type: "single", diff --git a/src/sunstone/public/app/tabs/vnets-tab/form-panels/create.js b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create.js new file mode 100644 index 0000000000..0980ed8647 --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create.js @@ -0,0 +1,313 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + require('foundation.tab'); + var BaseFormPanel = require('utils/form-panels/form-panel'); + var Sunstone = require('sunstone'); + var Locale = require('utils/locale'); + var Tips = require('utils/tips'); + + /* + TEMPLATES + */ + + var TemplateWizardHTML = require('hbs!./create/wizard'); + var TemplateAdvancedHTML = require('hbs!./create/advanced'); + + /* + CONSTANTS + */ + + var FORM_PANEL_ID = require('./create/formPanelId'); + + /* + CONSTRUCTOR + */ + + function FormPanel() { + this.formPanelId = FORM_PANEL_ID; + this.actions = { + 'create': { + 'title': Locale.tr("Create Virtual Network"), + 'buttonText': Locale.tr("Create"), + 'resetButton': true + }, + 'update': { + 'title': Locale.tr("Update Virtual Network"), + 'buttonText': Locale.tr("Update"), + 'resetButton': false + } + } + + BaseFormPanel.call(this); + }; + + FormPanel.FORM_PANEL_ID = FORM_PANEL_ID; + FormPanel.prototype = Object.create(BaseFormPanel.prototype); + FormPanel.prototype.constructor = FormPanel; + FormPanel.prototype.htmlWizard = _htmlWizard; + FormPanel.prototype.htmlAdvanced = _htmlAdvanced; + FormPanel.prototype.submitWizard = _submitWizard; + FormPanel.prototype.submitAdvanced = _submitAdvanced; + FormPanel.prototype.onShow = _onShow; + FormPanel.prototype.setup = _setup; + + return FormPanel; + + /* + FUNCTION DEFINITIONS + */ + + function _htmlWizard() { + return TemplateWizardHTML({formPanelId: this.formPanelId}); + } + + function _htmlAdvanced() { + return TemplateAdvancedHTML({formPanelId: this.formPanelId}); + } + + function _setup(context) { + var number_of_ar = 0; + + // close icon: removing the tab on click + $("#vnetCreateARTab", context).on("click", "i.remove-tab", function() { + var target = $(this).parent().attr("href"); + var dd = $(this).closest('dd'); + var dl = $(this).closest('dl'); + var content = $(target); + + dd.remove(); + content.remove(); + + if (dd.attr("class") == 'active') { + $('a', dl.children('dd').last()).click(); + } + + return false; + }); + + $("#vnet_wizard_ar_btn", context).bind("click", function() { + // TODO add_ar_tab(number_of_ar, context); + number_of_ar++; + + context.foundation(); + + return false; + }); + + $("#vnetCreateARTab #vnetCreateARTabUpdate", context).hide(); + + $('#network_mode', context).change(function() { + $('input,select#vlan,label[for!="network_mode"]', $(this).parent()).hide(); + $('input', $(this).parent()).val(""); + switch ($(this).val()) { + case "default": + $('input#bridge,label[for="bridge"]', context).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]', context).hide().prop('wizard_field_disabled', true); + $('select#vlan,label[for="vlan"]', context).hide().prop('wizard_field_disabled', true); + $('input#vlan_id,label[for="vlan_id"]', context).hide().prop('wizard_field_disabled', true); + $('input#ip_spoofing,label[for="ip_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mac_spoofing,label[for="mac_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mtu,label[for="mtu"]', context).hide().prop('wizard_field_disabled', false); + + $('input#phydev', context).removeAttr('required'); + $('input#bridge', context).attr('required', ''); + break; + case "802.1Q": + $('input#bridge,label[for="bridge"]', context).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]', context).show().prop('wizard_field_disabled', false); + $('select#vlan,label[for="vlan"]', context).show().prop('wizard_field_disabled', false); + $('input#vlan_id,label[for="vlan_id"]', context).show().prop('wizard_field_disabled', false); + $('input#ip_spoofing,label[for="ip_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mac_spoofing,label[for="mac_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mtu,label[for="mtu"]', context).show().prop('wizard_field_disabled', false); + + $('input#phydev', context).removeAttr('required'); + $('input#bridge', context).removeAttr('required'); + break; + case "vxlan": + $('input#bridge,label[for="bridge"]', context).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]', context).show().prop('wizard_field_disabled', false); + $('select#vlan,label[for="vlan"]', context).show().prop('wizard_field_disabled', false); + $('input#vlan_id,label[for="vlan_id"]', context).show().prop('wizard_field_disabled', false); + $('input#ip_spoofing,label[for="ip_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mac_spoofing,label[for="mac_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mtu,label[for="mtu"]', context).show().prop('wizard_field_disabled', false); + + $('input#phydev', context).removeAttr('required'); + $('input#bridge', context).removeAttr('required'); + break; + case "ebtables": + $('input#bridge,label[for="bridge"]', context).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]', context).hide().prop('wizard_field_disabled', true); + $('select#vlan,label[for="vlan"]', context).show().prop('wizard_field_disabled', false); + $('input#vlan_id,label[for="vlan_id"]', context).hide().prop('wizard_field_disabled', true); + $('input#ip_spoofing,label[for="ip_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mac_spoofing,label[for="mac_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mtu,label[for="mtu"]', context).hide().prop('wizard_field_disabled', false); + + $('input#phydev', context).removeAttr('required'); + $('input#bridge', context).attr('required', ''); + break; + case "openvswitch": + $('input#bridge,label[for="bridge"]', context).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]', context).hide().prop('wizard_field_disabled', true); + $('select#vlan,label[for="vlan"]', context).show().prop('wizard_field_disabled', false); + $('input#vlan_id,label[for="vlan_id"]', context).show().prop('wizard_field_disabled', false); + $('input#ip_spoofing,label[for="ip_spoofing"]', context).hide().prop('wizard_field_disabled', true); + $('input#mac_spoofing,label[for="mac_spoofing"]', context).show().prop('wizard_field_disabled', false); + $('input#mtu,label[for="mtu"]', context).hide().prop('wizard_field_disabled', false); + + $('input#phydev', context).removeAttr('required'); + $('input#bridge', context).attr('required', ''); + break; + case "vmware": + $('input#bridge,label[for="bridge"]', context).show(); + $('input#phydev,label[for="phydev"]', context).hide(); + $('select#vlan,label[for="vlan"]', context).show(); + $('input#vlan_id,label[for="vlan_id"]', context).show(); + $('input#ip_spoofing,label[for="ip_spoofing"]', context).hide().prop('wizard_field_disabled', true); + $('input#mac_spoofing,label[for="mac_spoofing"]', context).hide().prop('wizard_field_disabled', true); + $('input#mtu,label[for="mtu"]', context).hide().prop('wizard_field_disabled', false); + + $('input#phydev', context).removeAttr('required'); + $('input#bridge', context).attr('required', ''); + break; + }; + + $("div.network_mode_description").hide(); + $('div.network_mode_description[value="' + $(this).val() + '"]').show(); + }); + + //Initialize shown options + $('#network_mode', context).trigger("change"); + + //TODO setupSecurityGroupTableSelect(context, "vnet_create", {"multiple_choice": true}); + //TODO setupCustomTags($("#vnetCreateContextTab", context)); + // + // Add first AR + //TODO $("#vnet_wizard_ar_btn", context).trigger("click"); + + $(document).foundation('reflow', 'tab'); + Tips.setup(); + return false; + } + + function _submitWizard(context) { + //Fetch values + var network_json = {}; + + this.retrieveWizardFields($("#vnetCreateGeneralTab", context), network_json); + this.retrieveWizardFields($("#vnetCreateBridgeTab", context), network_json); + this.retrieveWizardFields($("#vnetCreateContextTab", context), network_json); + + /* TODO + var secgroups = retrieveSecurityGroupTableSelect(context, "vnet_create"); + if (secgroups != undefined && secgroups.length != 0) { + network_json["SECURITY_GROUPS"] = secgroups.join(","); + }*/ + + // TODO retrieveCustomTags($("#vnetCreateContextTab", context), network_json); + + /* TODO + $('.ar_tab', context).each(function() { + hash = retrieve_ar_tab_data(this); + + if (!$.isEmptyObject(hash)) { + if (!network_json["AR"]) + network_json["AR"] = []; + + network_json["AR"].push(hash); + } + });*/ + + if (this.action == "create") { + network_json = { + "vnet" : network_json + }; + + Sunstone.runAction("Network.create", network_json); + return false; + } else if (this.action == "update") { + Sunstone.runAction("Network.update", this.resourceId, convert_template_to_string(network_json)); + return false; + } + } + + function _submitAdvanced(context) { + if (this.action == "create") { + var template = $('textarea#template', context).val(); + var vnet_json = {vnet: {vnet_raw: template}}; + Sunstone.runAction("Network.create", vnet_json); + return false; + + } else if (this.action == "update") { + var template_raw = $('textarea#template', context).val(); + Sunstone.runAction("Network.update", this.resourceId, template_raw); + return false; + } + } + + function _onShow(element, context) { + if (this.action != "update") {return;} + this.resourceId = element.ID; + + $("#default_sg_warning").hide(); + // Populates the Avanced mode Tab + // TODO $('#template',context).val(convert_template_to_string(element.TEMPLATE).replace(/^[\r\n]+$/g, "")); + + $('[wizard_field="NAME"]',context).val( + element.NAME). //TODO escapeDoubleQuotes(htmlDecode( element.NAME ))). + prop("disabled", true). + prop('wizard_field_disabled', true); + + this.fillWizardFields($("#vnetCreateGeneralTab", context), element.TEMPLATE); + this.fillWizardFields($("#vnetCreateBridgeTab", context), element.TEMPLATE); + this.fillWizardFields($("#vnetCreateContextTab", context), element.TEMPLATE); + + // Show all network mode inputs, and make them not required. This will change + // if a different network model is selected + $('input#bridge,label[for="bridge"]',context).show().prop('wizard_field_disabled', false).removeAttr('required'); + $('input#phydev,label[for="phydev"]',context).show().prop('wizard_field_disabled', false).removeAttr('required'); + $('select#vlan,label[for="vlan"]',context).show().prop('wizard_field_disabled', false).removeAttr('required'); + $('input#vlan_id,label[for="vlan_id"]',context).show().prop('wizard_field_disabled', false).removeAttr('required'); + $('input#ip_spoofing,label[for="ip_spoofing"]',context).show().prop('wizard_field_disabled', false); + $('input#mac_spoofing,label[for="mac_spoofing"]',context).show().prop('wizard_field_disabled', false); + + /* TODO + if (element.TEMPLATE["SECURITY_GROUPS"] != undefined && + element.TEMPLATE["SECURITY_GROUPS"].length != 0){ + + var secgroups = element.TEMPLATE["SECURITY_GROUPS"].split(","); + + selectSecurityGroupTableSelect( + $("#vnetCreateSecurityTab", context), + "vnet_create", + { ids: secgroups }); + + } else { + refreshSecurityGroupTableSelect(context, "vnet_create"); + } + + // Delete so these attributes don't end in the custom tags table also + delete element.TEMPLATE["SECURITY_GROUPS"];*/ + + var fields = $('[wizard_field]', context); + + fields.each(function(){ + var field = $(this); + var field_name = field.attr('wizard_field'); + + delete element.TEMPLATE[field_name]; + }); + + // TODO fillCustomTags($("#vnetCreateContextTab", context), element.TEMPLATE); + + // Remove the first AR added in initialize_ + $("#vnetCreateARTab i.remove-tab", context).trigger("click"); + $("#vnetCreateARTab #vnetCreateARTabUpdate", context).show(); + $("#vnetCreateARTab #vnetCreateARTabCreate", context).hide(); + } +}); diff --git a/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/advanced.hbs b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/advanced.hbs new file mode 100644 index 0000000000..451477cf0b --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/advanced.hbs @@ -0,0 +1,12 @@ +
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/formPanelId.js b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/formPanelId.js new file mode 100644 index 0000000000..b5cb7de6a9 --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/formPanelId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'createVNetForm'; +}) \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/wizard.hbs b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/wizard.hbs new file mode 100644 index 0000000000..54d60fc32c --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/form-panels/create/wizard.hbs @@ -0,0 +1,263 @@ + \ No newline at end of file