/
CALEXT2_ViewCell.js
130 lines (120 loc) · 4.1 KB
/
CALEXT2_ViewCell.js
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
/* global View WeekSlot */
// eslint-disable-next-line no-unused-vars
class ViewCell extends View {
constructor(config, events) {
super(config, events);
this.slotUnit = "week";
}
makeSlots() {
this.contentDom.innerHTML = "";
this.slotPeriods = this.getSlotPeriods();
this.slots = WeekSlot.factory(this, this.slotPeriods, this.events);
for (let i = 0; i < this.slots.length; i++) {
const slot = this.slots[i];
this.appendSlot(slot);
}
this.makeModuleTitle();
}
getSlotPeriods() {
const { showWeekends } = this.config;
const getSlotPeriod = (tDay, seq) => {
const mtd = moment(tDay).locale(this.locale).add(seq, "week");
const start = showWeekends
? moment(mtd).startOf("week")
: moment(mtd).startOf("week").day(1).startOf("day");
const end = showWeekends
? moment(mtd).endOf("week")
: moment(mtd).startOf("week").day(5).endOf("day");
return {
start,
end
};
};
const periods = [];
const targetDay = this.getStartDay();
const count = this.getSlotCount();
for (let i = 0; i < count; i++) {
const period = getSlotPeriod(targetDay, i);
periods.push(period);
}
return periods;
}
getSubSlotPeriods(start) {
const { showWeekends } = this.config;
const days = showWeekends ? 7 : 5;
const periods = [];
const t = start;
const startDay = showWeekends
? moment(t).locale(this.locale).startOf("week")
: moment(t).locale(this.locale).startOf("week").day(1).startOf("day");
for (let i = 0; i < days; i++) {
const p = {
start: moment(startDay).startOf("day"),
end: moment(startDay).endOf("day")
};
periods.push(p);
startDay.add(1, "day");
}
return periods;
}
makeSlotDomClass(slot) {
const slotDom = slot.dom;
super.makeSlotDomClass(slot);
slotDom.classList.add("weekSlot");
}
// eslint-disable-next-line class-methods-use-this
viewDomType(viewDom) {
viewDom.classList.add("column");
}
adjustSlotHeight(slotDom) {
slotDom.style.maxHeight = this.config.slotMaxHeight;
slotDom.style.height = this.config.slotMaxHeight;
}
makeCellDomClass(slot, daySeq, weekSeq) {
const slotDom = slot.dom;
if (daySeq >= 0) slotDom.classList.add(`cellSeq_${daySeq}`);
if (weekSeq === 0 && daySeq === 0) {
slotDom.classList.add("firstCell");
}
const day = moment(slot.start).locale(this.locale);
const now = moment().locale(this.locale);
if (now.format("YYYY") === day.format("YYYY"))
slotDom.classList.add("thisyear");
if (now.format("M") === day.format("M")) slotDom.classList.add("thismonth");
if (now.format("w") === day.format("w")) slotDom.classList.add("thisweek");
if (now.format("YYYYMMDD") === day.format("YYYYMMDD"))
slotDom.classList.add("today");
if (now.format("YYYYMMDD") > day.format("YYYYMMDD"))
slotDom.classList.add("passedday");
slotDom.classList.add(`weekday_${day.format("E")}`);
slotDom.classList.add(`year_${day.format("YYYY")}`);
slotDom.classList.add(`month_${day.format("M")}`);
slotDom.classList.add(`day_${day.format("D")}`);
slotDom.classList.add(`week_${day.format("w")}`);
slotDom.classList.add(`dayofyear_${day.format("DDD")}`);
}
makeWeeksMark(start) {
const weeks = document.createElement("div");
weeks.classList.add("weeksmark");
weeks.innerHTML = moment(start)
.locale(this.locale)
.format(this.config.weeksFormat);
return weeks;
}
// eslint-disable-next-line class-methods-use-this, no-unused-vars
adjustSlotWidth(slotDom, count) {
// if (this.config.type == "row") slotDom.style.width = ((100 / count) - 0.25) + "%"
}
makeSlotHeader(slot) {
super.makeSlotHeader(slot);
const header = slot.headerDom;
const altTitle = header.querySelector(".slotAltTitle");
if (this.config.slotAltTitle) {
altTitle.innerHTML = this.config.slotTitle;
} else if (this.config.slotAltTitleFormat) {
altTitle.innerHTML = moment(slot.start)
.locale(this.locale)
.format(this.config.slotAltTitleFormat);
}
}
}