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
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
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
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
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
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
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
66 * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which
\r
67 * cooperates with this DropZone.
\r
69 * @param {Mixed} el The container element
\r
70 * @param {Object} config
\r
72 Ext.dd.DropZone = function(el, config){
\r
73 Ext.dd.DropZone.superclass.constructor.call(this, el, config);
\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
84 getTargetFromEvent : function(e){
\r
85 return Ext.dd.Registry.getTargetFromEvent(e);
\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
99 onNodeEnter : function(n, dd, e, data){
\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
116 onNodeOver : function(n, dd, e, data){
\r
117 return this.dropAllowed;
\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
130 onNodeOut : function(n, dd, e, data){
\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
145 onNodeDrop : function(n, dd, e, data){
\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
159 onContainerOver : function(dd, e, data){
\r
160 return this.dropNotAllowed;
\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
173 onContainerDrop : function(dd, e, data){
\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
188 notifyEnter : function(dd, e, data){
\r
189 return this.dropNotAllowed;
\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
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
212 return this.onContainerOver(dd, e, data);
\r
214 if(this.lastOverNode != n){
\r
215 if(this.lastOverNode){
\r
216 this.onNodeOut(this.lastOverNode, dd, e, data);
\r
218 this.onNodeEnter(n, dd, e, data);
\r
219 this.lastOverNode = n;
\r
221 return this.onNodeOver(n, dd, e, data);
\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
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
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
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
254 var n = this.getTargetFromEvent(e);
\r
256 this.onNodeDrop(n, dd, e, data) :
\r
257 this.onContainerDrop(dd, e, data);
\r
261 triggerCacheRefresh : function(){
\r
262 Ext.dd.DDM.refreshCache(this.groups);
\r