Topic: Block drag'n'drop to specific level in tree

Hi,

I must implement some blocking of drag'n' drop to some level, Let's say that I want to menu with max 3 level:

1. Main menu
   1.1
   1.2
      1.2.1
2. Main menu 2
   2.1
   2.2
and so on


so, there must be some way to block moving i.e. 2.2 to menu 1.2.1.1 for example:

1. Main menu
   1.1
   1.2
      1.2.1
         1.2.1.1 <- bad

Can anyone help me with this?

Thanks and regards
Paul

Re: Block drag'n'drop to specific level in tree

Mif.Tree.Node.implement({
    
    getLevel: function(){
        var level=0;
        var node=this;
        while(node){
            node=node.getParent();
            level++;
        }
        return level;
    }
    
});

tree = new Mif.Tree({
    initialize: function(){
        new Mif.Tree.Drag(this,{
            onDrag: function(){
                if(this.target.getLevel()>3){
                    this.where='notAllowed';
                }
            }
            ...
        });
        ...
    },
    ...

Re: Block drag'n'drop to specific level in tree

Thank you very much Moro, generally this works but not everytime.

1. Main menu
   1.1
   1.2

I could put menu 1.2 into menu 1.1:

1. Main menu
   1.1
      1.2
2. Main menu 2
...

This is OK. But I can't sort on this level (something like this):

before:
1. Main menu
   1.1
      1.1.2
      1.1.3
after
1. Main menu
   1.1
      1.1.3
      1.1.2

Re: Block drag'n'drop to specific level in tree

if(this.target.getLevel()>3 && this.where=='inside'){
    this.where='notAllowed';
}