Roo/tree/TreeDragZone.js
[roojs1] / Roo / tree / TreeDragZone.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  
12
13 if(Roo.dd.DragZone){
14 Roo.tree.TreeDragZone = function(tree, config){
15     Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
16     this.tree = tree;
17 };
18
19 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
20     ddGroup : "TreeDD",
21     scroller : false,
22     
23     onBeforeDrag : function(data, e){
24         var n = data.node;
25         return n && n.draggable && !n.disabled;
26     },
27     
28     onDragOut : function(e, id) 
29     {
30         var ret = Roo.tree.TreeDragZone.superclass.constructor.prototype.onDragOut.call(this, e, id);
31         
32         Roo.log('ondragout');
33         Roo.log(this);
34         
35         return ret;
36     },
37     onDragEnter : function(e, id) 
38     {
39         var ret = Roo.tree.TreeDragZone.superclass.constructor.prototype.onDragEnter.call(this, e, id);
40         
41         if (this.scroller !== false) {
42             window.clearTimeout(this.scroller);
43             this.scroller =false;
44             
45         }
46         
47         Roo.log('ondrageneter');
48         
49         
50         Roo.log(this);
51         
52         return ret;
53     },
54     onInitDrag : function(e){
55         var data = this.dragData;
56         this.tree.getSelectionModel().select(data.node);
57         this.proxy.update("");
58         data.node.ui.appendDDGhost(this.proxy.ghost.dom);
59         this.tree.fireEvent("startdrag", this.tree, data.node, e);
60     },
61     
62     getRepairXY : function(e, data){
63         return data.node.ui.getDDRepairXY();
64     },
65     
66     onEndDrag : function(data, e){
67         this.tree.fireEvent("enddrag", this.tree, data.node, e);
68     },
69     
70     onValidDrop : function(dd, e, id){
71         this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
72         this.hideProxy();
73     },
74     
75     beforeInvalidDrop : function(e, id){
76         // this scrolls the original position back into view
77         var sm = this.tree.getSelectionModel();
78         sm.clearSelections();
79         sm.select(this.dragData.node);
80     }
81 });
82 }