]>
git.proxmox.com Git - extjs.git/blob - extjs/packages/ux/classic/src/DataView/DragSelector.js
4 Ext
.define('Ext.ux.DataView.DragSelector', {
5 requires
: ['Ext.dd.DragTracker', 'Ext.util.Region'],
8 * Initializes the plugin by setting up the drag tracker
10 init: function(dataview
) {
14 * The DataView bound to this instance
16 this.dataview
= dataview
;
17 dataview
.mon(dataview
, {
18 beforecontainerclick
: this.cancelClick
,
30 * Called when the attached DataView is rendered. This sets up the DragTracker instance that will be used
31 * to created a dragged selection area
33 onRender: function() {
36 * @type Ext.dd.DragTracker
37 * The DragTracker attached to this instance. Note that the 4 on* functions are called in the scope of the
38 * DragTracker ('this' refers to the DragTracker inside those functions), so we pass a reference to the
39 * DragSelector so that we can call this class's functions.
41 this.tracker
= Ext
.create('Ext.dd.DragTracker', {
42 dataview
: this.dataview
,
45 onBeforeStart
: this.onBeforeStart
,
46 onStart
: this.onStart
,
52 * @property dragRegion
53 * @type Ext.util.Region
54 * Represents the region currently dragged out by the user. This is used to figure out which dataview nodes are
55 * in the selected area and to set the size of the Proxy element used to highlight the current drag area
57 this.dragRegion
= Ext
.create('Ext.util.Region');
62 * Listener attached to the DragTracker's onBeforeStart event. Returns false if the drag didn't start within the
65 onBeforeStart: function(e
) {
66 return e
.target
== this.dataview
.getEl().dom
;
71 * Listener attached to the DragTracker's onStart event. Cancel's the DataView's containerclick event from firing
72 * and sets the start co-ordinates of the Proxy element. Clears any existing DataView selection
73 * @param {Ext.event.Event} e The click event
75 onStart: function(e
) {
76 var dragSelector
= this.dragSelector
,
77 dataview
= this.dataview
;
79 // Flag which controls whether the cancelClick method vetoes the processing of the DataView's containerclick event.
80 // On IE (where else), this needs to remain set for a millisecond after mouseup because even though the mouse has
81 // moved, the mouseup will still trigger a click event.
84 //here we reset and show the selection proxy element and cache the regions each item in the dataview take up
85 dragSelector
.fillRegions();
86 dragSelector
.getProxy().show();
87 dataview
.getSelectionModel().deselectAll();
92 * Reusable handler that's used to cancel the container click event when dragging on the dataview. See onStart for
95 cancelClick: function() {
96 return !this.tracker
.dragging
;
101 * Listener attached to the DragTracker's onDrag event. Figures out how large the drag selection area should be and
102 * updates the proxy element's size to match. Then iterates over all of the rendered items and marks them selected
103 * if the drag region touches them
104 * @param {Ext.event.Event} e The drag event
106 onDrag: function(e
) {
107 var dragSelector
= this.dragSelector
,
108 selModel
= dragSelector
.dataview
.getSelectionModel(),
109 dragRegion
= dragSelector
.dragRegion
,
110 bodyRegion
= dragSelector
.bodyRegion
,
111 proxy
= dragSelector
.getProxy(),
112 regions
= dragSelector
.regions
,
113 length
= regions
.length
,
115 startXY
= this.startXY
,
116 currentXY
= this.getXY(),
117 minX
= Math
.min(startXY
[0], currentXY
[0]),
118 minY
= Math
.min(startXY
[1], currentXY
[1]),
119 width
= Math
.abs(startXY
[0] - currentXY
[0]),
120 height
= Math
.abs(startXY
[1] - currentXY
[1]),
123 Ext
.apply(dragRegion
, {
127 bottom
: minY
+ height
130 dragRegion
.constrainTo(bodyRegion
);
131 proxy
.setBox(dragRegion
);
133 for (i
= 0; i
< length
; i
++) {
135 selected
= dragRegion
.intersect(region
);
138 selModel
.select(i
, true);
140 selModel
.deselect(i
);
148 * Listener attached to the DragTracker's onEnd event. This is a delayed function which executes 1
149 * millisecond after it has been called. This is because the dragging flag must remain active to cancel
150 * the containerclick event which the mouseup event will trigger.
151 * @param {Ext.event.Event} e The event object
153 onEnd
: Ext
.Function
.createDelayed(function(e
) {
154 var dataview
= this.dataview
,
155 selModel
= dataview
.getSelectionModel(),
156 dragSelector
= this.dragSelector
;
158 this.dragging
= false;
159 dragSelector
.getProxy().hide();
164 * Creates a Proxy element that will be used to highlight the drag selection region
165 * @return {Ext.Element} The Proxy element
167 getProxy: function() {
169 this.proxy
= this.dataview
.getEl().createChild({
171 cls
: 'x-view-selector'
179 * Gets the region taken up by each rendered node in the DataView. We use these regions to figure out which nodes
180 * to select based on the selector region the user has dragged out
182 fillRegions: function() {
183 var dataview
= this.dataview
,
184 regions
= this.regions
= [];
186 dataview
.all
.each(function(node
) {
187 regions
.push(node
.getRegion());
189 this.bodyRegion
= dataview
.getEl().getRegion();