From 0241fe580b9ac8a61f19471e1a0d0380e4803026 Mon Sep 17 00:00:00 2001 From: Frederick Borges Date: Mon, 18 May 2020 15:32:19 +0200 Subject: [PATCH] F #4453: Sec. Groups VNets (#4747) --- .../etc/sunstone-views/kvm/admin.yaml | 2 + .../etc/sunstone-views/kvm/groupadmin.yaml | 2 + src/sunstone/etc/sunstone-views/kvm/user.yaml | 2 + .../etc/sunstone-views/mixed/admin.yaml | 2 + .../etc/sunstone-views/mixed/groupadmin.yaml | 2 + .../etc/sunstone-views/mixed/user.yaml | 2 + .../etc/sunstone-views/vcenter/admin.yaml | 2 + .../sunstone-views/vcenter/groupadmin.yaml | 2 + .../etc/sunstone-views/vcenter/user.yaml | 2 + src/sunstone/public/app/tabs/vnets-tab.js | 3 +- .../public/app/tabs/vnets-tab/actions.js | 27 ++++ .../tabs/vnets-tab/dialogs/add-secgroups.js | 123 ++++++++++++++++++ .../dialogs/add-secgroups/dialogId.js | 19 +++ .../vnets-tab/dialogs/add-secgroups/html.hbs | 42 ++++++ .../app/tabs/vnets-tab/panels/secgroups.js | 114 +++++++++++++++- .../tabs/vnets-tab/panels/secgroups/html.hbs | 38 ++++++ .../app/tabs/vnets-tab/utils/secgroups-tab.js | 110 ++++++++++++++++ .../vnets-tab/utils/secgroups-tab/html.hbs | 5 + 18 files changed, 494 insertions(+), 5 deletions(-) create mode 100644 src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups.js create mode 100644 src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/dialogId.js create mode 100644 src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/html.hbs create mode 100644 src/sunstone/public/app/tabs/vnets-tab/panels/secgroups/html.hbs create mode 100644 src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab.js create mode 100644 src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab/html.hbs diff --git a/src/sunstone/etc/sunstone-views/kvm/admin.yaml b/src/sunstone/etc/sunstone-views/kvm/admin.yaml index 1d5aecdb52..f98f477daa 100644 --- a/src/sunstone/etc/sunstone-views/kvm/admin.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/admin.yaml @@ -804,6 +804,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: true + Network.remove_secgroup: true vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml b/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml index f19217a8dc..dae9ab2c7d 100644 --- a/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/groupadmin.yaml @@ -804,6 +804,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: false + Network.remove_secgroup: false vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/kvm/user.yaml b/src/sunstone/etc/sunstone-views/kvm/user.yaml index 52f4ddc3f3..dea34db593 100644 --- a/src/sunstone/etc/sunstone-views/kvm/user.yaml +++ b/src/sunstone/etc/sunstone-views/kvm/user.yaml @@ -797,6 +797,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: true + Network.remove_secgroup: true vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/mixed/admin.yaml b/src/sunstone/etc/sunstone-views/mixed/admin.yaml index 7735b2b4d9..d610da0d7a 100644 --- a/src/sunstone/etc/sunstone-views/mixed/admin.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/admin.yaml @@ -807,6 +807,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: true + Network.remove_secgroup: true vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml b/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml index b0e31a961d..2856a0b10c 100644 --- a/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/groupadmin.yaml @@ -805,6 +805,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: false + Network.remove_secgroup: false vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/mixed/user.yaml b/src/sunstone/etc/sunstone-views/mixed/user.yaml index e4394c8463..078f92731d 100644 --- a/src/sunstone/etc/sunstone-views/mixed/user.yaml +++ b/src/sunstone/etc/sunstone-views/mixed/user.yaml @@ -798,6 +798,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: true + Network.remove_secgroup: true vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/vcenter/admin.yaml b/src/sunstone/etc/sunstone-views/vcenter/admin.yaml index f6472f9f8c..cafd69e7f5 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/admin.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/admin.yaml @@ -804,6 +804,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: true + Network.remove_secgroup: true vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml b/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml index 091e4e97e2..e8e0cc9ee4 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/groupadmin.yaml @@ -805,6 +805,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: false + Network.remove_secgroup: false vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/etc/sunstone-views/vcenter/user.yaml b/src/sunstone/etc/sunstone-views/vcenter/user.yaml index e4394c8463..078f92731d 100644 --- a/src/sunstone/etc/sunstone-views/vcenter/user.yaml +++ b/src/sunstone/etc/sunstone-views/vcenter/user.yaml @@ -798,6 +798,8 @@ tabs: Network.unlock: true Network.edit_labels: true Network.menu_labels: true + Network.add_secgroup: true + Network.remove_secgroup: true vnets-templates-tab: panel_tabs: vnet_template_info_tab: true diff --git a/src/sunstone/public/app/tabs/vnets-tab.js b/src/sunstone/public/app/tabs/vnets-tab.js index f4fc88ebf6..50903543a7 100644 --- a/src/sunstone/public/app/tabs/vnets-tab.js +++ b/src/sunstone/public/app/tabs/vnets-tab.js @@ -27,7 +27,8 @@ define(function(require) { require('./vnets-tab/dialogs/add-ar'), require('./vnets-tab/dialogs/update-ar'), require('./vnets-tab/dialogs/reserve'), - require('./vnets-templates-tab/dialogs/instantiate-add-ar') + require('./vnets-templates-tab/dialogs/instantiate-add-ar'), + require('./vnets-tab/dialogs/add-secgroups') ]; var _panels = [ diff --git a/src/sunstone/public/app/tabs/vnets-tab/actions.js b/src/sunstone/public/app/tabs/vnets-tab/actions.js index 6461b0c8b2..5bf91bdf61 100644 --- a/src/sunstone/public/app/tabs/vnets-tab/actions.js +++ b/src/sunstone/public/app/tabs/vnets-tab/actions.js @@ -35,6 +35,7 @@ define(function(require) { var RESERVE_DIALOG_ID = require("./dialogs/reserve/dialogId"); var IMPORT_DIALOG_ID = require("./form-panels/import/formPanelId"); var CLUSTERS_DIALOG_ID = require("utils/dialogs/clusters/dialogId"); + var ADD_SECGROUPS_DIALOG_ID = require("./dialogs/add-secgroups/dialogId"); var _commonActions = new CommonActions(OpenNebulaResource, RESOURCE, TAB_ID, XML_ROOT, Locale.tr("Virtual Network created")); @@ -160,6 +161,32 @@ define(function(require) { Sunstone.getDialog(CLUSTERS_DIALOG_ID).show(); }, error: Notifier.onError + }, + + "Network.add_secgroup" : { + type: "single", + call: OpenNebulaResource.append, + callback: function(req) { + // Reset the wizard + Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).hide(); + Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).reset(); + + Sunstone.runAction("Network.show",req.request.data[0]); + }, + error: Notifier.onError + }, + + "Network.rm_secgroup" : { + type: "single", + call: OpenNebulaResource.update, + callback: function(req) { + // Reset the wizard + Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).hide(); + Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).reset(); + + Sunstone.runAction("Network.show",req.request.data[0]); + }, + error: Notifier.onError } }; diff --git a/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups.js b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups.js new file mode 100644 index 0000000000..a6239ded8d --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups.js @@ -0,0 +1,123 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2020, 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. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./add-secgroups/html'); + var SecGroupsTab = require('tabs/vnets-tab/utils/secgroups-tab'); + var Sunstone = require('sunstone'); + var Notifier = require('utils/notifier'); + var Locale = require('utils/locale'); + var TemplateUtils = require("utils/template-utils"); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./add-secgroups/dialogId'); + var TAB_ID = require('../tabId'); + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + + this.secgroupTab = new SecGroupsTab(); + + BaseDialog.call(this); + } + + Dialog.DIALOG_ID = DIALOG_ID; + Dialog.prototype = Object.create(BaseDialog.prototype); + Dialog.prototype.constructor = Dialog; + Dialog.prototype.html = _html; + Dialog.prototype.onShow = _onShow; + Dialog.prototype.setup = _setup; + Dialog.prototype.setId = _setId; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'secGroupsTabHTML': this.secgroupTab.html("add_secgroup"), + 'action': "Network.add_secgroup" + }); + } + + function _setup(context) { + var that = this; + + Foundation.reflow(context, 'abide'); + + that.secgroupTab.setup(context, "add_secgroup"); + + $('#submit_secgroups_reset_button', context).click(function(){ + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + Sunstone.getDialog(DIALOG_ID).show(); + }); + + $('#add_secgroups_form', context) + .on('forminvalid.zf.abide', function(ev, frm) { + Notifier.notifyError(Locale.tr("One or more required fields are missing.")); + }) + .on('formvalid.zf.abide', function(ev, frm) { + var current_security_group = $("#value_td_input_SECURITY_GROUPS").text().split(","); + var new_security_groups = []; + for (var i = 0; i < current_security_group.length; i++) { + var security_group = current_security_group[i]; + if (security_group != ""){ + new_security_groups.push(security_group); + } + } + + var selected_security_groups = that.secgroupTab.retrieve()["SECURITY_GROUPS"].split(","); + + for (var i = 0; i < selected_security_groups.length; i++) { + var security_group = selected_security_groups[i]; + if (current_security_group.indexOf(security_group) < 0){ + new_security_groups += "," + security_group; + } + } + var network_json = {}; + network_json["SECURITY_GROUPS"] = new_security_groups; + Sunstone.runAction('Network.add_secgroup', that.vnetId, TemplateUtils.templateToString(network_json)); + }) + .on("submit", function(ev) { + ev.preventDefault(); + }); + } + + function _onShow(context) { + this.setNames( {tabId: TAB_ID} ); + + this.secgroupTab.onShow(); + } + + function _setId(id) { + this.vnetId = id; + } +}); diff --git a/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/dialogId.js b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/dialogId.js new file mode 100644 index 0000000000..7ca9e6c98a --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/dialogId.js @@ -0,0 +1,19 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2020, 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. */ +/* -------------------------------------------------------------------------- */ + +define(function(require){ + return 'add_secgroups_dialog'; +}); diff --git a/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/html.hbs b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/html.hbs new file mode 100644 index 0000000000..6b8964aac8 --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/dialogs/add-secgroups/html.hbs @@ -0,0 +1,42 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2020, 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. }} +{{! -------------------------------------------------------------------------- }} + +
+
+
+
+

