source: trunk/web/addons/job_monarch/lib/extjs/source/widgets/grid/ColumnDD.js @ 619

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

lib/:

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