3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * This plugin provides drag and/or drop functionality for a GridView.
18 * It creates a specialized instance of {@link Ext.dd.DragZone DragZone} which knows how to drag out of a {@link
19 * Ext.grid.View GridView} and loads the data object which is passed to a cooperating {@link Ext.dd.DragZone DragZone}'s
20 * methods with the following properties:
24 * The value of the GridView's `copy` property, or `true` if the GridView was configured with `allowCopy: true` _and_
25 * the control key was pressed when the drag operation was begun.
29 * The source GridView from which the drag originated.
31 * - `ddel` : HtmlElement
33 * The drag proxy element which moves with the mouse
35 * - `item` : HtmlElement
37 * The GridView node upon which the mousedown event was registered.
41 * An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.
43 * It also creates a specialized instance of {@link Ext.dd.DropZone} which cooperates with other DropZones which are
44 * members of the same ddGroup which processes such data objects.
46 * Adding this plugin to a view means that two new events may be fired from the client GridView, `{@link #beforedrop
47 * beforedrop}` and `{@link #drop drop}`
50 * Ext.create('Ext.data.Store', {
51 * storeId:'simpsonsStore',
53 * data: [["Lisa"], ["Bart"], ["Homer"], ["Marge"]],
60 * Ext.create('Ext.grid.Panel', {
61 * store: 'simpsonsStore',
63 * {header: 'Name', dataIndex: 'name', flex: true}
67 * ptype: 'gridviewdragdrop',
68 * dragText: 'Drag and drop to reorganize'
73 * renderTo: Ext.getBody()
76 Ext.define('Ext.grid.plugin.DragDrop', {
77 extend: 'Ext.AbstractPlugin',
78 alias: 'plugin.gridviewdragdrop',
82 'Ext.grid.ViewDropZone'
87 * **This event is fired through the GridView. Add listeners to the GridView object**
89 * Fired when a drop gesture has been triggered by a mouseup event in a valid drop position in the GridView.
91 * @param {HTMLElement} node The GridView node **if any** over which the mouse was positioned.
93 * Returning `false` to this event signals that the drop gesture was invalid, and if the drag proxy will animate
94 * back to the point from which the drag began.
96 * Returning `0` To this event signals that the data transfer operation should not take place, but that the gesture
97 * was valid, and that the repair operation should not take place.
99 * Any other return value continues with the data transfer operation.
101 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone
102 * DragZone}'s {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:
106 * The value of the GridView's `copy` property, or `true` if the GridView was configured with `allowCopy: true` and
107 * the control key was pressed when the drag operation was begun
111 * The source GridView from which the drag originated.
113 * - ddel : HtmlElement
115 * The drag proxy element which moves with the mouse
117 * - item : HtmlElement
119 * The GridView node upon which the mousedown event was registered.
123 * An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.
125 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
127 * @param {String} dropPosition `"before"` or `"after"` depending on whether the mouse is above or below the midline
130 * @param {Function} dropFunction
132 * A function to call to complete the data transfer operation and either move or copy Model instances from the
133 * source View's Store to the destination View's Store.
135 * This is useful when you want to perform some kind of asynchronous processing before confirming the drop, such as
136 * an {@link Ext.window.MessageBox#confirm confirm} call, or an Ajax request.
138 * Return `0` from this event handler, and call the `dropFunction` at any time to perform the data transfer.
143 * **This event is fired through the GridView. Add listeners to the GridView object** Fired when a drop operation
144 * has been completed and the data has been moved or copied.
146 * @param {HTMLElement} node The GridView node **if any** over which the mouse was positioned.
148 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone
149 * DragZone}'s {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:
153 * The value of the GridView's `copy` property, or `true` if the GridView was configured with `allowCopy: true` and
154 * the control key was pressed when the drag operation was begun
158 * The source GridView from which the drag originated.
160 * - ddel : HtmlElement
162 * The drag proxy element which moves with the mouse
164 * - item : HtmlElement
166 * The GridView node upon which the mousedown event was registered.
170 * An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.
172 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
174 * @param {String} dropPosition `"before"` or `"after"` depending on whether the mouse is above or below the midline
178 dragText : '{0} selected row{1}',
181 * @cfg {String} ddGroup
182 * A named drag drop group to which this object belongs. If a group is specified, then both the DragZones and
183 * DropZone used by this plugin will only interact with other drag drop objects in the same group.
188 * @cfg {String} dragGroup
189 * The ddGroup to which the DragZone will belong.
191 * This defines which other DropZones the DragZone will interact with. Drag/DropZones only interact with other
192 * Drag/DropZones which are members of the same ddGroup.
196 * @cfg {String} dropGroup
197 * The ddGroup to which the DropZone will belong.
199 * This defines which other DragZones the DropZone will interact with. Drag/DropZones only interact with other
200 * Drag/DropZones which are members of the same ddGroup.
204 * @cfg {Boolean} enableDrop
205 * False to disallow the View from accepting drop gestures.
210 * @cfg {Boolean} enableDrag
211 * False to disallow dragging items from the View.
215 init : function(view) {
216 view.on('render', this.onViewRender, this, {single: true});
221 * AbstractComponent calls destroy on all its plugins at destroy time.
223 destroy: function() {
224 Ext.destroy(this.dragZone, this.dropZone);
230 me.dragZone.unlock();
233 me.dropZone.unlock();
238 disable: function() {
249 onViewRender : function(view) {
253 me.dragZone = Ext.create('Ext.view.DragZone', {
255 ddGroup: me.dragGroup || me.ddGroup,
256 dragText: me.dragText
261 me.dropZone = Ext.create('Ext.grid.ViewDropZone', {
263 ddGroup: me.dropGroup || me.ddGroup