23a44ca855e8ca3e2e2e3b5a6750688490faeadd
[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     
22     onBeforeDrag : function(data, e){
23         var n = data.node;
24         return n && n.draggable && !n.disabled;
25     },
26     
27     onDragOut : function(e, id) 
28     {
29         Roo.tree.TreeDragZone.superclass.prototype.onDragOut.call(this, e, id);
30     },
31     
32     onInitDrag : function(e){
33         var data = this.dragData;
34         this.tree.getSelectionModel().select(data.node);
35         this.proxy.update("");
36         data.node.ui.appendDDGhost(this.proxy.ghost.dom);
37         this.tree.fireEvent("startdrag", this.tree, data.node, e);
38     },
39     
40     getRepairXY : function(e, data){
41         return data.node.ui.getDDRepairXY();
42     },
43     
44     onEndDrag : function(data, e){
45         this.tree.fireEvent("enddrag", this.tree, data.node, e);
46     },
47     
48     onValidDrop : function(dd, e, id){
49         this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
50         this.hideProxy();
51     },
52     
53     beforeInvalidDrop : function(e, id){
54         // this scrolls the original position back into view
55         var sm = this.tree.getSelectionModel();
56         sm.clearSelections();
57         sm.select(this.dragData.node);
58     }
59 });
60 }