dnd event before drop

104 views
Skip to first unread message

Thomas Auvinet

unread,
Jan 30, 2015, 9:26:22 AM1/30/15
to jst...@googlegroups.com
Hi,

First, thanks for this amazing plugin !

For my case, I have got a problem. I need to check the node I'm dragging before drop to know if I had to copy or move this node.
Typically, I have two kinds of items. If I drop on one of them, I want to copy. If it is the other one, I want to move it.

Is there an event or a way to do this ? A kind of "check_if_droppable" or something else.

Thanks, and sorry if my question has already been asked.
And sorry for my bad english !

Regards,
Thomas

Ivan Bozhanov

unread,
Jan 30, 2015, 9:59:47 AM1/30/15
to jst...@googlegroups.com
The closest thing I can think of is the check_callback, it will be triggered multiple times while dragging:
core : {
  check_callback : function (operation, node, par, pos, more) {
    // while dragging more.dnd will be set so check for it
    if((operation === "copy_node" || operation === "move_node") more && more.dnd) {
      // you can work with the nodes here
       var n = this.get_node(node),
            p = this.get_node(par);
       // if you want to prevent the drop - return false
       return false;
    }
  }

As for settings - check the dnd settings - there is an always_copy setting which may be useful in your case.

Best regards,
Ivan

Thomas Auvinet

unread,
Jan 30, 2015, 10:16:39 AM1/30/15
to jst...@googlegroups.com
Thanks for your quick response.
During this time, I look for this solution too.

I am trying something like this : 
if(node.parent === par.id){
   $.jstree.defaults.dnd.always_copy = false;
}else{
  $.jstree.defaults.dnd.always_copy = true;
}

But I can't change the operation dynamically. Do am I something wrong ? Is That possible to do this change ?

Thomas

Thomas Auvinet

unread,
Jan 30, 2015, 12:00:54 PM1/30/15
to jst...@googlegroups.com
I finally got it !

Here is my dnd settings : 
dnd:{
    is_draggable:function(nodeList){return nodeList[0].icon == 'category';},
    drag_selection:false,
    always_copy:true
}

I declare a global variable copy : 
var copy = true;

And my check_callback function : 
"check_callback" : function(operation, node, node_parent, node_position, more) {
    if((operation === "copy_node" || operation === "move_node") && more.dnd){
        copy = node.parent != node_parent.id;
    }

    if(!copy && !more.dnd){
        copy = true;
        $('#categorie-container').jstree(true).move_node(node, node_parent, node_position);
        return false;
    }

    return true;
}

May be there is a better solution but it works !

Thanks for all.
Thomas
Reply all
Reply to author
Forward
0 new messages