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-tree-ViewDDPlugin'>/**
19 </span> * @class Ext.tree.ViewDDPlugin
20 * @extends Ext.AbstractPlugin
21 * <p>This plugin provides drag and/or drop functionality for a TreeView.</p>
22 * <p>It creates a specialized instance of {@link Ext.dd.DragZone DragZone} which knows how to drag out of a {@link Ext.tree.View TreeView}
23 * and loads the data object which is passed to a cooperating {@link Ext.dd.DragZone DragZone}'s methods with the following properties:<ul>
24 * <li>copy : Boolean
25 * <div class="sub-desc">The value of the TreeView's <code>copy</code> property, or <code>true</code> if the TreeView was configured
26 * with <code>allowCopy: true</code> <u>and</u> the control key was pressed when the drag operation was begun.</div></li>
27 * <li>view : TreeView
28 * <div class="sub-desc">The source TreeView from which the drag originated.</div></li>
29 * <li>ddel : HtmlElement
30 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
31 * <li>item : HtmlElement
32 * <div class="sub-desc">The TreeView node upon which the mousedown event was registered.</div></li>
33 * <li>records : Array
34 * <div class="sub-desc">An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source TreeView.</div></li>
35 * </ul></p>
36 * <p>It also creates a specialized instance of {@link Ext.dd.DropZone} which cooperates with other DropZones which are members of the same
37 * ddGroup which processes such data objects.</p>
38 * <p>Adding this plugin to a view means that two new events may be fired from the client TreeView, <code>{@link #event-beforedrop beforedrop}</code> and
39 * <code>{@link #event-drop drop}</code></p>
41 Ext.define('Ext.tree.plugin.TreeViewDragDrop', {
42 extend: 'Ext.AbstractPlugin',
43 alias: 'plugin.treeviewdragdrop',
46 'Ext.tree.ViewDragZone',
47 'Ext.tree.ViewDropZone'
50 <span id='Ext-tree-ViewDDPlugin-event-beforedrop'> /**
51 </span> * @event beforedrop
52 * <p><b>This event is fired through the TreeView. Add listeners to the TreeView object</b></p>
53 * <p>Fired when a drop gesture has been triggered by a mouseup event in a valid drop position in the TreeView.
54 * @param {HtmlElement} node The TreeView node <b>if any</b> over which the mouse was positioned.</p>
55 * <p>Returning <code>false</code> to this event signals that the drop gesture was invalid, and if the drag proxy
56 * will animate back to the point from which the drag began.</p>
57 * <p>Returning <code>0</code> To this event signals that the data transfer operation should not take place, but
58 * that the gesture was valid, and that the repair operation should not take place.</p>
59 * <p>Any other return value continues with the data transfer operation.</p>
60 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone DragZone}'s
61 * {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:<ul>
62 * <li>copy : Boolean
63 * <div class="sub-desc">The value of the TreeView's <code>copy</code> property, or <code>true</code> if the TreeView was configured
64 * with <code>allowCopy: true</code> and the control key was pressed when the drag operation was begun</div></li>
65 * <li>view : TreeView
66 * <div class="sub-desc">The source TreeView from which the drag originated.</div></li>
67 * <li>ddel : HtmlElement
68 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
69 * <li>item : HtmlElement
70 * <div class="sub-desc">The TreeView node upon which the mousedown event was registered.</div></li>
71 * <li>records : Array
72 * <div class="sub-desc">An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source TreeView.</div></li>
74 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
75 * @param {String} dropPosition <code>"before"</code>, <code>"after"</code> or <code>"append"</code> depending on whether the mouse is above or below the midline of the node,
76 * or the node is a branch node which accepts new child nodes.
77 * @param {Function} dropFunction <p>A function to call to complete the data transfer operation and either move or copy Model instances from the source
78 * View's Store to the destination View's Store.</p>
79 * <p>This is useful when you want to perform some kind of asynchronous processing before confirming
80 * the drop, such as an {@link Ext.window.MessageBox#confirm confirm} call, or an Ajax request.</p>
81 * <p>Return <code>0</code> from this event handler, and call the <code>dropFunction</code> at any time to perform the data transfer.</p>
84 <span id='Ext-tree-ViewDDPlugin-event-drop'> /**
86 * <b>This event is fired through the TreeView. Add listeners to the TreeView object</b>
87 * Fired when a drop operation has been completed and the data has been moved or copied.
88 * @param {HtmlElement} node The TreeView node <b>if any</b> over which the mouse was positioned.
89 * @param {Object} data The data object gathered at mousedown time by the cooperating {@link Ext.dd.DragZone DragZone}'s
90 * {@link Ext.dd.DragZone#getDragData getDragData} method it contains the following properties:<ul>
91 * <li>copy : Boolean
92 * <div class="sub-desc">The value of the TreeView's <code>copy</code> property, or <code>true</code> if the TreeView was configured
93 * with <code>allowCopy: true</code> and the control key was pressed when the drag operation was begun</div></li>
94 * <li>view : TreeView
95 * <div class="sub-desc">The source TreeView from which the drag originated.</div></li>
96 * <li>ddel : HtmlElement
97 * <div class="sub-desc">The drag proxy element which moves with the mouse</div></li>
98 * <li>item : HtmlElement
99 * <div class="sub-desc">The TreeView node upon which the mousedown event was registered.</div></li>
100 * <li>records : Array
101 * <div class="sub-desc">An Array of {@link Ext.data.Model Model}s representing the selected data being dragged from the source TreeView.</div></li>
103 * @param {Ext.data.Model} overModel The Model over which the drop gesture took place.
104 * @param {String} dropPosition <code>"before"</code>, <code>"after"</code> or <code>"append"</code> depending on whether the mouse is above or below the midline of the node,
105 * or the node is a branch node which accepts new child nodes.
108 dragText : '{0} selected node{1}',
110 <span id='Ext-tree-ViewDDPlugin-cfg-allowParentInsert'> /**
111 </span> * @cfg {Boolean} allowParentInsert
112 * Allow inserting a dragged node between an expanded parent node and its first child that will become a
113 * sibling of the parent when dropped (defaults to false)
115 allowParentInserts: false,
117 <span id='Ext-tree-ViewDDPlugin-cfg-allowContainerDrop'> /**
118 </span> * @cfg {String} allowContainerDrop
119 * True if drops on the tree container (outside of a specific tree node) are allowed (defaults to false)
121 allowContainerDrops: false,
123 <span id='Ext-tree-ViewDDPlugin-cfg-appendOnly'> /**
124 </span> * @cfg {String} appendOnly
125 * True if the tree should only allow append drops (use for trees which are sorted, defaults to false)
129 <span id='Ext-tree-ViewDDPlugin-cfg-ddGroup'> /**
130 </span> * @cfg {String} ddGroup
131 * A named drag drop group to which this object belongs. If a group is specified, then both the DragZones and DropZone
132 * used by this plugin will only interact with other drag drop objects in the same group (defaults to 'TreeDD').
134 ddGroup : "TreeDD",
136 <span id='Ext-tree-ViewDDPlugin-cfg-dragGroup'> /**
137 </span> * @cfg {String} dragGroup
138 * <p>The ddGroup to which the DragZone will belong.</p>
139 * <p>This defines which other DropZones the DragZone will interact with. Drag/DropZones only interact with other Drag/DropZones
140 * which are members of the same ddGroup.</p>
143 <span id='Ext-tree-ViewDDPlugin-cfg-dropGroup'> /**
144 </span> * @cfg {String} dropGroup
145 * <p>The ddGroup to which the DropZone will belong.</p>
146 * <p>This defines which other DragZones the DropZone will interact with. Drag/DropZones only interact with other Drag/DropZones
147 * which are members of the same ddGroup.</p>
150 <span id='Ext-tree-ViewDDPlugin-cfg-expandDelay'> /**
151 </span> * @cfg {String} expandDelay
152 * The delay in milliseconds to wait before expanding a target tree node while dragging a droppable node
153 * over the target (defaults to 1000)
157 <span id='Ext-tree-ViewDDPlugin-cfg-enableDrop'> /**
158 </span> * @cfg {Boolean} enableDrop
159 * <p>Defaults to <code>true</code></p>
160 * <p>Set to <code>false</code> to disallow the View from accepting drop gestures</p>
164 <span id='Ext-tree-ViewDDPlugin-cfg-enableDrag'> /**
165 </span> * @cfg {Boolean} enableDrag
166 * <p>Defaults to <code>true</code></p>
167 * <p>Set to <code>false</code> to disallow dragging items from the View </p>
171 <span id='Ext-tree-ViewDDPlugin-cfg-nodeHighlightColor'> /**
172 </span> * @cfg {String} nodeHighlightColor The color to use when visually highlighting the dragged
173 * or dropped node (defaults to 'c3daf9' - light blue). The color must be a 6 digit hex value, without
174 * a preceding '#'. See also {@link #nodeHighlightOnDrop} and {@link #nodeHighlightOnRepair}.
176 nodeHighlightColor: 'c3daf9',
178 <span id='Ext-tree-ViewDDPlugin-cfg-nodeHighlightOnDrop'> /**
179 </span> * @cfg {Boolean} nodeHighlightOnDrop Whether or not to highlight any nodes after they are
180 * successfully dropped on their target. Defaults to the value of `Ext.enableFx`.
181 * See also {@link #nodeHighlightColor} and {@link #nodeHighlightOnRepair}.
184 nodeHighlightOnDrop: Ext.enableFx,
186 <span id='Ext-tree-ViewDDPlugin-cfg-nodeHighlightOnRepair'> /**
187 </span> * @cfg {Boolean} nodeHighlightOnRepair Whether or not to highlight any nodes after they are
188 * repaired from an unsuccessful drag/drop. Defaults to the value of `Ext.enableFx`.
189 * See also {@link #nodeHighlightColor} and {@link #nodeHighlightOnDrop}.
192 nodeHighlightOnRepair: Ext.enableFx,
194 init : function(view) {
195 view.on('render', this.onViewRender, this, {single: true});
198 <span id='Ext-tree-ViewDDPlugin-method-destroy'> /**
200 * AbstractComponent calls destroy on all its plugins at destroy time.
202 destroy: function() {
203 Ext.destroy(this.dragZone, this.dropZone);
206 onViewRender : function(view) {
210 me.dragZone = Ext.create('Ext.tree.ViewDragZone', {
212 ddGroup: me.dragGroup || me.ddGroup,
213 dragText: me.dragText,
214 repairHighlightColor: me.nodeHighlightColor,
215 repairHighlight: me.nodeHighlightOnRepair
220 me.dropZone = Ext.create('Ext.tree.ViewDropZone', {
222 ddGroup: me.dropGroup || me.ddGroup,
223 allowContainerDrops: me.allowContainerDrops,
224 appendOnly: me.appendOnly,
225 allowParentInserts: me.allowParentInserts,
226 expandDelay: me.expandDelay,
227 dropHighlightColor: me.nodeHighlightColor,
228 dropHighlight: me.nodeHighlightOnDrop