Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / src / widgets / tree / TreeDragZone.js
1 /*!
2  * Ext JS Library 3.3.1
3  * Copyright(c) 2006-2010 Sencha Inc.
4  * licensing@sencha.com
5  * http://www.sencha.com/license
6  */
7 /**
8  * @class Ext.tree.TreeDragZone
9  * @extends Ext.dd.DragZone
10  * @constructor
11  * @param {String/HTMLElement/Element} tree The {@link Ext.tree.TreePanel} for which to enable dragging
12  * @param {Object} config
13  */
14 if(Ext.dd.DragZone){
15 Ext.tree.TreeDragZone = function(tree, config){
16     Ext.tree.TreeDragZone.superclass.constructor.call(this, tree.innerCt, config);
17     /**
18     * The TreePanel for this drag zone
19     * @type Ext.tree.TreePanel
20     * @property
21     */
22     this.tree = tree;
23 };
24
25 Ext.extend(Ext.tree.TreeDragZone, Ext.dd.DragZone, {
26     /**
27      * @cfg {String} ddGroup
28      * A named drag drop group to which this object belongs.  If a group is specified, then this object will only
29      * interact with other drag drop objects in the same group (defaults to 'TreeDD').
30      */
31     ddGroup : "TreeDD",
32
33     // private
34     onBeforeDrag : function(data, e){
35         var n = data.node;
36         return n && n.draggable && !n.disabled;
37     },
38
39     // private
40     onInitDrag : function(e){
41         var data = this.dragData;
42         this.tree.getSelectionModel().select(data.node);
43         this.tree.eventModel.disable();
44         this.proxy.update("");
45         data.node.ui.appendDDGhost(this.proxy.ghost.dom);
46         this.tree.fireEvent("startdrag", this.tree, data.node, e);
47     },
48
49     // private
50     getRepairXY : function(e, data){
51         return data.node.ui.getDDRepairXY();
52     },
53
54     // private
55     onEndDrag : function(data, e){
56         this.tree.eventModel.enable.defer(100, this.tree.eventModel);
57         this.tree.fireEvent("enddrag", this.tree, data.node, e);
58     },
59
60     // private
61     onValidDrop : function(dd, e, id){
62         this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
63         this.hideProxy();
64     },
65
66     // private
67     beforeInvalidDrop : function(e, id){
68         // this scrolls the original position back into view
69         var sm = this.tree.getSelectionModel();
70         sm.clearSelections();
71         sm.select(this.dragData.node);
72     },
73     
74     // private
75     afterRepair : function(){
76         if (Ext.enableFx && this.tree.hlDrop) {
77             Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
78         }
79         this.dragging = false;
80     }
81 });
82 }