1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-27 10:50:10 +03:00

F #2623 remove resource from VDC (#3789)

Signed-off-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Lobo 2019-10-01 14:17:58 +02:00 committed by Ruben S. Montero
parent 0c830c2cee
commit cfac3ad57c
6 changed files with 120 additions and 29 deletions

View File

@ -102,10 +102,7 @@ define(function(require) {
var color_html = Status.state_lock_to_color("CLUSTER",false, element_json[XML_ROOT]["LOCK"]);
return [
'<input class="check_item" type="checkbox" '+
'style="vertical-align: inherit;" id="'+this.resource.toLowerCase()+'_' +
element.ID + '" name="selected_items" value="' +
element.ID + '"/>'+color_html,
'<input class="check_item" type="checkbox" style="vertical-align: inherit;" id="'+this.resource.toLowerCase()+'_' + element.ID + '" name="selected_items" value="' + element.ID + '"/>'+color_html,
element.ID,
element.NAME,
_lengthOf(element.HOSTS.ID),

View File

@ -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);

View File

@ -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,

View File

@ -132,7 +132,8 @@ define(function(require) {
$(html_tab_content).appendTo($(".vdc_zones_tabs_content", context));
$("select.vdc_zones_select", context).append(
'<option value="'+zone_id+'">'+zone_name+'</option>');
'<option value="'+zone_id+'">'+zone_name+'</option>'
);
var zoneSection = $('#' +unique_id+'Tab', context);

View File

@ -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
}
};
}

View File

@ -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('<span row_id="' + row_id + '" class="radius label">' + row_name + '</span> ');
var attr = {row_id:row_id, class:"radius label"};
var span = $("<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 = $("<span/>",attr).text(row_name);
$('#selected_ids_row_' + that.dataTableId, section).append('<span row_id="' + row_id + '" class="radius label">' + row_name + '</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);
}
$('#selected_ids_row_' + that.dataTableId, section).append(span);
});
$('#selected_ids_row_' + that.dataTableId, section).data("ids", data_ids);