4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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> * @class Ext.grid.plugin.DragDrop
20 * <p>This plugin provides drag and/or drop functionality for a GridView.</p>
21 * <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}
22 * and loads the data object which is passed to a cooperating {@link Ext.dd.DragZone DragZone}'s methods with the following properties:<ul>
23 * <li>copy : Boolean
24 * <div class="sub-desc">The value of the GridView's <code>copy</code> property, or <code>true</code> if the GridView was configured
25 * with <code>allowCopy: true</code> <u>and</u> the control key was pressed when the drag operation was begun.</div></li>
26 * <li>view : GridView
27 * <div class="sub-desc">The source GridView from which the drag originated.</div></li>
28 * <li>ddel : HtmlElement
29 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
30 * <li>item : HtmlElement
31 * <div class="sub-desc">The GridView node upon which the mousedown event was registered.</div></li>
32 * <li>records : Array
33 * <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>
34 * </ul></p>
35 * <p>It also creates a specialized instance of {@link Ext.dd.DropZone} which cooperates with other DropZones which are members of the same
36 * ddGroup which processes such data objects.</p>
37 * <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
38 * <code>{@link #event-drop drop}</code></p>
40 Ext.define('Ext.grid.plugin.DragDrop', {
41 extend: 'Ext.AbstractPlugin',
42 alias: 'plugin.gridviewdragdrop',
46 'Ext.grid.ViewDropZone'
49 <span id='Ext-grid-plugin-DragDrop-event-beforedrop'> /**
50 </span> * @event beforedrop
51 * <p><b>This event is fired through the GridView. Add listeners to the GridView object</b></p>
52 * <p>Fired when a drop gesture has been triggered by a mouseup event in a valid drop position in the GridView.
53 * @param {HtmlElement} node The GridView node <b>if any</b> over which the mouse was positioned.</p>
54 * <p>Returning <code>false</code> to this event signals that the drop gesture was invalid, and if the drag proxy
55 * will animate back to the point from which the drag began.</p>
56 * <p>Returning <code>0</code> To this event signals that the data transfer operation should not take place, but
57 * that the gesture was valid, and that the repair operation should not take place.</p>
58 * <p>Any other return value continues with the data transfer operation.</p>
59 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone DragZone}'s
60 * {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:<ul>
61 * <li>copy : Boolean
62 * <div class="sub-desc">The value of the GridView's <code>copy</code> property, or <code>true</code> if the GridView was configured
63 * with <code>allowCopy: true</code> and the control key was pressed when the drag operation was begun</div></li>
64 * <li>view : GridView
65 * <div class="sub-desc">The source GridView from which the drag originated.</div></li>
66 * <li>ddel : HtmlElement
67 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
68 * <li>item : HtmlElement
69 * <div class="sub-desc">The GridView node upon which the mousedown event was registered.</div></li>
70 * <li>records : Array
71 * <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>
73 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
74 * @param {String} dropPosition <code>"before"</code> or <code>"after"</code> depending on whether the mouse is above or below the midline of the node.
75 * @param {Function} dropFunction <p>A function to call to complete the data transfer operation and either move or copy Model instances from the source
76 * View's Store to the destination View's Store.</p>
77 * <p>This is useful when you want to perform some kind of asynchronous processing before confirming
78 * the drop, such as an {@link Ext.window.MessageBox#confirm confirm} call, or an Ajax request.</p>
79 * <p>Return <code>0</code> from this event handler, and call the <code>dropFunction</code> at any time to perform the data transfer.</p>
82 <span id='Ext-grid-plugin-DragDrop-event-drop'> /**
84 * <b>This event is fired through the GridView. Add listeners to the GridView object</b>
85 * Fired when a drop operation has been completed and the data has been moved or copied.
86 * @param {HtmlElement} node The GridView node <b>if any</b> over which the mouse was positioned.
87 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone DragZone}'s
88 * {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:<ul>
89 * <li>copy : Boolean
90 * <div class="sub-desc">The value of the GridView's <code>copy</code> property, or <code>true</code> if the GridView was configured
91 * with <code>allowCopy: true</code> and the control key was pressed when the drag operation was begun</div></li>
92 * <li>view : GridView
93 * <div class="sub-desc">The source GridView from which the drag originated.</div></li>
94 * <li>ddel : HtmlElement
95 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
96 * <li>item : HtmlElement
97 * <div class="sub-desc">The GridView node upon which the mousedown event was registered.</div></li>
98 * <li>records : Array
99 * <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>
101 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
102 * @param {String} dropPosition <code>"before"</code> or <code>"after"</code> depending on whether the mouse is above or below the midline of the node.
105 dragText : '{0} selected row{1}',
107 <span id='Ext-grid-plugin-DragDrop-cfg-ddGroup'> /**
108 </span> * @cfg {String} ddGroup
109 * A named drag drop group to which this object belongs. If a group is specified, then both the DragZones and DropZone
110 * used by this plugin will only interact with other drag drop objects in the same group (defaults to 'TreeDD').
112 ddGroup : "GridDD",
114 <span id='Ext-grid-plugin-DragDrop-cfg-dragGroup'> /**
115 </span> * @cfg {String} dragGroup
116 * <p>The ddGroup to which the DragZone will belong.</p>
117 * <p>This defines which other DropZones the DragZone will interact with. Drag/DropZones only interact with other Drag/DropZones
118 * which are members of the same ddGroup.</p>
121 <span id='Ext-grid-plugin-DragDrop-cfg-dropGroup'> /**
122 </span> * @cfg {String} dropGroup
123 * <p>The ddGroup to which the DropZone will belong.</p>
124 * <p>This defines which other DragZones the DropZone will interact with. Drag/DropZones only interact with other Drag/DropZones
125 * which are members of the same ddGroup.</p>
128 <span id='Ext-grid-plugin-DragDrop-cfg-enableDrop'> /**
129 </span> * @cfg {Boolean} enableDrop
130 * <p>Defaults to <code>true</code></p>
131 * <p>Set to <code>false</code> to disallow the View from accepting drop gestures</p>
135 <span id='Ext-grid-plugin-DragDrop-cfg-enableDrag'> /**
136 </span> * @cfg {Boolean} enableDrag
137 * <p>Defaults to <code>true</code></p>
138 * <p>Set to <code>false</code> to disallow dragging items from the View </p>
142 init : function(view) {
143 view.on('render', this.onViewRender, this, {single: true});
146 <span id='Ext-grid-plugin-DragDrop-method-destroy'> /**
148 * AbstractComponent calls destroy on all its plugins at destroy time.
150 destroy: function() {
151 Ext.destroy(this.dragZone, this.dropZone);
154 onViewRender : function(view) {
158 me.dragZone = Ext.create('Ext.view.DragZone', {
160 ddGroup: me.dragGroup || me.ddGroup,
161 dragText: me.dragText
166 me.dropZone = Ext.create('Ext.grid.ViewDropZone', {
168 ddGroup: me.dropGroup || me.ddGroup