Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / DropZone.html
1 <html>\r
2 <head>\r
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    \r
4   <title>The source code</title>\r
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js"><div id="cls-Ext.dd.DropZone"></div>/**\r
10  * @class Ext.dd.DropZone\r
11  * @extends Ext.dd.DropTarget\r
12  * <p>This class provides a container DD instance that allows dropping on multiple child target nodes.</p>\r
13  * <p>By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.\r
14  * However a simpler way to allow a DropZone to manage any number of target elements is to configure the\r
15  * DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed\r
16  * mouse event to see if it has taken place within an element, or class of elements. This is easily done\r
17  * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a\r
18  * {@link Ext.DomQuery} selector.</p>\r
19  * <p>Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over\r
20  * a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},\r
21  * {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations\r
22  * of these methods to provide application-specific behaviour for these events to update both\r
23  * application state, and UI state.</p>\r
24  * <p>For example to make a GridPanel a cooperating target with the example illustrated in\r
25  * {@link Ext.dd.DragZone DragZone}, the following technique might be used:</p><pre><code>\r
26 myGridPanel.on('render', function() {\r
27     myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {\r
28 \r
29 //      If the mouse is over a grid row, return that node. This is\r
30 //      provided as the "target" parameter in all "onNodeXXXX" node event handling functions\r
31         getTargetFromEvent: function(e) {\r
32             return e.getTarget(myGridPanel.getView().rowSelector);\r
33         },\r
34 \r
35 //      On entry into a target node, highlight that node.\r
36         onNodeEnter : function(target, dd, e, data){ \r
37             Ext.fly(target).addClass('my-row-highlight-class');\r
38         },\r
39 \r
40 //      On exit from a target node, unhighlight that node.\r
41         onNodeOut : function(target, dd, e, data){ \r
42             Ext.fly(target).removeClass('my-row-highlight-class');\r
43         },\r
44 \r
45 //      While over a target node, return the default drop allowed class which\r
46 //      places a "tick" icon into the drag proxy.\r
47         onNodeOver : function(target, dd, e, data){ \r
48             return Ext.dd.DropZone.prototype.dropAllowed;\r
49         },\r
50 \r
51 //      On node drop we can interrogate the target to find the underlying\r
52 //      application object that is the real target of the dragged data.\r
53 //      In this case, it is a Record in the GridPanel's Store.\r
54 //      We can use the data set up by the DragZone's getDragData method to read\r
55 //      any data we decided to attach in the DragZone's getDragData method.\r
56         onNodeDrop : function(target, dd, e, data){\r
57             var rowIndex = myGridPanel.getView().findRowIndex(target);\r
58             var r = myGridPanel.getStore().getAt(rowIndex);\r
59             Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +\r
60                 ' on Record id ' + r.id);\r
61             return true;\r
62         }\r
63     });\r
64 }\r
65 </code></pre>\r
66  * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which\r
67  * cooperates with this DropZone.\r
68  * @constructor\r
69  * @param {Mixed} el The container element\r
70  * @param {Object} config\r
71  */\r
72 Ext.dd.DropZone = function(el, config){\r
73     Ext.dd.DropZone.superclass.constructor.call(this, el, config);\r
74 };\r
75 \r
76 Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {\r
77     <div id="method-Ext.dd.DropZone-getTargetFromEvent"></div>/**\r
78      * Returns a custom data object associated with the DOM node that is the target of the event.  By default\r
79      * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to\r
80      * provide your own custom lookup.\r
81      * @param {Event} e The event\r
82      * @return {Object} data The custom data\r
83      */\r
84     getTargetFromEvent : function(e){\r
85         return Ext.dd.Registry.getTargetFromEvent(e);\r
86     },\r
87 \r
88     <div id="method-Ext.dd.DropZone-onNodeEnter"></div>/**\r
89      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node\r
90      * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.\r
91      * This method has no default implementation and should be overridden to provide\r
92      * node-specific processing if necessary.\r
93      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from \r
94      * {@link #getTargetFromEvent} for this node)\r
95      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
96      * @param {Event} e The event\r
97      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
98      */\r
99     onNodeEnter : function(n, dd, e, data){\r
100         \r
101     },\r
102 \r
103     <div id="method-Ext.dd.DropZone-onNodeOver"></div>/**\r
104      * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node\r
105      * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.\r
106      * The default implementation returns this.dropNotAllowed, so it should be\r
107      * overridden to provide the proper feedback.\r
108      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
109      * {@link #getTargetFromEvent} for this node)\r
110      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
111      * @param {Event} e The event\r
112      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
113      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
114      * underlying {@link Ext.dd.StatusProxy} can be updated\r
115      */\r
116     onNodeOver : function(n, dd, e, data){\r
117         return this.dropAllowed;\r
118     },\r
119 \r
120     <div id="method-Ext.dd.DropZone-onNodeOut"></div>/**\r
121      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of\r
122      * the drop node without dropping.  This method has no default implementation and should be overridden to provide\r
123      * node-specific processing if necessary.\r
124      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
125      * {@link #getTargetFromEvent} for this node)\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      */\r
130     onNodeOut : function(n, dd, e, data){\r
131         \r
132     },\r
133 \r
134     <div id="method-Ext.dd.DropZone-onNodeDrop"></div>/**\r
135      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto\r
136      * the drop node.  The default implementation returns false, so it should be overridden to provide the\r
137      * appropriate processing of the drop event and return true so that the drag source's repair action does not run.\r
138      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
139      * {@link #getTargetFromEvent} for this node)\r
140      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
141      * @param {Event} e The event\r
142      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
143      * @return {Boolean} True if the drop was valid, else false\r
144      */\r
145     onNodeDrop : function(n, dd, e, data){\r
146         return false;\r
147     },\r
148 \r
149     <div id="method-Ext.dd.DropZone-onContainerOver"></div>/**\r
150      * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,\r
151      * but not over any of its registered drop nodes.  The default implementation returns this.dropNotAllowed, so\r
152      * it should be overridden to provide the proper feedback if necessary.\r
153      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
154      * @param {Event} e The event\r
155      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
156      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
157      * underlying {@link Ext.dd.StatusProxy} can be updated\r
158      */\r
159     onContainerOver : function(dd, e, data){\r
160         return this.dropNotAllowed;\r
161     },\r
162 \r
163     <div id="method-Ext.dd.DropZone-onContainerDrop"></div>/**\r
164      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,\r
165      * but not on any of its registered drop nodes.  The default implementation returns false, so it should be\r
166      * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to\r
167      * be able to accept drops.  It should return true when valid so that the drag source's repair action does not run.\r
168      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
169      * @param {Event} e The event\r
170      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
171      * @return {Boolean} True if the drop was valid, else false\r
172      */\r
173     onContainerDrop : function(dd, e, data){\r
174         return false;\r
175     },\r
176 \r
177     <div id="method-Ext.dd.DropZone-notifyEnter"></div>/**\r
178      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over\r
179      * the zone.  The default implementation returns this.dropNotAllowed and expects that only registered drop\r
180      * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops\r
181      * you should override this method and provide a custom implementation.\r
182      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
183      * @param {Event} e The event\r
184      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
185      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
186      * underlying {@link Ext.dd.StatusProxy} can be updated\r
187      */\r
188     notifyEnter : function(dd, e, data){\r
189         return this.dropNotAllowed;\r
190     },\r
191 \r
192     <div id="method-Ext.dd.DropZone-notifyOver"></div>/**\r
193      * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.\r
194      * This method will be called on every mouse movement while the drag source is over the drop zone.\r
195      * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically\r
196      * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits\r
197      * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a\r
198      * registered node, it will call {@link #onContainerOver}.\r
199      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
200      * @param {Event} e The event\r
201      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
202      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
203      * underlying {@link Ext.dd.StatusProxy} can be updated\r
204      */\r
205     notifyOver : function(dd, e, data){\r
206         var n = this.getTargetFromEvent(e);\r
207         if(!n){ // not over valid drop target\r
208             if(this.lastOverNode){\r
209                 this.onNodeOut(this.lastOverNode, dd, e, data);\r
210                 this.lastOverNode = null;\r
211             }\r
212             return this.onContainerOver(dd, e, data);\r
213         }\r
214         if(this.lastOverNode != n){\r
215             if(this.lastOverNode){\r
216                 this.onNodeOut(this.lastOverNode, dd, e, data);\r
217             }\r
218             this.onNodeEnter(n, dd, e, data);\r
219             this.lastOverNode = n;\r
220         }\r
221         return this.onNodeOver(n, dd, e, data);\r
222     },\r
223 \r
224     <div id="method-Ext.dd.DropZone-notifyOut"></div>/**\r
225      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged\r
226      * out of the zone without dropping.  If the drag source is currently over a registered node, the notification\r
227      * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.\r
228      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
229      * @param {Event} e The event\r
230      * @param {Object} data An object containing arbitrary data supplied by the drag zone\r
231      */\r
232     notifyOut : function(dd, e, data){\r
233         if(this.lastOverNode){\r
234             this.onNodeOut(this.lastOverNode, dd, e, data);\r
235             this.lastOverNode = null;\r
236         }\r
237     },\r
238 \r
239     <div id="method-Ext.dd.DropZone-notifyDrop"></div>/**\r
240      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has\r
241      * been dropped on it.  The drag zone will look up the target node based on the event passed in, and if there\r
242      * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,\r
243      * otherwise it will call {@link #onContainerDrop}.\r
244      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
245      * @param {Event} e The event\r
246      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
247      * @return {Boolean} True if the drop was valid, else false\r
248      */\r
249     notifyDrop : function(dd, e, data){\r
250         if(this.lastOverNode){\r
251             this.onNodeOut(this.lastOverNode, dd, e, data);\r
252             this.lastOverNode = null;\r
253         }\r
254         var n = this.getTargetFromEvent(e);\r
255         return n ?\r
256             this.onNodeDrop(n, dd, e, data) :\r
257             this.onContainerDrop(dd, e, data);\r
258     },\r
259 \r
260     // private\r
261     triggerCacheRefresh : function(){\r
262         Ext.dd.DDM.refreshCache(this.groups);\r
263     }  \r
264 });</pre>    \r
265 </body>\r
266 </html>