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     this.relayEvents(this.view, ["select","monthchange","evententer","eventleave","rendered"]);
101
102     //this.grid = grid;
103     //this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
104 };
105
106
107 Roo.extend(Roo.CalendarPanel, Roo.ContentPanel, {
108     
109     startDay : 0,
110     
111     getId : function(){
112         return this.id;
113     },
114     /*
115     setSize : function(width, height){
116         if(!this.ignoreResize(width, height)){
117             var grid = this.grid;
118             var size = this.adjustForComponents(width, height);
119             grid.getGridEl().setSize(size.width, size.height);
120             grid.autoSize();
121         }
122     },
123     
124     beforeSlide : function(){
125         this.grid.getView().scroller.clip();
126     },
127     
128     afterSlide : function(){
129         this.grid.getView().scroller.unclip();
130     },
131     */
132     destroy : function(){
133       //  this.grid.destroy();
134        // delete this.grid;
135         Roo.GridPanel.superclass.destroy.call(this);
136          
137     },
138     render : function()
139     {
140         this.onRender(this.el, false)
141     },
142     
143     onRender : function(ct, position)
144     {
145         if (this.rendered) {
146             return;
147         }
148         this.rendered = true;
149         
150         Roo.log("render calendar");
151         
152         //Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
153         
154         
155         var cfg = Roo.apply({},  this.getAutoCreate());
156         cfg.id = Roo.id();
157         
158         // fill in the extra attributes 
159         if (this.xattr && typeof(this.xattr) =='object') {
160             for (var i in this.xattr) {
161                 cfg[i] = this.xattr[i];
162             }
163         }
164         
165         if(this.dataId){
166             cfg.dataId = this.dataId;
167         }
168         
169         if (this.cls) {
170             cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
171         }
172         
173         if (this.style) { // fixme needs to support more complex style data.
174             cfg.style = this.style;
175         }
176         
177         if(this.name){
178             cfg.name = this.name;
179         }
180         
181         this.el = ct.createChild(cfg, position);
182         
183         if(this.tabIndex !== undefined){
184             this.el.dom.setAttribute('tabIndex', this.tabIndex);
185         }
186         
187         
188         this.initEvents();
189         this.fireEvent('rendered');
190     }
191     
192     
193     
194     
195 });
196
197
198
199 Roo.each([
200     'getAutoCreate',
201     'initEvents',
202     'resize',
203     'showPrevMonth',
204     'showToday',
205     'showNextMonth',
206     'showPrevYear',
207     'showNextYear',
208     'update',
209     'findCell',
210     'findCells',
211     'findBestRow',
212     'addItem',
213     'clearEvents',
214     'renderEvents',
215     'onEventEnter',
216     'onEventLeave',
217     'onEventClick',
218     'onMonthChange',
219     'onLoad'
220
221     
222 ], function(p) {
223     Roo.log('add' + p);
224     Roo.CalendarPanel.prototype[p] = Roo.bootstrap.Calendar.prototype[p];
225  
226 });