3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.calendar.BoxLayoutTemplate
9 * @extends Ext.XTemplate
10 * <p>This is the template used to render calendar views based on small day boxes within a non-scrolling container (currently
11 * the {@link Ext.calendar.MonthView MonthView} and the all-day headers for {@link Ext.calendar.DayView DayView} and
12 * {@link Ext.calendar.WeekView WeekView}. This template is automatically bound to the underlying event store by the
13 * calendar components and expects records of type {@link Ext.calendar.EventRecord}.</p>
15 * @param {Object} config The config object
17 Ext.calendar.BoxLayoutTemplate = function(config){
19 Ext.apply(this, config);
21 var weekLinkTpl = this.showWeekLinks ? '<div id="{weekLinkId}" class="ext-cal-week-link">{weekNum}</div>' : '';
23 Ext.calendar.BoxLayoutTemplate.superclass.constructor.call(this,
25 '<div id="{[this.id]}-wk-{[xindex-1]}" class="ext-cal-wk-ct" style="top:{[this.getRowTop(xindex, xcount)]}%; height:{[this.getRowHeight(xcount)]}%;">',
27 '<table class="ext-cal-bg-tbl" cellpadding="0" cellspacing="0">',
31 '<td id="{[this.id]}-day-{date:date("Ymd")}" class="{cellCls}"> </td>',
36 '<table class="ext-cal-evt-tbl" cellpadding="0" cellspacing="0">',
40 '<td id="{[this.id]}-ev-day-{date:date("Ymd")}" class="{titleCls}"><div>{title}</div></td>',
47 getRowTop: function(i, ln){
48 return ((i-1)*(100/ln));
50 getRowHeight: function(ln){
57 Ext.extend(Ext.calendar.BoxLayoutTemplate, Ext.XTemplate, {
59 applyTemplate : function(o){
63 var w = 0, title = '', first = true, isToday = false, showMonth = false, prevMonth = false, nextMonth = false,
65 today = new Date().clearTime(),
66 dt = this.viewStart.clone(),
67 thisMonth = this.startDate.getMonth();
69 for(; w < this.weekCount || this.weekCount == -1; w++){
70 if(dt > this.viewEnd){
75 for(var d = 0; d < this.dayCount; d++){
76 isToday = dt.getTime() === today.getTime();
77 showMonth = first || (dt.getDate() == 1);
78 prevMonth = (dt.getMonth() < thisMonth) && this.weekCount == -1;
79 nextMonth = (dt.getMonth() > thisMonth) && this.weekCount == -1;
82 // The ISO week format 'W' is relative to a Monday week start. If we
83 // make this check on Sunday the week number will be off.
84 weeks[w].weekNum = this.showWeekNumbers ? dt.format('W') : ' ';
85 weeks[w].weekLinkId = 'ext-cal-week-'+dt.format('Ymd');
90 title = this.getTodayText();
93 title = dt.format(this.dayCount == 1 ? 'l, F j, Y' : (first ? 'M j, Y' : 'M j'));
97 var dayFmt = (w == 0 && this.showHeader !== true) ? 'D j' : 'j';
98 title = isToday ? this.getTodayText() : dt.format(dayFmt);
104 titleCls: 'ext-cal-dtitle ' + (isToday ? ' ext-cal-dtitle-today' : '') +
105 (w==0 ? ' ext-cal-dtitle-first' : '') +
106 (prevMonth ? ' ext-cal-dtitle-prev' : '') +
107 (nextMonth ? ' ext-cal-dtitle-next' : ''),
108 cellCls: 'ext-cal-day ' + (isToday ? ' ext-cal-day-today' : '') +
109 (d==0 ? ' ext-cal-day-first' : '') +
110 (prevMonth ? ' ext-cal-day-prev' : '') +
111 (nextMonth ? ' ext-cal-day-next' : '')
113 dt = dt.add(Date.DAY, 1);
118 return Ext.calendar.BoxLayoutTemplate.superclass.applyTemplate.call(this, {
124 getTodayText : function(){
125 var dt = new Date().format('l, F j, Y'),
126 todayText = this.showTodayText !== false ? this.todayText : '',
127 timeText = this.showTime !== false ? ' <span id="'+this.id+'-clock" class="ext-cal-dtitle-time">' +
128 new Date().format('g:i a') + '</span>' : '',
129 separator = todayText.length > 0 || timeText.length > 0 ? ' — ' : '';
131 if(this.dayCount == 1){
132 return dt + separator + todayText + timeText;
134 fmt = this.weekCount == 1 ? 'D j' : 'j';
135 return todayText.length > 0 ? todayText + timeText : new Date().format(fmt) + timeText;
139 Ext.calendar.BoxLayoutTemplate.prototype.apply = Ext.calendar.BoxLayoutTemplate.prototype.applyTemplate;