Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Richard Rowles on Nov 10, 2009 07:44
open dhtmlx forum
onDrop - remove parent if empty

Hi,

I'm trying to make sure that if I drag the last tiem out of a folder, instead of the folder turning to a page, the folder should be removed from the tree, if it is empty. Anyhow, unless I'm taking the wrong approach, this almost works but the page I've dragged out of the folder never gets dropped.

function onDrop(sId,tId,id,sObject,tObject)
{

        if (skipDrag == false)
            {
                var myID = tree.getSelectedItemId();            
                editSite(id,myID,"move"); /*does ajax stuff*/
                if (tree.hasChildren(tree.getParentId(sId)) == 1)
                    {    
                        tree.deleteItem(tree.getParentId(sId),true);
                    }
                
            }    

return true;
}
Answer posted by Alex (support) on Nov 10, 2009 08:00

Hello,

you can try to use the following approach:

var deleted = false;
tree.attachEvent("onDrag",function(sId,tId){
    if (tree.hasChildren(tree.getParentId(sId)) == 1) deleted = tree.getParentId(sId);
    else deleted = false;
    return true;  
})
tree.attachEvent("onDrop",function(sId,tId){
    if(deleted) tree.deleteItem(deleted,true);
})