Roo/ViewPanel.js
[roojs1] / Roo / ViewPanel.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 /**
13  * @class Roo.grid.EditorGrid
14  * @extends Roo.grid.Grid
15  * Class for creating and editable grid.
16  * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered - 
17  * The container MUST have some type of size defined for the grid to fill. The container will be 
18  * automatically set to position relative if it isn't already.
19  * @param {Object} dataSource The data model to bind to
20  * @param {Object} colModel The column model with info about this grid's columns
21  */
22 Roo.grid.ViewPanel = function(container, config){
23     // initialize the container
24     this.container = Roo.get(container);
25     this.container.update("");
26     this.container.setStyle("overflow", "hidden");
27     this.container.addClass('x-grid-container');
28
29     this.id = this.container.id;
30
31     Roo.apply(this, config);
32     // check and correct shorthanded configs
33     if(this.ds){
34         this.dataSource = this.ds;
35         delete this.ds;
36     }
37     if(this.cm){
38         this.colModel = this.cm;
39         delete this.cm;
40     }
41     if(this.sm){
42         this.selModel = this.sm;
43         delete this.sm;
44     }
45
46     if (this.selModel) {
47         this.selModel = Roo.factory(this.selModel, Roo.grid);
48         this.sm = this.selModel;
49         this.sm.xmodule = this.xmodule || false;
50     }
51     if (typeof(this.colModel.config) == 'undefined') {
52         this.colModel = new Roo.grid.ColumnModel(this.colModel);
53         this.cm = this.colModel;
54         this.cm.xmodule = this.xmodule || false;
55     }
56     if (this.dataSource) {
57         this.dataSource= Roo.factory(this.dataSource, Roo.data);
58         this.ds = this.dataSource;
59         this.ds.xmodule = this.xmodule || false;
60          
61     }
62     
63     
64     
65     if(this.width){
66         this.container.setWidth(this.width);
67     }
68
69     if(this.height){
70         this.container.setHeight(this.height);
71     }
72     /** @private */
73         this.addEvents({
74         // raw events
75         /**
76          * @event click
77          * The raw click event for the entire grid.
78          * @param {Roo.EventObject} e
79          */
80         "click" : true,
81         /**
82          * @event dblclick
83          * The raw dblclick event for the entire grid.
84          * @param {Roo.EventObject} e
85          */
86         "dblclick" : true,
87         /**
88          * @event contextmenu
89          * The raw contextmenu event for the entire grid.
90          * @param {Roo.EventObject} e
91          */
92         "contextmenu" : true,
93         /**
94          * @event mousedown
95          * The raw mousedown event for the entire grid.
96          * @param {Roo.EventObject} e
97          */
98         "mousedown" : true,
99         /**
100          * @event mouseup
101          * The raw mouseup event for the entire grid.
102          * @param {Roo.EventObject} e
103          */
104         "mouseup" : true,
105         /**
106          * @event mouseover
107          * The raw mouseover event for the entire grid.
108          * @param {Roo.EventObject} e
109          */
110         "mouseover" : true,
111         /**
112          * @event mouseout
113          * The raw mouseout event for the entire grid.
114          * @param {Roo.EventObject} e
115          */
116         "mouseout" : true,
117         /**
118          * @event keypress
119          * The raw keypress event for the entire grid.
120          * @param {Roo.EventObject} e
121          */
122         "keypress" : true,
123         /**
124          * @event keydown
125          * The raw keydown event for the entire grid.
126          * @param {Roo.EventObject} e
127          */
128         "keydown" : true,
129
130         // custom events
131
132         /**
133          * @event cellclick
134          * Fires when a cell is clicked
135          * @param {Grid} this
136          * @param {Number} rowIndex
137          * @param {Number} columnIndex
138          * @param {Roo.EventObject} e
139          */
140         "cellclick" : true,
141         /**
142          * @event celldblclick
143          * Fires when a cell is double clicked
144          * @param {Grid} this
145          * @param {Number} rowIndex
146          * @param {Number} columnIndex
147          * @param {Roo.EventObject} e
148          */
149         "celldblclick" : true,
150         /**
151          * @event rowclick
152          * Fires when a row is clicked
153          * @param {Grid} this
154          * @param {Number} rowIndex
155          * @param {Roo.EventObject} e
156          */
157         "rowclick" : true,
158         /**
159          * @event rowdblclick
160          * Fires when a row is double clicked
161          * @param {Grid} this
162          * @param {Number} rowIndex
163          * @param {Roo.EventObject} e
164          */
165         "rowdblclick" : true,
166         /**
167          * @event headerclick
168          * Fires when a header is clicked
169          * @param {Grid} this
170          * @param {Number} columnIndex
171          * @param {Roo.EventObject} e
172          */
173         "headerclick" : true,
174         /**
175          * @event headerdblclick
176          * Fires when a header cell is double clicked
177          * @param {Grid} this
178          * @param {Number} columnIndex
179          * @param {Roo.EventObject} e
180          */
181         "headerdblclick" : true,
182         /**
183          * @event rowcontextmenu
184          * Fires when a row is right clicked
185          * @param {Grid} this
186          * @param {Number} rowIndex
187          * @param {Roo.EventObject} e
188          */
189         "rowcontextmenu" : true,
190         /**
191          * @event cellcontextmenu
192          * Fires when a cell is right clicked
193          * @param {Grid} this
194          * @param {Number} rowIndex
195          * @param {Number} cellIndex
196          * @param {Roo.EventObject} e
197          */
198          "cellcontextmenu" : true,
199         /**
200          * @event headercontextmenu
201          * Fires when a header is right clicked
202          * @param {Grid} this
203          * @param {Number} columnIndex
204          * @param {Roo.EventObject} e
205          */
206         "headercontextmenu" : true,
207         /**
208          * @event bodyscroll
209          * Fires when the body element is scrolled
210          * @param {Number} scrollLeft
211          * @param {Number} scrollTop
212          */
213         "bodyscroll" : true,
214         /**
215          * @event columnresize
216          * Fires when the user resizes a column
217          * @param {Number} columnIndex
218          * @param {Number} newSize
219          */
220         "columnresize" : true,
221         /**
222          * @event columnmove
223          * Fires when the user moves a column
224          * @param {Number} oldIndex
225          * @param {Number} newIndex
226          */
227         "columnmove" : true,
228         /**
229          * @event startdrag
230          * Fires when row(s) start being dragged
231          * @param {Grid} this
232          * @param {Roo.GridDD} dd The drag drop object
233          * @param {event} e The raw browser event
234          */
235         "startdrag" : true,
236         /**
237          * @event enddrag
238          * Fires when a drag operation is complete
239          * @param {Grid} this
240          * @param {Roo.GridDD} dd The drag drop object
241          * @param {event} e The raw browser event
242          */
243         "enddrag" : true,
244         /**
245          * @event dragdrop
246          * Fires when dragged row(s) are dropped on a valid DD target
247          * @param {Grid} this
248          * @param {Roo.GridDD} dd The drag drop object
249          * @param {String} targetId The target drag drop object
250          * @param {event} e The raw browser event
251          */
252         "dragdrop" : true,
253         /**
254          * @event dragover
255          * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
256          * @param {Grid} this
257          * @param {Roo.GridDD} dd The drag drop object
258          * @param {String} targetId The target drag drop object
259          * @param {event} e The raw browser event
260          */
261         "dragover" : true,
262         /**
263          * @event dragenter
264          *  Fires when the dragged row(s) first cross another DD target while being dragged
265          * @param {Grid} this
266          * @param {Roo.GridDD} dd The drag drop object
267          * @param {String} targetId The target drag drop object
268          * @param {event} e The raw browser event
269          */
270         "dragenter" : true,
271         /**
272          * @event dragout
273          * Fires when the dragged row(s) leave another DD target while being dragged
274          * @param {Grid} this
275          * @param {Roo.GridDD} dd The drag drop object
276          * @param {String} targetId The target drag drop object
277          * @param {event} e The raw browser event
278          */
279         "dragout" : true,
280         /**
281          * @event rowclass
282          * Fires when a row is rendered, so you can change add a style to it.
283          * @param {GridView} gridview   The grid view
284          * @param {Object} rowcfg   contains record  rowIndex and rowClass - set rowClass to add a style.
285          */
286         'rowclass' : true,
287
288         /**
289          * @event render
290          * Fires when the grid is rendered
291          * @param {Grid} grid
292          */
293         'render' : true
294     });
295
296     Roo.grid.ViewPanel.superclass.constructor.call(this);
297 };
298
299
300 Roo.extend(Roo.grid.ViewPanel, Roo.grid.Grid, {
301     
302 });