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