source: trunk/web/addons/job_monarch/lib/extjs-30/src/widgets/grid/ColumnDD.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 6.0 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7// private
8// This is a support class used internally by the Grid components
9Ext.grid.HeaderDragZone = function(grid, hd, hd2){
10    this.grid = grid;
11    this.view = grid.getView();
12    this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
13    Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
14    if(hd2){
15        this.setHandleElId(Ext.id(hd));
16        this.setOuterHandleElId(Ext.id(hd2));
17    }
18    this.scroll = false;
19};
20Ext.extend(Ext.grid.HeaderDragZone, Ext.dd.DragZone, {
21    maxDragWidth: 120,
22    getDragData : function(e){
23        var t = Ext.lib.Event.getTarget(e);
24        var h = this.view.findHeaderCell(t);
25        if(h){
26            return {ddel: h.firstChild, header:h};
27        }
28        return false;
29    },
30
31    onInitDrag : function(e){
32        this.view.headersDisabled = true;
33        var clone = this.dragData.ddel.cloneNode(true);
34        clone.id = Ext.id();
35        clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
36        this.proxy.update(clone);
37        return true;
38    },
39
40    afterValidDrop : function(){
41        var v = this.view;
42        setTimeout(function(){
43            v.headersDisabled = false;
44        }, 50);
45    },
46
47    afterInvalidDrop : function(){
48        var v = this.view;
49        setTimeout(function(){
50            v.headersDisabled = false;
51        }, 50);
52    }
53});
54
55// private
56// This is a support class used internally by the Grid components
57Ext.grid.HeaderDropZone = function(grid, hd, hd2){
58    this.grid = grid;
59    this.view = grid.getView();
60    // split the proxies so they don't interfere with mouse events
61    this.proxyTop = Ext.DomHelper.append(document.body, {
62        cls:"col-move-top", html:" "
63    }, true);
64    this.proxyBottom = Ext.DomHelper.append(document.body, {
65        cls:"col-move-bottom", html:" "
66    }, true);
67    this.proxyTop.hide = this.proxyBottom.hide = function(){
68        this.setLeftTop(-100,-100);
69        this.setStyle("visibility", "hidden");
70    };
71    this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
72    // temporarily disabled
73    //Ext.dd.ScrollManager.register(this.view.scroller.dom);
74    Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
75};
76Ext.extend(Ext.grid.HeaderDropZone, Ext.dd.DropZone, {
77    proxyOffsets : [-4, -9],
78    fly: Ext.Element.fly,
79
80    getTargetFromEvent : function(e){
81        var t = Ext.lib.Event.getTarget(e);
82        var cindex = this.view.findCellIndex(t);
83        if(cindex !== false){
84            return this.view.getHeaderCell(cindex);
85        }
86    },
87
88    nextVisible : function(h){
89        var v = this.view, cm = this.grid.colModel;
90        h = h.nextSibling;
91        while(h){
92            if(!cm.isHidden(v.getCellIndex(h))){
93                return h;
94            }
95            h = h.nextSibling;
96        }
97        return null;
98    },
99
100    prevVisible : function(h){
101        var v = this.view, cm = this.grid.colModel;
102        h = h.prevSibling;
103        while(h){
104            if(!cm.isHidden(v.getCellIndex(h))){
105                return h;
106            }
107            h = h.prevSibling;
108        }
109        return null;
110    },
111
112    positionIndicator : function(h, n, e){
113        var x = Ext.lib.Event.getPageX(e);
114        var r = Ext.lib.Dom.getRegion(n.firstChild);
115        var px, pt, py = r.top + this.proxyOffsets[1];
116        if((r.right - x) <= (r.right-r.left)/2){
117            px = r.right+this.view.borderWidth;
118            pt = "after";
119        }else{
120            px = r.left;
121            pt = "before";
122        }
123
124        if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
125            return false;
126        }
127
128        px +=  this.proxyOffsets[0];
129        this.proxyTop.setLeftTop(px, py);
130        this.proxyTop.show();
131        if(!this.bottomOffset){
132            this.bottomOffset = this.view.mainHd.getHeight();
133        }
134        this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
135        this.proxyBottom.show();
136        return pt;
137    },
138
139    onNodeEnter : function(n, dd, e, data){
140        if(data.header != n){
141            this.positionIndicator(data.header, n, e);
142        }
143    },
144
145    onNodeOver : function(n, dd, e, data){
146        var result = false;
147        if(data.header != n){
148            result = this.positionIndicator(data.header, n, e);
149        }
150        if(!result){
151            this.proxyTop.hide();
152            this.proxyBottom.hide();
153        }
154        return result ? this.dropAllowed : this.dropNotAllowed;
155    },
156
157    onNodeOut : function(n, dd, e, data){
158        this.proxyTop.hide();
159        this.proxyBottom.hide();
160    },
161
162    onNodeDrop : function(n, dd, e, data){
163        var h = data.header;
164        if(h != n){
165            var cm = this.grid.colModel;
166            var x = Ext.lib.Event.getPageX(e);
167            var r = Ext.lib.Dom.getRegion(n.firstChild);
168            var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
169            var oldIndex = this.view.getCellIndex(h);
170            var newIndex = this.view.getCellIndex(n);
171            if(pt == "after"){
172                newIndex++;
173            }
174            if(oldIndex < newIndex){
175                newIndex--;
176            }
177            cm.moveColumn(oldIndex, newIndex);
178            this.grid.fireEvent("columnmove", oldIndex, newIndex);
179            return true;
180        }
181        return false;
182    }
183});
184
185
186Ext.grid.GridView.ColumnDragZone = function(grid, hd){
187    Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
188    this.proxy.el.addClass('x-grid3-col-dd');
189};
190
191Ext.extend(Ext.grid.GridView.ColumnDragZone, Ext.grid.HeaderDragZone, {
192    handleMouseDown : function(e){
193
194    },
195
196    callHandleMouseDown : function(e){
197        Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
198    }
199});
Note: See TracBrowser for help on using the repository browser.