3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 // This is a support class used internally by the Grid components
9 Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
12 constructor : function(grid, hd, hd2){
14 this.view = grid.getView();
15 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
16 Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
18 this.setHandleElId(Ext.id(hd));
19 this.setOuterHandleElId(Ext.id(hd2));
24 getDragData : function(e){
25 var t = Ext.lib.Event.getTarget(e),
26 h = this.view.findHeaderCell(t);
28 return {ddel: h.firstChild, header:h};
33 onInitDrag : function(e){
34 // keep the value here so we can restore it;
35 this.dragHeadersDisabled = this.view.headersDisabled;
36 this.view.headersDisabled = true;
37 var clone = this.dragData.ddel.cloneNode(true);
39 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
40 this.proxy.update(clone);
44 afterValidDrop : function(){
48 afterInvalidDrop : function(){
52 completeDrop: function(){
54 disabled = this.dragHeadersDisabled;
55 setTimeout(function(){
56 v.headersDisabled = disabled;
62 // This is a support class used internally by the Grid components
63 Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
64 proxyOffsets : [-4, -9],
67 constructor : function(grid, hd, hd2){
69 this.view = grid.getView();
70 // split the proxies so they don't interfere with mouse events
71 this.proxyTop = Ext.DomHelper.append(document.body, {
72 cls:"col-move-top", html:" "
74 this.proxyBottom = Ext.DomHelper.append(document.body, {
75 cls:"col-move-bottom", html:" "
77 this.proxyTop.hide = this.proxyBottom.hide = function(){
78 this.setLeftTop(-100,-100);
79 this.setStyle("visibility", "hidden");
81 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
82 // temporarily disabled
83 //Ext.dd.ScrollManager.register(this.view.scroller.dom);
84 Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
87 getTargetFromEvent : function(e){
88 var t = Ext.lib.Event.getTarget(e),
89 cindex = this.view.findCellIndex(t);
91 return this.view.getHeaderCell(cindex);
95 nextVisible : function(h){
96 var v = this.view, cm = this.grid.colModel;
99 if(!cm.isHidden(v.getCellIndex(h))){
107 prevVisible : function(h){
108 var v = this.view, cm = this.grid.colModel;
111 if(!cm.isHidden(v.getCellIndex(h))){
119 positionIndicator : function(h, n, e){
120 var x = Ext.lib.Event.getPageX(e),
121 r = Ext.lib.Dom.getRegion(n.firstChild),
124 py = r.top + this.proxyOffsets[1];
125 if((r.right - x) <= (r.right-r.left)/2){
126 px = r.right+this.view.borderWidth;
133 if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
137 px += this.proxyOffsets[0];
138 this.proxyTop.setLeftTop(px, py);
139 this.proxyTop.show();
140 if(!this.bottomOffset){
141 this.bottomOffset = this.view.mainHd.getHeight();
143 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
144 this.proxyBottom.show();
148 onNodeEnter : function(n, dd, e, data){
149 if(data.header != n){
150 this.positionIndicator(data.header, n, e);
154 onNodeOver : function(n, dd, e, data){
156 if(data.header != n){
157 result = this.positionIndicator(data.header, n, e);
160 this.proxyTop.hide();
161 this.proxyBottom.hide();
163 return result ? this.dropAllowed : this.dropNotAllowed;
166 onNodeOut : function(n, dd, e, data){
167 this.proxyTop.hide();
168 this.proxyBottom.hide();
171 onNodeDrop : function(n, dd, e, data){
174 var cm = this.grid.colModel,
175 x = Ext.lib.Event.getPageX(e),
176 r = Ext.lib.Dom.getRegion(n.firstChild),
177 pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before",
178 oldIndex = this.view.getCellIndex(h),
179 newIndex = this.view.getCellIndex(n);
183 if(oldIndex < newIndex){
186 cm.moveColumn(oldIndex, newIndex);
193 Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
195 constructor : function(grid, hd){
196 Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
197 this.proxy.el.addClass('x-grid3-col-dd');
200 handleMouseDown : function(e){
203 callHandleMouseDown : function(e){
204 Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);