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 * @class Ext.grid.plugin.DragDrop
17 * <p>This plugin provides drag and/or drop functionality for a GridView.</p>
18 * <p>It creates a specialized instance of {@link Ext.dd.DragZone DragZone} which knows how to drag out of a {@link Ext.grid.View GridView}
19 * and loads the data object which is passed to a cooperating {@link Ext.dd.DragZone DragZone}'s methods with the following properties:<ul>
21 * <div class="sub-desc">The value of the GridView's <code>copy</code> property, or <code>true</code> if the GridView was configured
22 * with <code>allowCopy: true</code> <u>and</u> the control key was pressed when the drag operation was begun.</div></li>
24 * <div class="sub-desc">The source GridView from which the drag originated.</div></li>
25 * <li>ddel : HtmlElement
26 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
27 * <li>item : HtmlElement
28 * <div class="sub-desc">The GridView node upon which the mousedown event was registered.</div></li>
30 * <div class="sub-desc">An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.</div></li>
32 * <p>It also creates a specialized instance of {@link Ext.dd.DropZone} which cooperates with other DropZones which are members of the same
33 * ddGroup which processes such data objects.</p>
34 * <p>Adding this plugin to a view means that two new events may be fired from the client GridView, <code>{@link #event-beforedrop beforedrop}</code> and
35 * <code>{@link #event-drop drop}</code></p>
37 Ext.define('Ext.grid.plugin.DragDrop', {
38 extend: 'Ext.AbstractPlugin',
39 alias: 'plugin.gridviewdragdrop',
43 'Ext.grid.ViewDropZone'
48 * <p><b>This event is fired through the GridView. Add listeners to the GridView object</b></p>
49 * <p>Fired when a drop gesture has been triggered by a mouseup event in a valid drop position in the GridView.
50 * @param {HtmlElement} node The GridView node <b>if any</b> over which the mouse was positioned.</p>
51 * <p>Returning <code>false</code> to this event signals that the drop gesture was invalid, and if the drag proxy
52 * will animate back to the point from which the drag began.</p>
53 * <p>Returning <code>0</code> To this event signals that the data transfer operation should not take place, but
54 * that the gesture was valid, and that the repair operation should not take place.</p>
55 * <p>Any other return value continues with the data transfer operation.</p>
56 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone DragZone}'s
57 * {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:<ul>
59 * <div class="sub-desc">The value of the GridView's <code>copy</code> property, or <code>true</code> if the GridView was configured
60 * with <code>allowCopy: true</code> and the control key was pressed when the drag operation was begun</div></li>
62 * <div class="sub-desc">The source GridView from which the drag originated.</div></li>
63 * <li>ddel : HtmlElement
64 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
65 * <li>item : HtmlElement
66 * <div class="sub-desc">The GridView node upon which the mousedown event was registered.</div></li>
68 * <div class="sub-desc">An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.</div></li>
70 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
71 * @param {String} dropPosition <code>"before"</code> or <code>"after"</code> depending on whether the mouse is above or below the midline of the node.
72 * @param {Function} dropFunction <p>A function to call to complete the data transfer operation and either move or copy Model instances from the source
73 * View's Store to the destination View's Store.</p>
74 * <p>This is useful when you want to perform some kind of asynchronous processing before confirming
75 * the drop, such as an {@link Ext.window.MessageBox#confirm confirm} call, or an Ajax request.</p>
76 * <p>Return <code>0</code> from this event handler, and call the <code>dropFunction</code> at any time to perform the data transfer.</p>
81 * <b>This event is fired through the GridView. Add listeners to the GridView object</b>
82 * Fired when a drop operation has been completed and the data has been moved or copied.
83 * @param {HtmlElement} node The GridView node <b>if any</b> over which the mouse was positioned.
84 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone DragZone}'s
85 * {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:<ul>
87 * <div class="sub-desc">The value of the GridView's <code>copy</code> property, or <code>true</code> if the GridView was configured
88 * with <code>allowCopy: true</code> and the control key was pressed when the drag operation was begun</div></li>
90 * <div class="sub-desc">The source GridView from which the drag originated.</div></li>
91 * <li>ddel : HtmlElement
92 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
93 * <li>item : HtmlElement
94 * <div class="sub-desc">The GridView node upon which the mousedown event was registered.</div></li>
96 * <div class="sub-desc">An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source GridView.</div></li>
98 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
99 * @param {String} dropPosition <code>"before"</code> or <code>"after"</code> depending on whether the mouse is above or below the midline of the node.
102 dragText : '{0} selected row{1}',
105 * @cfg {String} ddGroup
106 * A named drag drop group to which this object belongs. If a group is specified, then both the DragZones and DropZone
107 * used by this plugin will only interact with other drag drop objects in the same group (defaults to 'TreeDD').
112 * @cfg {String} dragGroup
113 * <p>The ddGroup to which the DragZone will belong.</p>
114 * <p>This defines which other DropZones the DragZone will interact with. Drag/DropZones only interact with other Drag/DropZones
115 * which are members of the same ddGroup.</p>
119 * @cfg {String} dropGroup
120 * <p>The ddGroup to which the DropZone will belong.</p>
121 * <p>This defines which other DragZones the DropZone will interact with. Drag/DropZones only interact with other Drag/DropZones
122 * which are members of the same ddGroup.</p>
126 * @cfg {Boolean} enableDrop
127 * <p>Defaults to <code>true</code></p>
128 * <p>Set to <code>false</code> to disallow the View from accepting drop gestures</p>
133 * @cfg {Boolean} enableDrag
134 * <p>Defaults to <code>true</code></p>
135 * <p>Set to <code>false</code> to disallow dragging items from the View </p>
139 init : function(view) {
140 view.on('render', this.onViewRender, this, {single: true});
145 * AbstractComponent calls destroy on all its plugins at destroy time.
147 destroy: function() {
148 Ext.destroy(this.dragZone, this.dropZone);
151 onViewRender : function(view) {
155 me.dragZone = Ext.create('Ext.view.DragZone', {
157 ddGroup: me.dragGroup || me.ddGroup,
158 dragText: me.dragText
163 me.dropZone = Ext.create('Ext.grid.ViewDropZone', {
165 ddGroup: me.dropGroup || me.ddGroup