Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / dd / DropTarget.js
1 /*!
2  * Ext JS Library 3.1.0
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.dd.DropTarget\r
9  * @extends Ext.dd.DDTarget\r
10  * A simple class that provides the basic implementation needed to make any element a drop target that can have\r
11  * draggable items dropped onto it.  The drop has no effect until an implementation of notifyDrop is provided.\r
12  * @constructor\r
13  * @param {Mixed} el The container element\r
14  * @param {Object} config\r
15  */\r
16 Ext.dd.DropTarget = function(el, config){\r
17     this.el = Ext.get(el);\r
18     \r
19     Ext.apply(this, config);\r
20     \r
21     if(this.containerScroll){\r
22         Ext.dd.ScrollManager.register(this.el);\r
23     }\r
24     \r
25     Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, \r
26           {isTarget: true});\r
27 \r
28 };\r
29 \r
30 Ext.extend(Ext.dd.DropTarget, Ext.dd.DDTarget, {\r
31     /**\r
32      * @cfg {String} ddGroup\r
33      * A named drag drop group to which this object belongs.  If a group is specified, then this object will only\r
34      * interact with other drag drop objects in the same group (defaults to undefined).\r
35      */\r
36     /**\r
37      * @cfg {String} overClass\r
38      * The CSS class applied to the drop target element while the drag source is over it (defaults to "").\r
39      */\r
40     /**\r
41      * @cfg {String} dropAllowed\r
42      * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").\r
43      */\r
44     dropAllowed : "x-dd-drop-ok",\r
45     /**\r
46      * @cfg {String} dropNotAllowed\r
47      * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").\r
48      */\r
49     dropNotAllowed : "x-dd-drop-nodrop",\r
50 \r
51     // private\r
52     isTarget : true,\r
53 \r
54     // private\r
55     isNotifyTarget : true,\r
56 \r
57     /**\r
58      * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source is now over the\r
59      * target.  This default implementation adds the CSS class specified by overClass (if any) to the drop element\r
60      * and returns the dropAllowed config value.  This method should be overridden if drop validation is required.\r
61      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
62      * @param {Event} e The event\r
63      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
64      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
65      * underlying {@link Ext.dd.StatusProxy} can be updated\r
66      */\r
67     notifyEnter : function(dd, e, data){\r
68         if(this.overClass){\r
69             this.el.addClass(this.overClass);\r
70         }\r
71         return this.dropAllowed;\r
72     },\r
73 \r
74     /**\r
75      * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the target.\r
76      * This method will be called on every mouse movement while the drag source is over the drop target.\r
77      * This default implementation simply returns the dropAllowed config value.\r
78      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
79      * @param {Event} e The event\r
80      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
81      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
82      * underlying {@link Ext.dd.StatusProxy} can be updated\r
83      */\r
84     notifyOver : function(dd, e, data){\r
85         return this.dropAllowed;\r
86     },\r
87 \r
88     /**\r
89      * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source has been dragged\r
90      * out of the target without dropping.  This default implementation simply removes the CSS class specified by\r
91      * overClass (if any) from the drop element.\r
92      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
93      * @param {Event} e The event\r
94      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
95      */\r
96     notifyOut : function(dd, e, data){\r
97         if(this.overClass){\r
98             this.el.removeClass(this.overClass);\r
99         }\r
100     },\r
101 \r
102     /**\r
103      * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the dragged item has\r
104      * been dropped on it.  This method has no default implementation and returns false, so you must provide an\r
105      * implementation that does something to process the drop event and returns true so that the drag source's\r
106      * repair action does not run.\r
107      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
108      * @param {Event} e The event\r
109      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
110      * @return {Boolean} True if the drop was valid, else false\r
111      */\r
112     notifyDrop : function(dd, e, data){\r
113         return false;\r
114     }\r
115 });