in script.js [770:822]
function handleDrop(e) {
e.stopPropagation(); // Stop redirect
e.preventDefault();
// Remove drag-over class from all items
document.querySelectorAll('.tree-item.drag-over').forEach(item => {
item.classList.remove('drag-over');
});
// Find the tree item element (could be a child element that received the event)
const dropTarget = e.target.closest('.tree-item');
if (!dropTarget) {
return false;
}
// Remove highlight from drop target
dropTarget.classList.remove('drag-over');
// Get the target management group ID (where we're dropping)
const dropTargetId = dropTarget.dataset.id;
// Only process if target has an ID (is a management group)
if (!dropTargetId) {
return false;
}
// Don't do anything if dropping onto itself
if (draggedMgId === dropTargetId) {
return false;
}
// Prevent a management group from becoming its own ancestor
if (wouldCreateCycle(draggedMgId, dropTargetId)) {
alert("Cannot move a management group to one of its descendants.");
return false;
}
// Change the parent ID of the dragged management group
updateMgParent(draggedMgId, dropTargetId);
// Mark the drop as successful
dropSuccessful = true;
// Re-render the tree
renderManagementGroups();
// Keep the previously selected management group selected
if (selectedMgId) {
selectManagementGroup(selectedMgId);
}
return false;
}