Roo/grid/GridDragZone.js
[roojs1] / Roo / grid / GridDragZone.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  
12 // private
13 // This is a support class used internally by the Grid components
14 Roo.grid.GridDragZone = function(grid, config){
15     this.view = grid.getView();
16     Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
17     if(this.view.lockedBody){
18         this.setHandleElId(Roo.id(this.view.mainBody.dom));
19         this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
20     }
21     this.scroll = false;
22     this.grid = grid;
23     this.ddel = document.createElement('div');
24     this.ddel.className = 'x-grid-dd-wrap';
25 };
26
27 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
28     ddGroup : "GridDD",
29
30     getDragData : function(e){
31         var t = Roo.lib.Event.getTarget(e);
32         var rowIndex = this.view.findRowIndex(t);
33         var sm = this.grid.selModel;
34             
35         //Roo.log(rowIndex);
36         
37         if (sm.getSelectedCell) {
38             // cell selection..
39             if (!sm.getSelectedCell()) {
40                 return false;
41             }
42             if (rowIndex != sm.getSelectedCell()[0]) {
43                 return false;
44             }
45         
46         }
47         
48         var sels = sm.getSelections ? sm.getSelections() : (
49                     sm.getSelectedCell() ? [ this.grid.ds.getAt(sm.getSelectedCell()[0]) ] : []);
50         
51         // before it used to all dragging of unseleted... - now we dont do that.
52         if(sels || sels.length){
53             
54             // if editorgrid.. 
55             
56             
57             //Roo.log([ sm.getSelectedCell() ? sm.getSelectedCell()[0] : 'NO' , rowIndex ]);
58                
59             //if(!sm.isSelected(rowIndex) || e.hasModifier()){
60               //  
61             //}
62             if (e.hasModifier()){
63                 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
64             }
65             
66             Roo.log("getDragData");
67             
68             return {
69                 grid: this.grid,
70                 ddel: this.ddel,
71                 rowIndex: rowIndex,
72                 selections:sm.getSelections ? sm.getSelections() : (
73                     sm.getSelectedCell() ? [ this.grid.ds.getAt(sm.getSelectedCell()[0]) ] : []
74                 )
75             };
76         }
77         return false;
78     },
79     
80     onBeforeDrag : function(data, e)
81     {
82         // if we dont have any data to drag - then cancel.
83         return data !== false;
84     },
85     onInitDrag : function(e){
86         var data = this.dragData;
87         this.ddel.innerHTML = this.grid.getDragDropText();
88         this.proxy.update(this.ddel);
89         // fire start drag?
90     },
91
92     afterRepair : function(){
93         this.dragging = false;
94     },
95
96     getRepairXY : function(e, data){
97         return false;
98     },
99
100     onEndDrag : function(data, e){
101         // fire end drag?
102     },
103
104     onValidDrop : function(dd, e, id){
105         // fire drag drop?
106         this.hideProxy();
107     },
108
109     beforeInvalidDrop : function(e, id){
110
111     }
112 });