WeekEventRenderer.js
7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* @private
* This is an internal helper class for the calendar views and should not be overridden.
* It is responsible for the base event rendering logic underlying all views based on a
* box-oriented layout that supports day spanning (MonthView, MultiWeekView, DayHeaderView).
*/
Ext.define('Ext.calendar.util.WeekEventRenderer', {
requires: ['Ext.core.DomHelper'],
statics: {
// private
getEventRow: function(id, week, index) {
var indexOffset = 1,
//skip row with date #'s
evtRow,
wkRow = Ext.get(id + '-wk-' + week);
if (wkRow) {
var table = wkRow.child('.ext-cal-evt-tbl', true);
evtRow = table.tBodies[0].childNodes[index + indexOffset];
if (!evtRow) {
evtRow = Ext.core.DomHelper.append(table.tBodies[0], '<tr></tr>');
}
}
return Ext.get(evtRow);
},
render: function(o) {
var w = 0,
grid = o.eventGrid,
dt = Ext.Date.clone(o.viewStart),
eventTpl = o.tpl,
max = o.maxEventsPerDay != undefined ? o.maxEventsPerDay: 999,
weekCount = o.weekCount < 1 ? 6: o.weekCount,
dayCount = o.weekCount == 1 ? o.dayCount: 7,
cellCfg;
for (; w < weekCount; w++) {
if (!grid[w] || grid[w].length == 0) {
// no events or span cells for the entire week
if (weekCount == 1) {
row = this.getEventRow(o.id, w, 0);
cellCfg = {
tag: 'td',
cls: 'ext-cal-ev',
id: o.id + '-empty-0-day-' + Ext.Date.format(dt, 'Ymd'),
html: ' '
};
if (dayCount > 1) {
cellCfg.colspan = dayCount;
}
Ext.core.DomHelper.append(row, cellCfg);
}
dt = Ext.calendar.util.Date.add(dt, {days: 7});
} else {
var row,
d = 0,
wk = grid[w],
startOfWeek = Ext.Date.clone(dt),
endOfWeek = Ext.calendar.util.Date.add(startOfWeek, {days: dayCount, millis: -1});
for (; d < dayCount; d++) {
if (wk[d]) {
var ev = emptyCells = skipped = 0,
day = wk[d],
ct = day.length,
evt;
for (; ev < ct; ev++) {
if (!day[ev]) {
emptyCells++;
continue;
}
if (emptyCells > 0 && ev - emptyCells < max) {
row = this.getEventRow(o.id, w, ev - emptyCells);
cellCfg = {
tag: 'td',
cls: 'ext-cal-ev',
id: o.id + '-empty-' + ct + '-day-' + Ext.Date.format(dt, 'Ymd')
};
if (emptyCells > 1 && max - ev > emptyCells) {
cellCfg.rowspan = Math.min(emptyCells, max - ev);
}
Ext.core.DomHelper.append(row, cellCfg);
emptyCells = 0;
}
if (ev >= max) {
skipped++;
continue;
}
evt = day[ev];
if (!evt.isSpan || evt.isSpanStart) {
//skip non-starting span cells
var item = evt.data || evt.event.data;
item._weekIndex = w;
item._renderAsAllDay = item[Ext.calendar.data.EventMappings.IsAllDay.name] || evt.isSpanStart;
item.spanLeft = item[Ext.calendar.data.EventMappings.StartDate.name].getTime() < startOfWeek.getTime();
item.spanRight = item[Ext.calendar.data.EventMappings.EndDate.name].getTime() > endOfWeek.getTime();
item.spanCls = (item.spanLeft ? (item.spanRight ? 'ext-cal-ev-spanboth':
'ext-cal-ev-spanleft') : (item.spanRight ? 'ext-cal-ev-spanright': ''));
row = this.getEventRow(o.id, w, ev);
cellCfg = {
tag: 'td',
cls: 'ext-cal-ev',
cn: eventTpl.apply(o.templateDataFn(item))
};
var diff = Ext.calendar.util.Date.diffDays(dt, item[Ext.calendar.data.EventMappings.EndDate.name]) + 1,
cspan = Math.min(diff, dayCount - d);
if (cspan > 1) {
cellCfg.colspan = cspan;
}
Ext.core.DomHelper.append(row, cellCfg);
}
}
if (ev > max) {
row = this.getEventRow(o.id, w, max);
Ext.core.DomHelper.append(row, {
tag: 'td',
cls: 'ext-cal-ev-more',
id: 'ext-cal-ev-more-' + Ext.Date.format(dt, 'Ymd'),
cn: {
tag: 'a',
html: '+' + skipped + ' more...'
}
});
}
if (ct < o.evtMaxCount[w]) {
row = this.getEventRow(o.id, w, ct);
if (row) {
cellCfg = {
tag: 'td',
cls: 'ext-cal-ev',
id: o.id + '-empty-' + (ct + 1) + '-day-' + Ext.Date.format(dt, 'Ymd')
};
var rowspan = o.evtMaxCount[w] - ct;
if (rowspan > 1) {
cellCfg.rowspan = rowspan;
}
Ext.core.DomHelper.append(row, cellCfg);
}
}
} else {
row = this.getEventRow(o.id, w, 0);
if (row) {
cellCfg = {
tag: 'td',
cls: 'ext-cal-ev',
id: o.id + '-empty-day-' + Ext.Date.format(dt, 'Ymd')
};
if (o.evtMaxCount[w] > 1) {
cellCfg.rowSpan = o.evtMaxCount[w];
}
Ext.core.DomHelper.append(row, cellCfg);
}
}
dt = Ext.calendar.util.Date.add(dt, {days: 1});
}
}
}
}
}
});