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     
44     this.on('activate', function()
45     {
46         Roo.log('activate');
47          
48         //console.log('render tree');
49         this.render();
50     },this);
51     
52     this.addEvents({
53         /**
54              * @event select
55              * Fires when a date is selected
56              * @param {DatePicker} this
57              * @param {Date} date The selected date
58              */
59         'select': true,
60         /**
61              * @event monthchange
62              * Fires when the displayed month changes 
63              * @param {DatePicker} this
64              * @param {Date} date The selected month
65              */
66         'monthchange': true,
67         /**
68              * @event evententer
69              * Fires when mouse over an event
70              * @param {Calendar} this
71              * @param {event} Event
72              */
73         'evententer': true,
74         /**
75              * @event eventleave
76              * Fires when the mouse leaves an
77              * @param {Calendar} this
78              * @param {event}
79              */
80         'eventleave': true,
81         /**
82              * @event eventclick
83              * Fires when the mouse click an
84              * @param {Calendar} this
85              * @param {event}
86              */
87         'eventclick': true,
88         /**
89              * @event rendered
90              * Fires when the grid is rendered
91              * @param {Calendar} this
92             
93              */
94         'rendered': true
95         
96         
97     });
98     
99     //this.grid = grid;
100     //this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
101 };
102
103
104 Roo.extend(Roo.CalendarPanel, Roo.ContentPanel, {
105     getId : function(){
106         return this.id;
107     },
108     /*
109     setSize : function(width, height){
110         if(!this.ignoreResize(width, height)){
111             var grid = this.grid;
112             var size = this.adjustForComponents(width, height);
113             grid.getGridEl().setSize(size.width, size.height);
114             grid.autoSize();
115         }
116     },
117     
118     beforeSlide : function(){
119         this.grid.getView().scroller.clip();
120     },
121     
122     afterSlide : function(){
123         this.grid.getView().scroller.unclip();
124     },
125     */
126     destroy : function(){
127       //  this.grid.destroy();
128        // delete this.grid;
129         Roo.GridPanel.superclass.destroy.call(this);
130          
131     },
132     render : function()
133     {
134         this.onRender(this.el, false)
135     },
136     
137     onRender : function(ct, position)
138     {
139         if (this.rendered) {
140             return;
141         }
142         this.rendered = true;
143         
144         Roo.log("render calendar");
145         
146         //Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
147         
148         
149         var cfg = Roo.apply({},  this.getAutoCreate());
150         cfg.id = Roo.id();
151         
152         // fill in the extra attributes 
153         if (this.xattr && typeof(this.xattr) =='object') {
154             for (var i in this.xattr) {
155                 cfg[i] = this.xattr[i];
156             }
157         }
158         
159         if(this.dataId){
160             cfg.dataId = this.dataId;
161         }
162         
163         if (this.cls) {
164             cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
165         }
166         
167         if (this.style) { // fixme needs to support more complex style data.
168             cfg.style = this.style;
169         }
170         
171         if(this.name){
172             cfg.name = this.name;
173         }
174         
175         this.el = ct.createChild(cfg, position);
176         
177         if(this.tabIndex !== undefined){
178             this.el.dom.setAttribute('tabIndex', this.tabIndex);
179         }
180         this.initEvents();
181     },
182     
183     
184     getAutoCreate : Roo.bootstrap.Calendar.prototype.getAutoCreate,
185     
186     initEvents : Roo.bootstrap.Calendar.prototype.initEvents 
187     
188     
189 });
190
191
192
193 Roo.each([
194     'getAutoCreate',
195     'initEvents',
196     'resize',
197     'showPrevMonth',
198     'showToday',
199     'showNextMonth',
200     'showPrevYear',
201     'showNextYear',
202     'update',
203     'findCell',
204     'findCells',
205     'findBestRow',
206     'addItem',
207     'clearEvents',
208     'renderEvents',
209     'onEventEnter',
210     'onEventLeave',
211     'onEventClick',
212     'onMonthChange',
213     'onLoad'
214
215     
216 ], function(p) {
217     Roo.log('add' + p);
218     Roo.CalendarPanel.prototype[p] = Roo.bootstrap.Calendar.prototype[p];
219  
220 });