+ {{tr "Add Security Group"}} +

+
+
+ {{{secGroupsTabHTML}}} + + +
+
+
diff --git a/src/sunstone/public/app/tabs/vnets-tab/panels/secgroups.js b/src/sunstone/public/app/tabs/vnets-tab/panels/secgroups.js index c0de813c1f..5a374587ea 100644 --- a/src/sunstone/public/app/tabs/vnets-tab/panels/secgroups.js +++ b/src/sunstone/public/app/tabs/vnets-tab/panels/secgroups.js @@ -21,16 +21,22 @@ define(function(require) { var Locale = require('utils/locale'); var SecurityGroupsTable = require('tabs/secgroups-tab/datatable'); + var SecGroupsTemplate = require('hbs!./secgroups/html'); + var Sunstone = require('sunstone'); + var Config = require('sunstone-config'); + var TemplateUtils = require("utils/template-utils"); /* CONSTANTS */ - + var TAB_ID = require('../tabId'); var PANEL_ID = require('./secgroups/panelId'); var SG_TABLE_ID = PANEL_ID + "SecurityGroupsTable"; var RESOURCE = "Network"; var XML_ROOT = "VNET"; + var ADD_SECGROUPS_DIALOG_ID = require('../dialogs/add-secgroups/dialogId'); + var CONFIRM_DIALOG_ID = require('utils/dialogs/generic-confirm/dialogId'); /* CONSTRUCTOR */ @@ -74,12 +80,112 @@ define(function(require) { this.secgroupTable = new SecurityGroupsTable(SG_TABLE_ID, opts); - return this.secgroupTable.dataTableHTML; + return SecGroupsTemplate( + { + 'element': this.element, + 'tab': "vnets-tab", + 'action_add': "Network.add_secgroup", + 'action_rm': "Network.remove_secgroup", + 'dataTableHTML': this.secgroupTable.dataTableHTML + } + ); } function _setup(context) { - this.secgroupTable.initialize(); - this.secgroupTable.refreshResourceTableSelect(); + var that = this; + $("#selected_ids_row_vnet_sg_list_tabSecurityGroupsTable",context).hide(); + + if (that.secgroupTable){ + that.secgroupTable.initialize(); + that.secgroupTable.refreshResourceTableSelect(); + } + + var secGroupDatatable = $("#vnet_sg_list_tabSecurityGroupsTable", context).dataTable({ + "bSortClasses" : false, + "bDeferRender": true, + "aoColumnDefs": [ + //{ "bSortable": false, "aTargets": [3,4] }, + ] + }); + + secGroupDatatable.off("click", 'tbody tr'); + secGroupDatatable.on("click", 'tbody tr', function(e){ + var aData = secGroupDatatable.fnGetData(this); + if (!aData) return true; + var id = aData[1]; + if (!id) return true; + var name = aData[2]; + if (!name) return true; + + if(that.last_selected_row_secgroup) { + that.last_selected_row_secgroup.children().each(function(){ + $(this).removeClass('markrowchecked'); + }); + } + + that.last_selected_row_secgroup = $(this); + $(this).children().each(function(){ + $(this).addClass('markrowchecked'); + }); + + $("#rm_secgroup_button", context).attr("secgroups_id", id).attr("secgroups_name", name).removeAttr('disabled'); + + return false; + }); + + if (Config.isTabActionEnabled("vnets-tab", "Network.remove_secgroup")) { + context.off("click", 'button#rm_secgroup_button'); + context.on("click", 'button#rm_secgroup_button', function(){ + var secgroups_id = $(this).attr('secgroups_id'); + var secgroups_name = $(this).attr('secgroups_name'); + Sunstone.getDialog(CONFIRM_DIALOG_ID).setParams({ + //header : + headerTabId: TAB_ID, + body : Locale.tr("This will remove the security group") + ' "' + secgroups_name + '"', + //question : + submit : function(){ + var current_security_group = that.element.TEMPLATE.SECURITY_GROUPS.split(","); + var new_security_groups = []; + // Get current values of VNet. + var network_json = {} + obj = that.element.TEMPLATE; + for (var key in obj){ + var value = obj[key]; + network_json[key] = value; + } + + for (var i = 0; i < current_security_group.length; i++) { + var security_group = current_security_group[i]; + if (security_group != secgroups_id){ + new_security_groups.push(security_group); + } + } + + network_json["SECURITY_GROUPS"] = new_security_groups.join(","); + Sunstone.runAction('Network.rm_secgroup',that.element.ID,TemplateUtils.templateToString(network_json)); + + return false; + } + }); + + Sunstone.getDialog(CONFIRM_DIALOG_ID).reset(); + Sunstone.getDialog(CONFIRM_DIALOG_ID).show(); + + return false; + }); + } + + if (Config.isTabActionEnabled("vnets-tab", "Network.add_secgroup")) { + context.off("click", 'button#add_secgroup_button'); + context.on("click", 'button#add_secgroup_button', function(){ + var id = that.element.ID; + + Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).setId(id); + Sunstone.getDialog(ADD_SECGROUPS_DIALOG_ID).show(); + + return false; + }); + } return false; } diff --git a/src/sunstone/public/app/tabs/vnets-tab/panels/secgroups/html.hbs b/src/sunstone/public/app/tabs/vnets-tab/panels/secgroups/html.hbs new file mode 100644 index 0000000000..f495ca09ea --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/panels/secgroups/html.hbs @@ -0,0 +1,38 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2020, 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. }} +{{! -------------------------------------------------------------------------- }} + +
+
+
+ {{#isTabActionEnabled tab action_add}} + + {{/isTabActionEnabled}} + + {{#isTabActionEnabled tab action_rm}} + + {{/isTabActionEnabled}} + +
+
+
+ {{{dataTableHTML}}} +
+ +
diff --git a/src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab.js b/src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab.js new file mode 100644 index 0000000000..c39e9dc957 --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab.js @@ -0,0 +1,110 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2020, 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. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + // Dependencies + var Locale = require('utils/locale'); + var Tips = require('utils/tips'); + var CustomTagsTable = require('utils/custom-tags-table'); + var WizardFields = require('utils/wizard-fields'); + var SecurityGroupsTable = require('tabs/secgroups-tab/datatable'); + + var TemplateHTML = require('hbs!./secgroups-tab/html'); + + function SecGroupsTab() { + return this; + } + + SecGroupsTab.prototype = { + 'html': _generate_secgroup_tab_content, + 'setup': _setup_secgroup_tab_content, + 'onShow': _onShow, + 'fill': _fill_secgroup_tab_data, + 'retrieve': _retrieve_secgroup_tab_data + }; + SecGroupsTab.prototype.constructor = SecGroupsTab; + + return SecGroupsTab; + + function _generate_secgroup_tab_content(str_secgroup_tab_id){ + + var current_security_group = $("#value_td_input_SECURITY_GROUPS").text().split(","); + var secgroups = []; + + var opts = { + info: false, + select: true, + selectOptions: { + "multiple_choice": true + } + }; + + this.securityGroupsTable = new SecurityGroupsTable(str_secgroup_tab_id, opts); + + return TemplateHTML({ + 'str_secgroup_tab_id': str_secgroup_tab_id, + 'customTagsHTML': CustomTagsTable.html(), + 'securityGroupsTableHTML': this.securityGroupsTable.dataTableHTML + }); + } + + function _setup_secgroup_tab_content(secgroup_section, str_secgroup_tab_id) { + + this.secgroup_section = secgroup_section; + + CustomTagsTable.setup($('#'+str_secgroup_tab_id+'_custom_tags',secgroup_section)); + + this.securityGroupsTable.initialize(); + + Tips.setup(secgroup_section); + } + + function _onShow(){ + this.securityGroupsTable.refreshResourceTableSelect(); + } + + function _retrieve_secgroup_tab_data(){ + var data = {}; + + var fields = []; + + $.extend(data, CustomTagsTable.retrieve(this.secgroup_section)); + + var str_secgroup_tab_id = $('div[name="str_secgroup_tab_id"]', this.secgroup_section).attr("str_secgroup_tab_id"); + + var secgroups = this.securityGroupsTable.retrieveResourceTableSelect(); + if (secgroups != undefined && secgroups.length != 0){ + data["SECURITY_GROUPS"] = secgroups.join(","); + } + + return data; + } + + function _fill_secgroup_tab_data(secgroup_json){ + + if (secgroup_json["SECURITY_GROUPS"] != undefined && + secgroup_json["SECURITY_GROUPS"].length != 0){ + + var secgroups = secgroup_json["SECURITY_GROUPS"].split(","); + + this.securityGroupsTable.selectResourceTableSelect({ids: secgroups}); + } + + delete secgroup_json["SECURITY_GROUPS"]; + + CustomTagsTable.fill(this.secgroup_section, secgroup_json); + } +}); diff --git a/src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab/html.hbs b/src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab/html.hbs new file mode 100644 index 0000000000..663e8a96cf --- /dev/null +++ b/src/sunstone/public/app/tabs/vnets-tab/utils/secgroups-tab/html.hbs @@ -0,0 +1,5 @@ +
+
+ {{{securityGroupsTableHTML}}} +
+
\ No newline at end of file