Merge branch 'master' of http://git.roojs.com/roojs1
[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     
28     onInitDrag : function(e){
29         var data = this.dragData;
30         this.tree.getSelectionModel().select(data.node);
31         this.proxy.update("");
32         data.node.ui.appendDDGhost(this.proxy.ghost.dom);
33         this.tree.fireEvent("startdrag", this.tree, data.node, e);
34     },
35     
36     getRepairXY : function(e, data){
37         return data.node.ui.getDDRepairXY();
38     },
39     
40     onEndDrag : function(data, e){
41         this.tree.fireEvent("enddrag", this.tree, data.node, e);
42         
43         
44     },
45     
46     onValidDrop : function(dd, e, id){
47         this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
48         this.hideProxy();
49     },
50     
51     beforeInvalidDrop : function(e, id){
52         // this scrolls the original position back into view
53         var sm = this.tree.getSelectionModel();
54         sm.clearSelections();
55         sm.select(this.dragData.node);
56     }
57 });
58 }