Roo/CalendarPanel.js
[roojs1] / Roo / CalendarPanel.js
1 /*
2  * - LGPL
3  *
4  * based on jquery fullcalendar
5  * 
6  */
7
8
9 /**
10  * @class Roo.Calendar
11  * @extends Roo.Component
12  * Bootstrap Calendar class
13     
14  * @constructor
15  * Create a new Container
16  * @param {Object} config The config object
17  */
18
19 Roo.CalendarPanel = function(config){
20     
21     Roo.log("cal panel ctr");
22   
23     this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
24         {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
25         
26     //this.wrapper.dom.appendChild(grid.getGridEl().dom);
27     
28     Roo.CalendarPanel.superclass.constructor.call(this, this.wrapper, config);
29     
30     Roo.log(this.el);
31     
32     if(this.toolbar){
33         this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
34     }
35     // xtype created footer. - not sure if will work as we normally have to render first..
36     if (this.footer && !this.footer.el && this.footer.xtype) {
37         
38         //this.footer.container = this.grid.getView().getFooterPanel(true);
39         //this.footer.dataSource = this.grid.dataSource;
40         //this.footer = Roo.factory(this.footer, Roo);
41         
42     }
43     this.view = new Roo.calendar.View(config);
44     
45     
46     this.on('activate', function()
47     {
48         Roo.log('activate');
49          
50         //console.log('render tree');
51         this.render();
52     },this);
53     
54     this.addEvents({
55         /**
56              * @event select
57              * Fires when a date is selected
58              * @param {DatePicker} this
59              * @param {Date} date The selected date
60              */
61         'select': true,
62         /**
63              * @event monthchange
64              * Fires when the displayed month changes 
65              * @param {DatePicker} this
66              * @param {Date} date The selected month
67              */
68         'monthchange': true,
69         /**
70              * @event evententer
71              * Fires when mouse over an event
72              * @param {Calendar} this
73              * @param {event} Event
74              */
75         'evententer': true,
76         /**
77              * @event eventleave
78              * Fires when the mouse leaves an
79              * @param {Calendar} this
80              * @param {event}
81              */
82         'eventleave': true,
83         /**
84              * @event eventclick
85              * Fires when the mouse click an
86              * @param {Calendar} this
87              * @param {event}
88              */
89         'eventclick': true,
90         /**
91              * @event rendered
92              * Fires when the grid is rendered
93              * @param {Calendar} this
94             
95              */
96         'rendered': true
97         
98         
99     });
100     
101     //this.grid = grid;
102     //this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
103 };
104
105
106 Roo.extend(Roo.CalendarPanel, Roo.ContentPanel, {
107     
108     startDay : 0,
109     
110     getId : function(){
111         return this.id;
112     },
113     /*
114     setSize : function(width, height){
115         if(!this.ignoreResize(width, height)){
116             var grid = this.grid;
117             var size = this.adjustForComponents(width, height);
118             grid.getGridEl().setSize(size.width, size.height);
119             grid.autoSize();
120         }
121     },
122     
123     beforeSlide : function(){
124         this.grid.getView().scroller.clip();
125     },
126     
127     afterSlide : function(){
128         this.grid.getView().scroller.unclip();
129     },
130     */
131     destroy : function(){
132       //  this.grid.destroy();
133        // delete this.grid;
134         Roo.GridPanel.superclass.destroy.call(this);
135          
136     },
137     render : function()
138     {
139         this.onRender(this.el, false)
140     },
141     
142     onRender : function(ct, position)
143     {
144         if (this.rendered) {
145             return;
146         }
147         this.rendered = true;
148         
149         Roo.log("render calendar");
150         
151         //Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
152         
153         
154         var cfg = Roo.apply({},  this.getAutoCreate());
155         cfg.id = Roo.id();
156         
157         // fill in the extra attributes 
158         if (this.xattr && typeof(this.xattr) =='object') {
159             for (var i in this.xattr) {
160                 cfg[i] = this.xattr[i];
161             }
162         }
163         
164         if(this.dataId){
165             cfg.dataId = this.dataId;
166         }
167         
168         if (this.cls) {
169             cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
170         }
171         
172         if (this.style) { // fixme needs to support more complex style data.
173             cfg.style = this.style;
174         }
175         
176         if(this.name){
177             cfg.name = this.name;
178         }
179         
180         this.el = ct.createChild(cfg, position);
181         
182         if(this.tabIndex !== undefined){
183             this.el.dom.setAttribute('tabIndex', this.tabIndex);
184         }
185         
186         
187         this.initEvents();
188         this.fireEvent('rendered');
189     }
190     
191     
192     
193     
194 });
195
196
197
198 Roo.each([
199     'getAutoCreate',
200     'initEvents',
201     'resize',
202     'showPrevMonth',
203     'showToday',
204     'showNextMonth',
205     'showPrevYear',
206     'showNextYear',
207     'update',
208     'findCell',
209     'findCells',
210     'findBestRow',
211     'addItem',
212     'clearEvents',
213     'renderEvents',
214     'onEventEnter',
215     'onEventLeave',
216     'onEventClick',
217     'onMonthChange',
218     'onLoad'
219
220     
221 ], function(p) {
222     Roo.log('add' + p);
223     Roo.CalendarPanel.prototype[p] = Roo.bootstrap.Calendar.prototype[p];
224  
225 });