try and get ctrl-enter to add a clear all
[roojs1] / Roo / grid / HeaderDropZone.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11 // private
12 // This is a support class used internally by the Grid components
13 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
14     this.grid = grid;
15     this.view = grid.getView();
16     // split the proxies so they don't interfere with mouse events
17     this.proxyTop = Roo.DomHelper.append(document.body, {
18         cls:"col-move-top", html:"&#160;"
19     }, true);
20     this.proxyBottom = Roo.DomHelper.append(document.body, {
21         cls:"col-move-bottom", html:"&#160;"
22     }, true);
23     this.proxyTop.hide = this.proxyBottom.hide = function(){
24         this.setLeftTop(-100,-100);
25         this.setStyle("visibility", "hidden");
26     };
27     this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
28     // temporarily disabled
29     //Roo.dd.ScrollManager.register(this.view.scroller.dom);
30     Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
31 };
32 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
33     proxyOffsets : [-4, -9],
34     fly: Roo.Element.fly,
35
36     getTargetFromEvent : function(e){
37         var t = Roo.lib.Event.getTarget(e);
38         var cindex = this.view.findCellIndex(t);
39         if(cindex !== false){
40             return this.view.getHeaderCell(cindex);
41         }
42         return null;
43     },
44
45     nextVisible : function(h){
46         var v = this.view, cm = this.grid.colModel;
47         h = h.nextSibling;
48         while(h){
49             if(!cm.isHidden(v.getCellIndex(h))){
50                 return h;
51             }
52             h = h.nextSibling;
53         }
54         return null;
55     },
56
57     prevVisible : function(h){
58         var v = this.view, cm = this.grid.colModel;
59         h = h.prevSibling;
60         while(h){
61             if(!cm.isHidden(v.getCellIndex(h))){
62                 return h;
63             }
64             h = h.prevSibling;
65         }
66         return null;
67     },
68
69     positionIndicator : function(h, n, e){
70         var x = Roo.lib.Event.getPageX(e);
71         var r = Roo.lib.Dom.getRegion(n.firstChild);
72         var px, pt, py = r.top + this.proxyOffsets[1];
73         if((r.right - x) <= (r.right-r.left)/2){
74             px = r.right+this.view.borderWidth;
75             pt = "after";
76         }else{
77             px = r.left;
78             pt = "before";
79         }
80         var oldIndex = this.view.getCellIndex(h);
81         var newIndex = this.view.getCellIndex(n);
82
83         if(this.grid.colModel.isFixed(newIndex)){
84             return false;
85         }
86
87         var locked = this.grid.colModel.isLocked(newIndex);
88
89         if(pt == "after"){
90             newIndex++;
91         }
92         if(oldIndex < newIndex){
93             newIndex--;
94         }
95         if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
96             return false;
97         }
98         px +=  this.proxyOffsets[0];
99         this.proxyTop.setLeftTop(px, py);
100         this.proxyTop.show();
101         if(!this.bottomOffset){
102             this.bottomOffset = this.view.mainHd.getHeight();
103         }
104         this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
105         this.proxyBottom.show();
106         return pt;
107     },
108
109     onNodeEnter : function(n, dd, e, data){
110         if(data.header != n){
111             this.positionIndicator(data.header, n, e);
112         }
113     },
114
115     onNodeOver : function(n, dd, e, data){
116         var result = false;
117         if(data.header != n){
118             result = this.positionIndicator(data.header, n, e);
119         }
120         if(!result){
121             this.proxyTop.hide();
122             this.proxyBottom.hide();
123         }
124         return result ? this.dropAllowed : this.dropNotAllowed;
125     },
126
127     onNodeOut : function(n, dd, e, data){
128         this.proxyTop.hide();
129         this.proxyBottom.hide();
130     },
131
132     onNodeDrop : function(n, dd, e, data){
133         var h = data.header;
134         if(h != n){
135             var cm = this.grid.colModel;
136             var x = Roo.lib.Event.getPageX(e);
137             var r = Roo.lib.Dom.getRegion(n.firstChild);
138             var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
139             var oldIndex = this.view.getCellIndex(h);
140             var newIndex = this.view.getCellIndex(n);
141             var locked = cm.isLocked(newIndex);
142             if(pt == "after"){
143                 newIndex++;
144             }
145             if(oldIndex < newIndex){
146                 newIndex--;
147             }
148             if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
149                 return false;
150             }
151             cm.setLocked(oldIndex, locked, true);
152             cm.moveColumn(oldIndex, newIndex);
153             this.grid.fireEvent("columnmove", oldIndex, newIndex);
154             return true;
155         }
156         return false;
157     }
158 });