diff --git a/src/sunstone/public/app/tabs/clusters-tab/datatable.js b/src/sunstone/public/app/tabs/clusters-tab/datatable.js index 90a077aafe..7acd446ef9 100644 --- a/src/sunstone/public/app/tabs/clusters-tab/datatable.js +++ b/src/sunstone/public/app/tabs/clusters-tab/datatable.js @@ -102,10 +102,7 @@ define(function(require) { var color_html = Status.state_lock_to_color("CLUSTER",false, element_json[XML_ROOT]["LOCK"]); return [ - ''+color_html, + ''+color_html, element.ID, element.NAME, _lengthOf(element.HOSTS.ID), diff --git a/src/sunstone/public/app/tabs/vdcs-tab/form-panels/create.js b/src/sunstone/public/app/tabs/vdcs-tab/form-panels/create.js index 43bc95f3a6..6cb8f7ea5c 100644 --- a/src/sunstone/public/app/tabs/vdcs-tab/form-panels/create.js +++ b/src/sunstone/public/app/tabs/vdcs-tab/form-panels/create.js @@ -19,7 +19,7 @@ define(function(require) { DEPENDENCIES */ -// require('foundation.tab'); + // require('foundation.tab'); var BaseFormPanel = require('utils/form-panels/form-panel'); var Sunstone = require('sunstone'); var Locale = require('utils/locale'); @@ -131,12 +131,16 @@ define(function(require) { success: function (request, obj_list){ var zoneSection = $("#vdcCreateResourcesTab",context); - $.each(obj_list,function(){ - that.resourcesTab.addResourcesZone( - this.ZONE.ID, - this.ZONE.NAME, - zoneSection); - }); + $.each( + obj_list, + function(){ + that.resourcesTab.addResourcesZone( + this.ZONE.ID, + this.ZONE.NAME, + zoneSection + ); + } + ); that.resourcesTab.setup(zoneSection); }, @@ -159,7 +163,6 @@ define(function(require) { $.extend(vdc_json, CustomTagsTable.retrieve($("#vdcCreateGeneralTab", context))); var group_ids = this.groupsTable.retrieveResourceTableSelect(); - if (this.action == "create") { var resources = this.resourcesTab.retrieve(context); @@ -362,7 +365,8 @@ define(function(require) { this.ZONE.ID, this.ZONE.NAME, zoneSection); - }); + } + ); that.resourcesTab.setup(zoneSection); that.resourcesTab.fill(zoneSection, that.originalSelectedResources); diff --git a/src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js index b89304b844..36d6434b03 100644 --- a/src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js +++ b/src/sunstone/public/app/tabs/vdcs-tab/panels/resources.js @@ -40,11 +40,10 @@ define(function(require) { function Panel(info) { this.title = Locale.tr("Resources"); this.icon = "fa-th"; - this.element = info[XML_ROOT]; - + window.VDCId = this.element.ID; + window.VDCInfo = this.element; this.resourcesTab = new ResourcesTab("vdc_info_panel"); - return this; } @@ -64,9 +63,7 @@ define(function(require) { function _setup(context) { var that = this; - var indexed_resources = Utils.indexedVdcResources(this.element); - $.each(indexed_resources, function(zone_id,objects){ that.resourcesTab.addResourcesZone( zone_id, diff --git a/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-tab.js b/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-tab.js index 5745a15b60..cedbf7275e 100644 --- a/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-tab.js +++ b/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-tab.js @@ -132,7 +132,8 @@ define(function(require) { $(html_tab_content).appendTo($(".vdc_zones_tabs_content", context)); $("select.vdc_zones_select", context).append( - ''); + '' + ); var zoneSection = $('#' +unique_id+'Tab', context); diff --git a/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-zone.js b/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-zone.js index baa1f2b77d..a8a9fbabc7 100644 --- a/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-zone.js +++ b/src/sunstone/public/app/tabs/vdcs-tab/utils/resources-zone.js @@ -22,6 +22,7 @@ define(function(require) { var HostsTable = require('tabs/hosts-tab/datatable'); var VNetsTable = require('tabs/vnets-tab/datatable'); var DatastoresTable = require('tabs/datastores-tab/datatable'); + var Sunstone = require('sunstone'); var Tips = require('utils/tips'); var Utils = require('./common'); @@ -57,19 +58,95 @@ define(function(require) { var opts = {}; $.each(["clusters", "hosts", "vnets", "datastores"], function(i,res_name){ + var existElement = function(position, internalPosition, id){ + var rtn = false; + if(position && + internalPosition && + id && + window && + window.VDCInfo && + window.VDCInfo[position] && + window.VDCInfo[position][internalPosition] + ){ + var info = window.VDCInfo[position][internalPosition]; + var retn = {}; + if(Array.isArray(info) && + info.find(function(element){ + return element[internalPosition+"_ID"] === id; + })) + { + retn = info.filter(function(el) { return el[internalPosition+"_ID"] !== id}); + rtn = true; + }else if(info && info[internalPosition] && info[internalPosition+"_ID"] === id){ + rtn = true; + } + window.VDCInfo[position][internalPosition] = retn; + } + return rtn; + }; + var clickAction = function(e){ + var element = $(this); + var action = "Vdc.del_"; + var dataAction = {zone_id: that.zone_id}; + var id = element.attr("row_id"); + var pass = false; + var actionName = "datastore"; + switch (res_name) { + case "clusters": + actionName = "cluster"; + action = action+actionName; + dataAction.cluster_id = id; + pass = existElement(res_name.toUpperCase(),actionName.toUpperCase(),id); + break; + case "hosts": + actionName = "host"; + action = action+actionName; + dataAction.host_id = id; + pass = existElement(res_name.toUpperCase(),actionName.toUpperCase(),id); + break; + case "vnets": + actionName = "vnet"; + action = action+actionName; + dataAction.vnet_id = id; + pass = existElement(res_name.toUpperCase(),actionName.toUpperCase(),id); + break; + default: + action = action+actionName; + dataAction.ds_id = id; + pass = existElement(res_name.toUpperCase(),actionName.toUpperCase(),id); + break; + } + if(window && window.VDCId && window.VDCInfo && pass){ + Sunstone.runAction( + action, + window.window.VDCId, + dataAction + ); + } + element.parent().parent().siblings().find("table").find("tr").each( + function(i,row){ + var tds = $(row).find("td"); + if(tds && $(tds[0]).text() === id){ + tds.removeClass("markrowchecked"); + $(tds[0]).parent().click(); + } + } + ); + element.remove(); + } + if(that.resources != undefined){ opts[res_name] = { info: true, select: true, selectOptions: { - read_only: true, - zone_id: that.zone_id + read_only: false, + zone_id: that.zone_id, + click: clickAction } }; - if (!(that.resources[res_name].length == 1 && - that.resources[res_name][0] == VDC_ALL_RESOURCES) ){ - + if (!(that.resources[res_name].length == 1 && that.resources[res_name][0] == VDC_ALL_RESOURCES)){ opts[res_name].selectOptions.fixed_ids = that.resources[res_name]; } } else { @@ -78,7 +155,8 @@ define(function(require) { select: true, selectOptions: { multiple_choice: true, - zone_id: that.zone_id + zone_id: that.zone_id, + click: clickAction } }; } diff --git a/src/sunstone/public/app/utils/tab-datatable.js b/src/sunstone/public/app/utils/tab-datatable.js index 2e758d4ecf..04a1381425 100644 --- a/src/sunstone/public/app/utils/tab-datatable.js +++ b/src/sunstone/public/app/utils/tab-datatable.js @@ -904,8 +904,14 @@ define(function(require) { $("td", row).addClass('markrowchecked'); $('input.check_item', row).prop('checked', true); } - - $('#selected_ids_row_' + that.dataTableId, section).append('' + row_name + ' '); + + var attr = {row_id:row_id, class:"radius label"}; + var span = $("",attr).text(row_name); + $('#selected_ids_row_' + that.dataTableId, section).append(span); + if(that.selectOptions.click && typeof that.selectOptions.click === "function"){ + span.attr("title",Locale.tr("just click if you want to delete the resource")); + span.off("click").on("click", that.selectOptions.click); + } that.selectOptions.select_callback(aData, that.selectOptions); } @@ -1064,9 +1070,10 @@ define(function(require) { */ function _selectResourceTableSelect(selectedResources) { var that = this; + var section = $('#' + that.dataTableId + 'Container'); - if (that.selectOptions.multiple_choice) { + if (that && that.selectOptions && that.selectOptions.multiple_choice) { that.refreshResourceTableSelect(section, that.dataTableId); var data_ids = {}; @@ -1089,8 +1096,15 @@ define(function(require) { var row_name = "" + row_id; row_name = OpenNebula[that.resource].getName(row_id); + var attr = {row_id:row_id, class:"radius label"}; + var span = $("",attr).text(row_name); - $('#selected_ids_row_' + that.dataTableId, section).append('' + row_name + ' '); + if(that.selectOptions.click && typeof that.selectOptions.click === "function"){ + span.attr("title",Locale.tr("just click if you want to delete the resource")); + span.off("click").on("click", that.selectOptions.click); + } + + $('#selected_ids_row_' + that.dataTableId, section).append(span); }); $('#selected_ids_row_' + that.dataTableId, section).data("ids", data_ids);