Inventory refactor: fixed drag-n-drop so that a group cannot be dropped onto itself or dropped into a group where it already exists.

This commit is contained in:
chris Houseknecht 2014-01-15 14:19:46 -05:00
parent 9bf941e8d4
commit c62718493c
4 changed files with 26 additions and 10 deletions

View File

@ -417,7 +417,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
})
.error( function(data, status, headers, config) {
ProcessErrors(scope, data, status, form,
{ hdr: 'Error!', msg: 'Failed to retrieve host: ' + id + '. GET returned status: ' + status });
{ hdr: 'Error!', msg: 'Failed to retrieve host: ' + host_id + '. GET returned status: ' + status });
});

View File

@ -376,12 +376,12 @@ dd {
.help-link,
.help-link:active,
.help-link:visited {
color: #49afcd;
color: @grey;
text-decoration: none;
}
.help-link:hover {
color: @blue;
color: @black;
text-decoration: none;
}

View File

@ -75,7 +75,7 @@ angular.module('InventoryTree', ['Utilities', 'RestServices', 'GroupsHelper', 'P
var children = [];
for (var j=0; j < sorted[i].children.length; j++) {
children.push(sorted[i].children[j]);
children.push(sorted[i].children[j].id);
}
var group = {

View File

@ -554,14 +554,30 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService'])
// the following is inventory specific accept checking and
// drop processing.
accept: function(draggable) {
var node = Find({ list: scope.groups, key: 'id', val: parseInt($(this).attr('data-tree-id')) });
if (node) {
var group = draggable.attr('data-group-id');
return (node.children.indexOf(group) > -1) ? false : true;
if ($(this).attr('data-group-id') == draggable.attr('data-group-id')) {
// No dropping a node onto itself (or a copy)
return false;
}
else {
// this shouldn't be possible
return false;
// No dropping a node into a group that already has the node
var node = Find({ list: scope.groups, key: 'id', val: parseInt($(this).attr('data-tree-id')) });
if (node) {
var group = parseInt(draggable.attr('data-group-id'));
var found = false;
// For whatever reason indexOf() would not work...
for (var i=0; i < node.children.length; i++) {
if (node.children[i] == group) {
found = true;
break;
}
}
return (found) ? false : true;
}
else {
// this shouldn't be possible
return false;
}
}
},
over: function(e, ui) {