4 * based on jquery fullcalendar
10 * @class Roo.bootstrap.Calendar
11 * @extends Roo.bootstrap.Component
12 * Bootstrap Calendar class
15 * Create a new Container
16 * @param {Object} config The config object
19 Roo.bootstrap.Calendar = function(config){
20 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
24 * Fires when a date is selected
25 * @param {DatePicker} this
26 * @param {Date} date The selected date
31 * Fires when the displayed month changes
32 * @param {DatePicker} this
33 * @param {Date} date The selected month
40 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
43 * @cfg {Number} startDay
44 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
48 getAutoCreate : function(){
51 fc_button = function(name, corner, style, content ) {
54 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
56 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
59 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
74 cls : 'fc-header-left',
76 fc_button('prev', 'left', 'arrow', '‹' ),
77 fc_button('next', 'right', 'arrow', '›' ),
78 { tag: 'span', cls: 'fc-header-space' },
79 fc_button('today', 'left right', '', 'today' ), // neds state disabled..
87 cls : 'fc-header-center',
91 cls: 'fc-header-title',
102 cls : 'fc-header-right',
104 fc_button('month', 'left', '', 'month' ),
105 fc_button('week', '', '', 'week' ),
106 fc_button('day', 'right', '', 'day' )
118 var cal_heads = function() {
120 // fixme - handle this.
122 for (var i =0; i < Date.dayNames.length; i++) {
123 var d = Date.dayNames[i];
126 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
127 html : d.substring(0,3)
131 ret[0].cls += ' fc-first';
132 ret[6].cls += ' fc-last';
135 var cal_cell = function(n) {
138 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
143 cls: 'fc-day-number',
147 cls: 'fc-day-content',
151 style: 'position: relative;' // height: 17px;
163 var cal_rows = function() {
165 for (var r = 0; r < 6; r++) {
172 for (var i =0; i < Date.dayNames.length; i++) {
173 var d = Date.dayNames[i];
174 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
177 row.cn[0].cls+=' fc-first';
178 row.cn[0].cn[0].style = 'min-height:90px';
179 row.cn[6].cls+=' fc-last';
183 ret[0].cls += ' fc-first';
185 ret[5].cls += ' fc-last';
191 cls: 'fc-border-separate',
192 style : 'width:100%',
200 cls : 'fc-first fc-last',
219 style : "position: relative;",
222 cls : 'fc-view fc-view-month fc-grid',
223 style : 'position: relative',
227 cls : 'fc-event-container',
228 style : 'position:absolute;z-index:8;top:0;left:0;'
246 initEvents : function()
249 this.cells = this.el.select('.fc-day',true);
250 this.textNodes = this.el.query('.fc-day-number');
251 this.update(new Date());
254 resize : function() {
255 var sz = this.el.getSize();
257 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
258 this.el.select('.fc-day-content div',true).setHeight(34);
261 update : function(date)
263 var vd = this.activeDate;
264 this.activeDate = date;
266 var t = date.getTime();
267 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
268 this.cells.removeClass("fc-state-highlight");
269 this.cells.each(function(c){
270 if(c.dom.firstChild.dateValue == t){
271 c.addClass("fc-state-highlight");
272 setTimeout(function(){
273 try{c.dom.firstChild.focus();}catch(e){}
283 var days = date.getDaysInMonth();
284 var firstOfMonth = date.getFirstDateOfMonth();
285 var startingPos = firstOfMonth.getDay()-this.startDay;
287 if(startingPos <= this.startDay){
291 var pm = date.add("mo", -1);
292 var prevStart = pm.getDaysInMonth()-startingPos;
294 var cells = this.cells.elements;
295 var textEls = this.textNodes;
298 // convert everything to numbers so it's fast
300 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
301 var today = new Date().clearTime().getTime();
302 var sel = date.clearTime().getTime();
303 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
304 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
305 var ddMatch = this.disabledDatesRE;
306 var ddText = this.disabledDatesText;
307 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
308 var ddaysText = this.disabledDaysText;
309 var format = this.format;
311 var setCellClass = function(cal, cell){
316 cell.className += " fc-today";
317 cell.title = cal.todayText;
320 cell.className += " fc-state-highlight";
321 //setTimeout(function(){
322 // try{cell.firstChild.focus();}catch(e){}
327 cell.className = " fc-state-disabled";
328 cell.title = cal.minText;
332 cell.className = " fc-state-disabled";
333 cell.title = cal.maxText;
337 if(ddays.indexOf(d.getDay()) != -1){
338 cell.title = ddaysText;
339 cell.className = " fc-state-disabled";
342 if(ddMatch && format){
343 var fvalue = d.dateFormat(format);
344 if(ddMatch.test(fvalue)){
345 cell.title = ddText.replace("%0", fvalue);
346 cell.className = " fc-state-disabled";
349 if (!cell.initialClassName) {
350 cell.initialClassName = cell.dom.className;
352 cell.dom.className = cell.initialClassName + ' ' + cell.className;
356 for(; i < startingPos; i++) {
357 textEls[i].innerHTML = (++prevStart);
358 d.setDate(d.getDate()+1);
359 cells[i].className = "fc-past fc-other-month";
360 setCellClass(this, cells[i]);
362 for(; i < days; i++){
363 intDay = i - startingPos + 1;
364 textEls[i].innerHTML = (intDay);
365 d.setDate(d.getDate()+1);
366 //cells[i].className = "x-date-active";
367 setCellClass(this, cells[i]);
371 textEls[i].innerHTML = (++extraDays);
372 d.setDate(d.getDate()+1);
373 cells[i].className = "fc-future fc-other-month";
374 setCellClass(this, cells[i]);
377 this.el.select('.fc-header-title h2',true).update((Date.monthNames[date.getMonth()] + " " + date.getFullYear());
378 this.fireEvent('monthchange', this, date);
382 if(!this.internalRender){
383 var main = this.el.dom.firstChild;
384 var w = main.offsetWidth;
385 this.el.setWidth(w + this.el.getBorderWidth("lr"));
386 Roo.fly(main).setWidth(w);
387 this.internalRender = true;
388 // opera does not respect the auto grow header center column
389 // then, after it gets a width opera refuses to recalculate
390 // without a second pass
391 if(Roo.isOpera && !this.secondPass){
392 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
393 this.secondPass = true;
394 this.update.defer(10, this, [date]);