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, // 't' or 'b'
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         
31           Roo.log('ondragout');
32         var ret = Roo.tree.TreeDragZone.superclass.constructor.prototype.onDragOut.call(this, e, id);
33         
34         // if it's gone off top and bottom, start the scroller
35        
36         this.scrollDir = 't';
37         
38         if (this.scroller === false) {
39             Roo.log('start interval');
40             this.scroller = window.setInterval(
41                 this.scrollAct.createDelegate(this),
42                 500
43             );
44         }
45         
46         //Roo.log(this.el.dom);
47         
48         return ret;
49     },
50     onDragEnter : function(e, id) 
51     {
52         var ret = Roo.tree.TreeDragZone.superclass.constructor.prototype.onDragEnter.call(this, e, id);
53         Roo.log('ondrageneter');
54         if (this.scroller !== false) {
55             Roo.log('clear scroller');
56             window.clearInterval(this.scroller);
57             this.scroller =false;
58             
59         }
60         
61         //
62         
63         
64         //Roo.log(this);
65         
66         return ret;
67     },
68     
69     scrollAct: function()
70     {
71         Roo.log('scrollAct');
72         if (this.scrollDir === false) {
73             return;
74         }
75         Roo.log('scroll!');
76         this.el.scroll(this.scrollDir, 10, false);
77         
78         
79     },
80     
81     onInitDrag : function(e){
82         var data = this.dragData;
83         this.tree.getSelectionModel().select(data.node);
84         this.proxy.update("");
85         data.node.ui.appendDDGhost(this.proxy.ghost.dom);
86         this.tree.fireEvent("startdrag", this.tree, data.node, e);
87     },
88     
89     getRepairXY : function(e, data){
90         return data.node.ui.getDDRepairXY();
91     },
92     
93     onEndDrag : function(data, e){
94         this.tree.fireEvent("enddrag", this.tree, data.node, e);
95     },
96     
97     onValidDrop : function(dd, e, id){
98         this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
99         this.hideProxy();
100     },
101     
102     beforeInvalidDrop : function(e, id){
103         // this scrolls the original position back into view
104         var sm = this.tree.getSelectionModel();
105         sm.clearSelections();
106         sm.select(this.dragData.node);
107     }
108 });
109 }