4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-grid-plugin-DragDrop'>/**
19 </span> * This plugin provides drag and/or drop functionality for a GridView.
21 * It creates a specialized instance of {@link Ext.dd.DragZone DragZone} which knows how to drag out of a {@link
22 * Ext.grid.View GridView} and loads the data object which is passed to a cooperating {@link Ext.dd.DragZone DragZone}'s
23 * methods with the following properties:
27 * The value of the GridView's `copy` property, or `true` if the GridView was configured with `allowCopy: true` _and_
28 * the control key was pressed when the drag operation was begun.
32 * The source GridView from which the drag originated.
34 * - `ddel` : HtmlElement
36 * The drag proxy element which moves with the mouse
38 * - `item` : HtmlElement
40 * The GridView node upon which the mousedown event was registered.
44 * An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.
46 * It also creates a specialized instance of {@link Ext.dd.DropZone} which cooperates with other DropZones which are
47 * members of the same ddGroup which processes such data objects.
49 * Adding this plugin to a view means that two new events may be fired from the client GridView, `{@link #beforedrop
50 * beforedrop}` and `{@link #drop drop}`
53 * Ext.create('Ext.data.Store', {
54 * storeId:'simpsonsStore',
56 * data: [["Lisa"], ["Bart"], ["Homer"], ["Marge"]],
63 * Ext.create('Ext.grid.Panel', {
64 * store: 'simpsonsStore',
66 * {header: 'Name', dataIndex: 'name', flex: true}
70 * ptype: 'gridviewdragdrop',
71 * dragText: 'Drag and drop to reorganize'
76 * renderTo: Ext.getBody()
79 Ext.define('Ext.grid.plugin.DragDrop', {
80 extend: 'Ext.AbstractPlugin',
81 alias: 'plugin.gridviewdragdrop',
85 'Ext.grid.ViewDropZone'
88 <span id='Ext-grid-plugin-DragDrop-event-beforedrop'> /**
89 </span> * @event beforedrop
90 * **This event is fired through the GridView. Add listeners to the GridView object**
92 * Fired when a drop gesture has been triggered by a mouseup event in a valid drop position in the GridView.
94 * @param {HTMLElement} node The GridView node **if any** over which the mouse was positioned.
96 * Returning `false` to this event signals that the drop gesture was invalid, and if the drag proxy will animate
97 * back to the point from which the drag began.
99 * Returning `0` To this event signals that the data transfer operation should not take place, but that the gesture
100 * was valid, and that the repair operation should not take place.
102 * Any other return value continues with the data transfer operation.
104 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone
105 * DragZone}'s {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:
109 * The value of the GridView's `copy` property, or `true` if the GridView was configured with `allowCopy: true` and
110 * the control key was pressed when the drag operation was begun
114 * The source GridView from which the drag originated.
116 * - ddel : HtmlElement
118 * The drag proxy element which moves with the mouse
120 * - item : HtmlElement
122 * The GridView node upon which the mousedown event was registered.
126 * An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.
128 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
130 * @param {String} dropPosition `"before"` or `"after"` depending on whether the mouse is above or below the midline
133 * @param {Function} dropFunction
135 * A function to call to complete the data transfer operation and either move or copy Model instances from the
136 * source View's Store to the destination View's Store.
138 * This is useful when you want to perform some kind of asynchronous processing before confirming the drop, such as
139 * an {@link Ext.window.MessageBox#confirm confirm} call, or an Ajax request.
141 * Return `0` from this event handler, and call the `dropFunction` at any time to perform the data transfer.
144 <span id='Ext-grid-plugin-DragDrop-event-drop'> /**
145 </span> * @event drop
146 * **This event is fired through the GridView. Add listeners to the GridView object** Fired when a drop operation
147 * has been completed and the data has been moved or copied.
149 * @param {HTMLElement} node The GridView node **if any** over which the mouse was positioned.
151 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone
152 * DragZone}'s {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:
156 * The value of the GridView's `copy` property, or `true` if the GridView was configured with `allowCopy: true` and
157 * the control key was pressed when the drag operation was begun
161 * The source GridView from which the drag originated.
163 * - ddel : HtmlElement
165 * The drag proxy element which moves with the mouse
167 * - item : HtmlElement
169 * The GridView node upon which the mousedown event was registered.
173 * An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.
175 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
177 * @param {String} dropPosition `"before"` or `"after"` depending on whether the mouse is above or below the midline
181 dragText : '{0} selected row{1}',
183 <span id='Ext-grid-plugin-DragDrop-cfg-ddGroup'> /**
184 </span> * @cfg {String} ddGroup
185 * A named drag drop group to which this object belongs. If a group is specified, then both the DragZones and
186 * DropZone used by this plugin will only interact with other drag drop objects in the same group.
188 ddGroup : "GridDD",
190 <span id='Ext-grid-plugin-DragDrop-cfg-dragGroup'> /**
191 </span> * @cfg {String} dragGroup
192 * The ddGroup to which the DragZone will belong.
194 * This defines which other DropZones the DragZone will interact with. Drag/DropZones only interact with other
195 * Drag/DropZones which are members of the same ddGroup.
198 <span id='Ext-grid-plugin-DragDrop-cfg-dropGroup'> /**
199 </span> * @cfg {String} dropGroup
200 * The ddGroup to which the DropZone will belong.
202 * This defines which other DragZones the DropZone will interact with. Drag/DropZones only interact with other
203 * Drag/DropZones which are members of the same ddGroup.
206 <span id='Ext-grid-plugin-DragDrop-cfg-enableDrop'> /**
207 </span> * @cfg {Boolean} enableDrop
208 * False to disallow the View from accepting drop gestures.
212 <span id='Ext-grid-plugin-DragDrop-cfg-enableDrag'> /**
213 </span> * @cfg {Boolean} enableDrag
214 * False to disallow dragging items from the View.
218 init : function(view) {
219 view.on('render', this.onViewRender, this, {single: true});
222 <span id='Ext-grid-plugin-DragDrop-method-destroy'> /**
224 * AbstractComponent calls destroy on all its plugins at destroy time.
226 destroy: function() {
227 Ext.destroy(this.dragZone, this.dropZone);
233 me.dragZone.unlock();
236 me.dropZone.unlock();
241 disable: function() {
252 onViewRender : function(view) {
256 me.dragZone = Ext.create('Ext.view.DragZone', {
258 ddGroup: me.dragGroup || me.ddGroup,
259 dragText: me.dragText
264 me.dropZone = Ext.create('Ext.grid.ViewDropZone', {
266 ddGroup: me.dropGroup || me.ddGroup