DropZone2.html
11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-grid-header-DropZone'>/**
</span> * @private
*/
Ext.define('Ext.grid.header.DropZone', {
extend: 'Ext.dd.DropZone',
colHeaderCls: Ext.baseCSSPrefix + 'column-header',
proxyOffsets: [-4, -9],
constructor: function(headerCt){
this.headerCt = headerCt;
this.ddGroup = this.getDDGroup();
this.callParent([headerCt.el]);
},
getDDGroup: function() {
return 'header-dd-zone-' + this.headerCt.up('[scrollerOwner]').id;
},
getTargetFromEvent : function(e){
return e.getTarget('.' + this.colHeaderCls);
},
getTopIndicator: function() {
if (!this.topIndicator) {
this.topIndicator = Ext.DomHelper.append(Ext.getBody(), {
cls: "col-move-top",
html: "&#160;"
}, true);
}
return this.topIndicator;
},
getBottomIndicator: function() {
if (!this.bottomIndicator) {
this.bottomIndicator = Ext.DomHelper.append(Ext.getBody(), {
cls: "col-move-bottom",
html: "&#160;"
}, true);
}
return this.bottomIndicator;
},
getLocation: function(e, t) {
var x = e.getXY()[0],
region = Ext.fly(t).getRegion(),
pos, header;
if ((region.right - x) <= (region.right - region.left) / 2) {
pos = "after";
} else {
pos = "before";
}
return {
pos: pos,
header: Ext.getCmp(t.id),
node: t
};
},
positionIndicator: function(draggedHeader, node, e){
var location = this.getLocation(e, node),
header = location.header,
pos = location.pos,
nextHd = draggedHeader.nextSibling('gridcolumn:not([hidden])'),
prevHd = draggedHeader.previousSibling('gridcolumn:not([hidden])'),
topIndicator, bottomIndicator, topAnchor, bottomAnchor,
topXY, bottomXY, headerCtEl, minX, maxX,
allDropZones, ln, i, dropZone;
// Cannot drag beyond non-draggable start column
if (!header.draggable && header.getIndex() === 0) {
return false;
}
this.lastLocation = location;
if ((draggedHeader !== header) &&
((pos === "before" && nextHd !== header) ||
(pos === "after" && prevHd !== header)) &&
!header.isDescendantOf(draggedHeader)) {
// As we move in between different DropZones that are in the same
// group (such as the case when in a locked grid), invalidateDrop
// on the other dropZones.
allDropZones = Ext.dd.DragDropManager.getRelated(this);
ln = allDropZones.length;
i = 0;
for (; i < ln; i++) {
dropZone = allDropZones[i];
if (dropZone !== this && dropZone.invalidateDrop) {
dropZone.invalidateDrop();
}
}
this.valid = true;
topIndicator = this.getTopIndicator();
bottomIndicator = this.getBottomIndicator();
if (pos === 'before') {
topAnchor = 'tl';
bottomAnchor = 'bl';
} else {
topAnchor = 'tr';
bottomAnchor = 'br';
}
topXY = header.el.getAnchorXY(topAnchor);
bottomXY = header.el.getAnchorXY(bottomAnchor);
// constrain the indicators to the viewable section
headerCtEl = this.headerCt.el;
minX = headerCtEl.getLeft();
maxX = headerCtEl.getRight();
topXY[0] = Ext.Number.constrain(topXY[0], minX, maxX);
bottomXY[0] = Ext.Number.constrain(bottomXY[0], minX, maxX);
// adjust by offsets, this is to center the arrows so that they point
// at the split point
topXY[0] -= 4;
topXY[1] -= 9;
bottomXY[0] -= 4;
// position and show indicators
topIndicator.setXY(topXY);
bottomIndicator.setXY(bottomXY);
topIndicator.show();
bottomIndicator.show();
// invalidate drop operation and hide indicators
} else {
this.invalidateDrop();
}
},
invalidateDrop: function() {
this.valid = false;
this.hideIndicators();
},
onNodeOver: function(node, dragZone, e, data) {
var me = this,
header = me.headerCt,
doPosition = true,
from = data.header,
to;
if (data.header.el.dom === node) {
doPosition = false;
} else {
to = me.getLocation(e, node).header;
doPosition = (from.ownerCt === to.ownerCt) || (!from.ownerCt.sealed && !to.ownerCt.sealed);
}
if (doPosition) {
me.positionIndicator(data.header, node, e);
} else {
me.valid = false;
}
return me.valid ? me.dropAllowed : me.dropNotAllowed;
},
hideIndicators: function() {
this.getTopIndicator().hide();
this.getBottomIndicator().hide();
},
onNodeOut: function() {
this.hideIndicators();
},
onNodeDrop: function(node, dragZone, e, data) {
if (this.valid) {
var dragHeader = data.header,
lastLocation = this.lastLocation,
targetHeader = lastLocation.header,
fromCt = dragHeader.ownerCt,
fromHeader = dragHeader.up('headercontainer:not(gridcolumn)'),
localFromIdx = fromCt.items.indexOf(dragHeader), // Container.items is a MixedCollection
toCt = targetHeader.ownerCt,
toHeader = targetHeader.up('headercontainer:not(gridcolumn)'),
localToIdx = toCt.items.indexOf(targetHeader),
headerCt = this.headerCt,
fromIdx = headerCt.getHeaderIndex(dragHeader),
colsToMove = dragHeader.isGroupHeader ? dragHeader.query(':not([isGroupHeader])').length : 1,
toIdx = headerCt.getHeaderIndex(targetHeader),
groupCt,
scrollerOwner;
// Drop position is to the right of the targetHeader, increment the toIdx correctly
if (lastLocation.pos === 'after') {
localToIdx++;
toIdx += targetHeader.isGroupHeader ? targetHeader.query(':not([isGroupHeader])').length : 1;
}
// If we are dragging in between two HeaderContainers that have had the lockable
// mixin injected we will lock/unlock headers in between sections, and then continue
// with another execution of onNodeDrop to ensure the header is dropped into the correct group
if (fromHeader !== toHeader && fromHeader.lockableInjected && toHeader.lockableInjected && toHeader.lockedCt) {
scrollerOwner = fromCt.up('[scrollerOwner]');
scrollerOwner.lock(dragHeader, localToIdx);
// Now that the header has been transferred into the correct HeaderContainer, recurse, and continue the drop operation with the same dragData
this.onNodeDrop(node, dragZone, e, data);
} else if (fromHeader !== toHeader && fromHeader.lockableInjected && toHeader.lockableInjected && fromHeader.lockedCt) {
scrollerOwner = fromCt.up('[scrollerOwner]');
scrollerOwner.unlock(dragHeader, localToIdx);
// Now that the header has been transferred into the correct HeaderContainer, recurse, and continue the drop operation with the same dragData
this.onNodeDrop(node, dragZone, e, data);
}
// This is a drop within the same HeaderContainer.
else {
this.invalidateDrop();
// If dragging rightwards, then after removal, the insertion index will be less when moving
// within the same container.
if ((fromCt === toCt) && (localToIdx > localFromIdx)) {
// Wer're dragging whole headers, so locally, the adjustment is only one
localToIdx -= 1;
}
// Suspend layouts while we sort all this out.
Ext.suspendLayouts();
// Remove dragged header from where it was.
if (fromCt !== toCt) {
fromCt.remove(dragHeader, false);
// Dragged the last header out of the fromCt group... The fromCt group must die
if (fromCt.isGroupHeader) {
if (!fromCt.items.getCount()) {
groupCt = fromCt.ownerCt;
groupCt.remove(fromCt, false);
fromCt.el.dom.parentNode.removeChild(fromCt.el.dom);
}
}
}
// Move dragged header into its drop position
if (fromCt === toCt) {
toCt.move(localFromIdx, localToIdx);
} else {
toCt.insert(localToIdx, dragHeader);
}
// Group headers acquire the aggregate width of their child headers
// Therefore a child header may not flex; it must contribute a fixed width.
// But we restore the flex value when moving back into the main header container
if (toCt.isGroupHeader) {
// Adjust the width of the "to" group header only if we dragged in from somewhere else.
if (toCt !== fromCt) {
dragHeader.savedFlex = dragHeader.flex;
delete dragHeader.flex;
dragHeader.width = dragHeader.getWidth();
}
} else {
if (dragHeader.savedFlex) {
dragHeader.flex = dragHeader.savedFlex;
delete dragHeader.width;
}
}
// Refresh columns cache in case we remove an emptied group column
headerCt.purgeCache();
Ext.resumeLayouts(true);
headerCt.onHeaderMoved(dragHeader, colsToMove, fromIdx, toIdx);
// Emptied group header can only be destroyed after the header and grid have been refreshed
if (!fromCt.items.getCount()) {
fromCt.destroy();
}
}
}
}
});
</pre>
</body>
</html>