-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
192 lines (174 loc) · 5.67 KB
/
index.js
File metadata and controls
192 lines (174 loc) · 5.67 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
$(() => {
const isWeekEnd = (date) => {
const day = date.getDay();
return day === 0 || day === 6;
};
const getCurrentTraining = (date, employeeID) => {
const result = (date + employeeID) % 3;
return `training-background-${result}`;
};
const appointmentTooltipTemplate = (data) => {
const curResource = employees
.find((resource) => resource.id === data.appointmentData.employeeID);
const tooltip = $('<div class="dx-tooltip-appointment-item">');
const marker = $('<div class="dx-tooltip-appointment-item-marker">')
.append($('<div class="dx-tooltip-appointment-item-marker-body">').css('background', curResource.color));
const content = $('<div class="dx-tooltip-appointment-item-content">')
.append($('<div class="dx-tooltip-appointment-item-content-subject">').text(data.appointmentData.text))
.append($('<div class="dx-tooltip-appointment-item-content-date">').text(data.appointmentData.startDate));
tooltip.append(marker);
tooltip.append(content);
const isButtonExist = !curResource.disabled && (scheduler.option('editing')
&& (scheduler.option('editing.allowDeleting') === true || scheduler.option('editing') === true));
if (isButtonExist) {
const buttonContainer = $('<div class="dx-tooltip-appointment-item-delete-button-container">');
const button = $('<div class="dx-tooltip-appointment-item-delete-button">').dxButton({
icon: 'trash',
stylingMode: 'text',
onClick(e) {
scheduler.deleteAppointment(data.appointmentData);
e.event.stopPropagation();
scheduler.hideAppointmentTooltip();
},
});
buttonContainer.append(button);
tooltip.append(buttonContainer);
}
return tooltip;
};
const dataCellTemplate = (cellData, index, container) => {
const { employeeID } = cellData.groups;
const currentTraining = getCurrentTraining(cellData.startDate.getDate(), employeeID);
const wrapper = $('<div>')
.toggleClass(`employee-weekend-${employeeID}`, isWeekEnd(cellData.startDate)).appendTo(container)
.addClass(`employee-${employeeID}`)
.addClass('dx-template-wrapper');
wrapper.append($('<div>')
.text(cellData.text)
.addClass(currentTraining)
.addClass('day-cell'));
};
const resourceCellTemplate = (cellData) => {
const name = $('<div>')
.addClass('name')
.css({ backgroundColor: cellData.color })
.append($('<h2>')
.text(cellData.text));
const avatar = $('<div>')
.addClass('avatar')
.html(`<img src=${cellData.data.avatar}>`)
.attr('title', cellData.text);
const info = $('<div>')
.addClass('info')
.css({ color: cellData.color })
.html(`Age: ${cellData.data.age}<br/><b>${cellData.data.discipline}</b>`);
return $('<div>').append([name, avatar, info]);
};
const scheduler = $('#scheduler').dxScheduler({
timeZone: 'America/Los_Angeles',
dataSource: data,
views: ['month'],
currentView: 'month',
currentDate: new Date(2021, 5, 2, 11, 30),
firstDayOfWeek: 1,
startDayHour: 8,
endDayHour: 18,
showAllDayPanel: false,
height: 600,
groups: ['employeeID'],
resources: [
{
fieldExpr: 'employeeID',
allowMultiple: false,
dataSource: employees,
label: 'Employee',
},
],
appointmentTooltipTemplate,
dataCellTemplate,
resourceCellTemplate,
}).dxScheduler('instance');
});
const employees = [{
text: 'John Heart',
id: 1,
color: '#56ca85',
avatar: '../public/images/coach-man.png',
age: 27,
discipline: 'ABS, Fitball, StepFit',
}, {
text: 'Sandra Johnson',
id: 2,
color: '#ff9747',
avatar: '../public/images/coach-woman.png',
age: 25,
discipline: 'ABS, Fitball, StepFit',
}];
const data = [
{
text: 'Helen',
employeeID: 2,
startDate: new Date('2021-06-01T16:30:00.000Z'),
endDate: new Date('2021-06-01T18:30:00.000Z'),
}, {
text: 'Helen',
employeeID: 2,
startDate: new Date('2021-06-10T16:30:00.000Z'),
endDate: new Date('2021-06-11T18:30:00.000Z'),
}, {
text: 'Alex',
employeeID: 1,
startDate: new Date('2021-06-02T16:30:00.000Z'),
endDate: new Date('2021-06-02T18:30:00.000Z'),
}, {
text: 'Alex',
employeeID: 1,
startDate: new Date('2021-06-11T19:00:00.000Z'),
endDate: new Date('2021-06-11T20:00:00.000Z'),
}, {
text: 'Alex',
employeeID: 2,
startDate: new Date('2021-06-16T16:30:00.000Z'),
endDate: new Date('2021-06-16T18:30:00.000Z'),
}, {
text: 'Stan',
employeeID: 1,
startDate: new Date('2021-06-07T16:30:00.000Z'),
endDate: new Date('2021-06-07T18:30:00.000Z'),
}, {
text: 'Stan',
employeeID: 1,
startDate: new Date('2021-06-28T16:30:00.000Z'),
endDate: new Date('2021-06-28T18:30:00.000Z'),
}, {
text: 'Stan',
employeeID: 1,
startDate: new Date('2021-06-30T16:30:00.000Z'),
endDate: new Date('2021-06-30T18:30:00.000Z'),
}, {
text: 'Rachel',
employeeID: 2,
startDate: new Date('2021-06-04T16:30:00.000Z'),
endDate: new Date('2021-06-04T18:30:00.000Z'),
}, {
text: 'Rachel',
employeeID: 2,
startDate: new Date('2021-06-07T16:30:00.000Z'),
endDate: new Date('2021-06-07T18:30:00.000Z'),
}, {
text: 'Rachel',
employeeID: 1,
startDate: new Date('2021-06-21T16:30:00.000Z'),
endDate: new Date('2021-06-21T18:30:00.000Z'),
}, {
text: 'Kelly',
employeeID: 2,
startDate: new Date('2021-06-15T16:30:00.000Z'),
endDate: new Date('2021-06-15T18:30:00.000Z'),
}, {
text: 'Kelly',
employeeID: 2,
startDate: new Date('2021-06-29T16:30:00.000Z'),
endDate: new Date('2021-06-29T18:30:00.000Z'),
},
];