Hybrid View

  1. #1
    Ext User
    Join Date
    Apr 2007
    Posts
    32
    Vote Rating
    0
    vicent is on a distinguished road

      0  

    Default how can copy the Item but not cut it on the Drag and Drop ?

    how can copy the Item but not cut it on the Drag and Drop ?


    Any one can give me a suggest about .. how can I copy the item to another place ? that mean the original item still on the original place

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I think that would be up to your implementation to decide whether to remove the original or not. The DragDrop system just informs you of user actions. You write the code to move data around and possibly remove data from the source.

  3. #3
    Ext User
    Join Date
    Apr 2007
    Posts
    32
    Vote Rating
    0
    vicent is on a distinguished road

      0  

    Default


    Ext.onReady(function(){
    // shorthand
    var Tree = Ext.tree;

    var tree = new Tree.TreePanel('tree-div', {
    animate:true,
    loader: new Tree.TreeLoader({dataUrl:'get-nodes.php'}),
    enableDD:true,
    containerScroll: true
    });

    // set the root node
    var root = new Tree.AsyncTreeNode({
    text: 'Ext JS',
    draggable:false,
    id:'source'
    });
    tree.setRootNode(root);

    // render the tree
    tree.render();
    root.expand();
    });

    could you please tell me how can I config on these code ? I just want it doesn't remove when drop on another place

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I know as much as you about this.

    But I'm sure it's possible. You just have to listen for the right events.

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    You are going to love how easy it is.

    Copy the node before the drop is processed and change the dropNode:

    Code:
    tree.on('beforenodedrop', function(e){
        var n = e.dropNode; // the node that was dropped
        var copy = new xt.TreeNode( // copy it
              Ext.apply({}, n.attributes) 
        );
        e.dropNode = copy; // assign the copy as the new dropNode
    });
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com

  6. #6
    Ext User
    Join Date
    Apr 2007
    Posts
    32
    Vote Rating
    0
    vicent is on a distinguished road

      0  

    Default


    Animal , Jack
    Thanks a lot for your help !

  7. #7
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Jack, would it be possible to have the mousedown handler record the state of the control key, and have the default processing do a copy if the node drag was started with CTRL+MOUSEDOWN?

    That would have to be an optional feature because sometimes you don't want copying.

  8. #8
    Sencha User broutard's Avatar
    Join Date
    Jan 2008
    Location
    France
    Posts
    13
    Vote Rating
    0
    broutard is on a distinguished road

      0  

    Default


    Thanks, but this copy work partialy...

    When you copy a non-opening folder, you can't open the copy

    Example here : http://www.chassemy.org/sesamath/tree/two-trees.html

    nb: To prevent duplicating nodes dragged from inside the tree I have writed this :
    Code:
    tree2.on('beforenodedrop', function(e){
           if(e.source.tree.el != e.target.ownerTree.el) {
                  e.dropNode = e.dropNode.clone();
           }
    });
    Anyone can help me please ?
    Last edited by broutard; 7 Jan 2008 at 3:58 PM. Reason: adding example

  9. #9
    Ext User para's Avatar
    Join Date
    Apr 2007
    Location
    Redmond, WA
    Posts
    918
    Vote Rating
    -2
    para has a little shameless behaviour in the past

      0  

    Default


    That is because the function was made to work with TreeNode, not AsyncTreeNode.
    Here's a better version:

    Code:
    Ext.override(Ext.tree.TreeNode, {
    	clone: function() {
    		var atts = this.attributes;
    		atts.id = Ext.id(null, "ynode-");
    		if(this.childrenRendered || this.loaded || !this.attributes.children) {
    			var clone = new Ext.tree.TreeNode(Ext.apply({}, atts));
    		}
    		else {
    			var newAtts = Ext.apply({}, atts);
    			newAtts.children = this.cloneUnrenderedChildren();
    			var clone = new Ext.tree.AsyncTreeNode(newAtts);
    		}
    		newNode.text = this.text;
    		clone.text = this.text;
    	
    		for(var i=0; i<this.childNodes.length; i++){
    			clone.appendChild(this.childNodes[i].clone());
    		}
    		return clone;
    	},
    
    	cloneUnrenderedChildren: function() {
    	
    		unrenderedClone = function(n) {
    			n.id = undefined;
    			if(n.children) {
    				for(var j=0; j<n.children.length; j++) {
    					n.children[j] = unrenderedClone(n.children[j]);
    				}
    			}
    			return n;
    		};
    
    		var c = [];
    		for(var i=0; i<this.attributes.children.length; i++) {
    			c[i] = Ext.apply({}, this.attributes.children[i]);
    			c[i] = unrenderedClone(c[i]);
    		}
    	
    
    		return c;
    	},
    
    });
    I'm sure there's a more efficient way to do this though.

  10. #10
    Sencha User
    Join Date
    Nov 2008
    Posts
    50
    Vote Rating
    0
    dtondo is on a distinguished road

      0  

    Default


    good, works for me, only comment this line: //newNode.text = this.text;

    thanks

    Quote Originally Posted by para View Post
    That is because the function was made to work with TreeNode, not AsyncTreeNode.
    Here's a better version:

    Code:
    Ext.override(Ext.tree.TreeNode, {
        clone: function() {
            var atts = this.attributes;
            atts.id = Ext.id(null, "ynode-");
            if(this.childrenRendered || this.loaded || !this.attributes.children) {
                var clone = new Ext.tree.TreeNode(Ext.apply({}, atts));
            }
            else {
                var newAtts = Ext.apply({}, atts);
                newAtts.children = this.cloneUnrenderedChildren();
                var clone = new Ext.tree.AsyncTreeNode(newAtts);
            }
            newNode.text = this.text;
            clone.text = this.text;
        
            for(var i=0; i<this.childNodes.length; i++){
                clone.appendChild(this.childNodes[i].clone());
            }
            return clone;
        },
    
        cloneUnrenderedChildren: function() {
        
            unrenderedClone = function(n) {
                n.id = undefined;
                if(n.children) {
                    for(var j=0; j<n.children.length; j++) {
                        n.children[j] = unrenderedClone(n.children[j]);
                    }
                }
                return n;
            };
    
            var c = [];
            for(var i=0; i<this.attributes.children.length; i++) {
                c[i] = Ext.apply({}, this.attributes.children[i]);
                c[i] = unrenderedClone(c[i]);
            }
        
    
            return c;
        },
    
    });
    I'm sure there's a more efficient way to do this though.