provide installation instructions
[extjs.git] / source / dd / DropZone.js
1 /*\r
2  * Ext JS Library 2.2.1\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 /**\r
10  * @class Ext.dd.DropZone\r
11  * @extends Ext.dd.DropTarget\r
12  * This class provides a container DD instance that proxies for multiple child node targets.<br />\r
13  * By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.\r
14  * @constructor\r
15  * @param {Mixed} el The container element\r
16  * @param {Object} config\r
17  */\r
18 Ext.dd.DropZone = function(el, config){\r
19     Ext.dd.DropZone.superclass.constructor.call(this, el, config);\r
20 };\r
21 \r
22 Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {\r
23     /**\r
24      * Returns a custom data object associated with the DOM node that is the target of the event.  By default\r
25      * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to\r
26      * provide your own custom lookup.\r
27      * @param {Event} e The event\r
28      * @return {Object} data The custom data\r
29      */\r
30     getTargetFromEvent : function(e){\r
31         return Ext.dd.Registry.getTargetFromEvent(e);\r
32     },\r
33 \r
34     /**\r
35      * Called internally when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node\r
36      * that it has registered.  This method has no default implementation and should be overridden to provide\r
37      * node-specific processing if necessary.\r
38      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from \r
39      * {@link #getTargetFromEvent} for this node)\r
40      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
41      * @param {Event} e The event\r
42      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
43      */\r
44     onNodeEnter : function(n, dd, e, data){\r
45         \r
46     },\r
47 \r
48     /**\r
49      * Called internally while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node\r
50      * that it has registered.  The default implementation returns this.dropNotAllowed, so it should be\r
51      * overridden to provide the proper feedback.\r
52      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
53      * {@link #getTargetFromEvent} for this node)\r
54      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
55      * @param {Event} e The event\r
56      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
57      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
58      * underlying {@link Ext.dd.StatusProxy} can be updated\r
59      */\r
60     onNodeOver : function(n, dd, e, data){\r
61         return this.dropAllowed;\r
62     },\r
63 \r
64     /**\r
65      * Called internally when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of\r
66      * the drop node without dropping.  This method has no default implementation and should be overridden to provide\r
67      * node-specific processing if necessary.\r
68      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
69      * {@link #getTargetFromEvent} for this node)\r
70      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
71      * @param {Event} e The event\r
72      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
73      */\r
74     onNodeOut : function(n, dd, e, data){\r
75         \r
76     },\r
77 \r
78     /**\r
79      * Called internally when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto\r
80      * the drop node.  The default implementation returns false, so it should be overridden to provide the\r
81      * appropriate processing of the drop event and return true so that the drag source's repair action does not run.\r
82      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
83      * {@link #getTargetFromEvent} for this node)\r
84      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
85      * @param {Event} e The event\r
86      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
87      * @return {Boolean} True if the drop was valid, else false\r
88      */\r
89     onNodeDrop : function(n, dd, e, data){\r
90         return false;\r
91     },\r
92 \r
93     /**\r
94      * Called internally while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,\r
95      * but not over any of its registered drop nodes.  The default implementation returns this.dropNotAllowed, so\r
96      * it should be overridden to provide the proper feedback if necessary.\r
97      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
98      * @param {Event} e The event\r
99      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
100      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
101      * underlying {@link Ext.dd.StatusProxy} can be updated\r
102      */\r
103     onContainerOver : function(dd, e, data){\r
104         return this.dropNotAllowed;\r
105     },\r
106 \r
107     /**\r
108      * Called internally when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,\r
109      * but not on any of its registered drop nodes.  The default implementation returns false, so it should be\r
110      * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to\r
111      * be able to accept drops.  It should return true when valid so that the drag source's repair action does not run.\r
112      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
113      * @param {Event} e The event\r
114      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
115      * @return {Boolean} True if the drop was valid, else false\r
116      */\r
117     onContainerDrop : function(dd, e, data){\r
118         return false;\r
119     },\r
120 \r
121     /**\r
122      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over\r
123      * the zone.  The default implementation returns this.dropNotAllowed and expects that only registered drop\r
124      * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops\r
125      * you should override this method and provide a custom implementation.\r
126      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
127      * @param {Event} e The event\r
128      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
129      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
130      * underlying {@link Ext.dd.StatusProxy} can be updated\r
131      */\r
132     notifyEnter : function(dd, e, data){\r
133         return this.dropNotAllowed;\r
134     },\r
135 \r
136     /**\r
137      * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.\r
138      * This method will be called on every mouse movement while the drag source is over the drop zone.\r
139      * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically\r
140      * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits\r
141      * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a\r
142      * registered node, it will call {@link #onContainerOver}.\r
143      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
144      * @param {Event} e The event\r
145      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
146      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
147      * underlying {@link Ext.dd.StatusProxy} can be updated\r
148      */\r
149     notifyOver : function(dd, e, data){\r
150         var n = this.getTargetFromEvent(e);\r
151         if(!n){ // not over valid drop target\r
152             if(this.lastOverNode){\r
153                 this.onNodeOut(this.lastOverNode, dd, e, data);\r
154                 this.lastOverNode = null;\r
155             }\r
156             return this.onContainerOver(dd, e, data);\r
157         }\r
158         if(this.lastOverNode != n){\r
159             if(this.lastOverNode){\r
160                 this.onNodeOut(this.lastOverNode, dd, e, data);\r
161             }\r
162             this.onNodeEnter(n, dd, e, data);\r
163             this.lastOverNode = n;\r
164         }\r
165         return this.onNodeOver(n, dd, e, data);\r
166     },\r
167 \r
168     /**\r
169      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged\r
170      * out of the zone without dropping.  If the drag source is currently over a registered node, the notification\r
171      * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.\r
172      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
173      * @param {Event} e The event\r
174      * @param {Object} data An object containing arbitrary data supplied by the drag zone\r
175      */\r
176     notifyOut : function(dd, e, data){\r
177         if(this.lastOverNode){\r
178             this.onNodeOut(this.lastOverNode, dd, e, data);\r
179             this.lastOverNode = null;\r
180         }\r
181     },\r
182 \r
183     /**\r
184      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has\r
185      * been dropped on it.  The drag zone will look up the target node based on the event passed in, and if there\r
186      * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,\r
187      * otherwise it will call {@link #onContainerDrop}.\r
188      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
189      * @param {Event} e The event\r
190      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
191      * @return {Boolean} True if the drop was valid, else false\r
192      */\r
193     notifyDrop : function(dd, e, data){\r
194         if(this.lastOverNode){\r
195             this.onNodeOut(this.lastOverNode, dd, e, data);\r
196             this.lastOverNode = null;\r
197         }\r
198         var n = this.getTargetFromEvent(e);\r
199         return n ?\r
200             this.onNodeDrop(n, dd, e, data) :\r
201             this.onContainerDrop(dd, e, data);\r
202     },\r
203 \r
204     // private\r
205     triggerCacheRefresh : function(){\r
206         Ext.dd.DDM.refreshCache(this.groups);\r
207     }  \r
208 });