AgendaView.js
11.7 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/* An abstract class for all agenda-related views. Displays one more columns with time slots running vertically.
----------------------------------------------------------------------------------------------------------------------*/
// Is a manager for the TimeGrid subcomponent and possibly the DayGrid subcomponent (if allDaySlot is on).
// Responsible for managing width/height.
var AGENDA_DEFAULTS = {
allDaySlot: true,
allDayText: 'all-day',
scrollTime: '06:00:00',
slotDuration: '00:30:00',
minTime: '00:00:00',
maxTime: '24:00:00',
slotEventOverlap: true // a bad name. confused with overlap/constraint system
};
var AGENDA_ALL_DAY_EVENT_LIMIT = 5;
var AgendaView = fcViews.agenda = View.extend({
timeGrid: null, // the main time-grid subcomponent of this view
dayGrid: null, // the "all-day" subcomponent. if all-day is turned off, this will be null
axisWidth: null, // the width of the time axis running down the side
noScrollRowEls: null, // set of fake row elements that must compensate when scrollerEl has scrollbars
// when the time-grid isn't tall enough to occupy the given height, we render an <hr> underneath
bottomRuleEl: null,
bottomRuleHeight: null,
initialize: function() {
this.timeGrid = new TimeGrid(this);
if (this.opt('allDaySlot')) { // should we display the "all-day" area?
this.dayGrid = new DayGrid(this); // the all-day subcomponent of this view
// the coordinate grid will be a combination of both subcomponents' grids
this.coordMap = new ComboCoordMap([
this.dayGrid.coordMap,
this.timeGrid.coordMap
]);
}
else {
this.coordMap = this.timeGrid.coordMap;
}
},
/* Rendering
------------------------------------------------------------------------------------------------------------------*/
// Sets the display range and computes all necessary dates
setRange: function(range) {
View.prototype.setRange.call(this, range); // call the super-method
this.timeGrid.setRange(range);
if (this.dayGrid) {
this.dayGrid.setRange(range);
}
},
// Renders the view into `this.el`, which has already been assigned
render: function() {
this.el.addClass('fc-agenda-view').html(this.renderHtml());
// the element that wraps the time-grid that will probably scroll
this.scrollerEl = this.el.find('.fc-time-grid-container');
this.timeGrid.coordMap.containerEl = this.scrollerEl; // don't accept clicks/etc outside of this
this.timeGrid.setElement(this.el.find('.fc-time-grid'));
this.timeGrid.renderDates();
// the <hr> that sometimes displays under the time-grid
this.bottomRuleEl = $('<hr class="fc-divider ' + this.widgetHeaderClass + '"/>')
.appendTo(this.timeGrid.el); // inject it into the time-grid
if (this.dayGrid) {
this.dayGrid.setElement(this.el.find('.fc-day-grid'));
this.dayGrid.renderDates();
// have the day-grid extend it's coordinate area over the <hr> dividing the two grids
this.dayGrid.bottomCoordPadding = this.dayGrid.el.next('hr').outerHeight();
}
this.noScrollRowEls = this.el.find('.fc-row:not(.fc-scroller *)'); // fake rows not within the scroller
},
// Unrenders the content of the view. Since we haven't separated skeleton rendering from date rendering,
// always completely kill each grid's rendering.
destroy: function() {
this.timeGrid.destroyDates();
this.timeGrid.removeElement();
if (this.dayGrid) {
this.dayGrid.destroyDates();
this.dayGrid.removeElement();
}
},
renderBusinessHours: function() {
this.timeGrid.renderBusinessHours();
if (this.dayGrid) {
this.dayGrid.renderBusinessHours();
}
},
// Builds the HTML skeleton for the view.
// The day-grid and time-grid components will render inside containers defined by this HTML.
renderHtml: function() {
return '' +
'<table>' +
'<thead class="fc-head">' +
'<tr>' +
'<td class="' + this.widgetHeaderClass + '">' +
this.timeGrid.headHtml() + // render the day-of-week headers
'</td>' +
'</tr>' +
'</thead>' +
'<tbody class="fc-body">' +
'<tr>' +
'<td class="' + this.widgetContentClass + '">' +
(this.dayGrid ?
'<div class="fc-day-grid"/>' +
'<hr class="fc-divider ' + this.widgetHeaderClass + '"/>' :
''
) +
'<div class="fc-time-grid-container">' +
'<div class="fc-time-grid"/>' +
'</div>' +
'</td>' +
'</tr>' +
'</tbody>' +
'</table>';
},
// Generates the HTML that will go before the day-of week header cells.
// Queried by the TimeGrid subcomponent when generating rows. Ordering depends on isRTL.
headIntroHtml: function() {
var date;
var weekText;
if (this.opt('weekNumbers')) {
date = this.timeGrid.getCell(0).start;
weekText = date.format(this.opt('smallWeekFormat'));
return '' +
'<th class="fc-axis fc-week-number ' + this.widgetHeaderClass + '" ' + this.axisStyleAttr() + '>' +
'<span>' + // needed for matchCellWidths
htmlEscape(weekText) +
'</span>' +
'</th>';
}
else {
return '<th class="fc-axis ' + this.widgetHeaderClass + '" ' + this.axisStyleAttr() + '></th>';
}
},
// Generates the HTML that goes before the all-day cells.
// Queried by the DayGrid subcomponent when generating rows. Ordering depends on isRTL.
dayIntroHtml: function() {
return '' +
'<td class="fc-axis ' + this.widgetContentClass + '" ' + this.axisStyleAttr() + '>' +
'<span>' + // needed for matchCellWidths
(this.opt('allDayHtml') || htmlEscape(this.opt('allDayText'))) +
'</span>' +
'</td>';
},
// Generates the HTML that goes before the bg of the TimeGrid slot area. Long vertical column.
slotBgIntroHtml: function() {
return '<td class="fc-axis ' + this.widgetContentClass + '" ' + this.axisStyleAttr() + '></td>';
},
// Generates the HTML that goes before all other types of cells.
// Affects content-skeleton, helper-skeleton, highlight-skeleton for both the time-grid and day-grid.
// Queried by the TimeGrid and DayGrid subcomponents when generating rows. Ordering depends on isRTL.
introHtml: function() {
return '<td class="fc-axis" ' + this.axisStyleAttr() + '></td>';
},
// Generates an HTML attribute string for setting the width of the axis, if it is known
axisStyleAttr: function() {
if (this.axisWidth !== null) {
return 'style="width:' + this.axisWidth + 'px"';
}
return '';
},
/* Dimensions
------------------------------------------------------------------------------------------------------------------*/
updateSize: function(isResize) {
this.timeGrid.updateSize(isResize);
View.prototype.updateSize.call(this, isResize); // call the super-method
},
// Refreshes the horizontal dimensions of the view
updateWidth: function() {
// make all axis cells line up, and record the width so newly created axis cells will have it
this.axisWidth = matchCellWidths(this.el.find('.fc-axis'));
},
// Adjusts the vertical dimensions of the view to the specified values
setHeight: function(totalHeight, isAuto) {
var eventLimit;
var scrollerHeight;
if (this.bottomRuleHeight === null) {
// calculate the height of the rule the very first time
this.bottomRuleHeight = this.bottomRuleEl.outerHeight();
}
this.bottomRuleEl.hide(); // .show() will be called later if this <hr> is necessary
// reset all dimensions back to the original state
this.scrollerEl.css('overflow', '');
unsetScroller(this.scrollerEl);
uncompensateScroll(this.noScrollRowEls);
// limit number of events in the all-day area
if (this.dayGrid) {
this.dayGrid.destroySegPopover(); // kill the "more" popover if displayed
eventLimit = this.opt('eventLimit');
if (eventLimit && typeof eventLimit !== 'number') {
eventLimit = AGENDA_ALL_DAY_EVENT_LIMIT; // make sure "auto" goes to a real number
}
if (eventLimit) {
this.dayGrid.limitRows(eventLimit);
}
}
if (!isAuto) { // should we force dimensions of the scroll container, or let the contents be natural height?
scrollerHeight = this.computeScrollerHeight(totalHeight);
if (setPotentialScroller(this.scrollerEl, scrollerHeight)) { // using scrollbars?
// make the all-day and header rows lines up
compensateScroll(this.noScrollRowEls, getScrollbarWidths(this.scrollerEl));
// the scrollbar compensation might have changed text flow, which might affect height, so recalculate
// and reapply the desired height to the scroller.
scrollerHeight = this.computeScrollerHeight(totalHeight);
this.scrollerEl.height(scrollerHeight);
}
else { // no scrollbars
// still, force a height and display the bottom rule (marks the end of day)
this.scrollerEl.height(scrollerHeight).css('overflow', 'hidden'); // in case <hr> goes outside
this.bottomRuleEl.show();
}
}
},
// Computes the initial pre-configured scroll state prior to allowing the user to change it
computeInitialScroll: function() {
var scrollTime = moment.duration(this.opt('scrollTime'));
var top = this.timeGrid.computeTimeTop(scrollTime);
// zoom can give weird floating-point values. rather scroll a little bit further
top = Math.ceil(top);
if (top) {
top++; // to overcome top border that slots beyond the first have. looks better
}
return top;
},
/* Events
------------------------------------------------------------------------------------------------------------------*/
// Renders events onto the view and populates the View's segment array
renderEvents: function(events) {
var dayEvents = [];
var timedEvents = [];
var daySegs = [];
var timedSegs;
var i;
// separate the events into all-day and timed
for (i = 0; i < events.length; i++) {
if (events[i].allDay) {
dayEvents.push(events[i]);
}
else {
timedEvents.push(events[i]);
}
}
// render the events in the subcomponents
timedSegs = this.timeGrid.renderEvents(timedEvents);
if (this.dayGrid) {
daySegs = this.dayGrid.renderEvents(dayEvents);
}
// the all-day area is flexible and might have a lot of events, so shift the height
this.updateHeight();
},
// Retrieves all segment objects that are rendered in the view
getEventSegs: function() {
return this.timeGrid.getEventSegs().concat(
this.dayGrid ? this.dayGrid.getEventSegs() : []
);
},
// Unrenders all event elements and clears internal segment data
destroyEvents: function() {
// destroy the events in the subcomponents
this.timeGrid.destroyEvents();
if (this.dayGrid) {
this.dayGrid.destroyEvents();
}
// we DON'T need to call updateHeight() because:
// A) a renderEvents() call always happens after this, which will eventually call updateHeight()
// B) in IE8, this causes a flash whenever events are rerendered
},
/* Dragging (for events and external elements)
------------------------------------------------------------------------------------------------------------------*/
// A returned value of `true` signals that a mock "helper" event has been rendered.
renderDrag: function(dropLocation, seg) {
if (dropLocation.start.hasTime()) {
return this.timeGrid.renderDrag(dropLocation, seg);
}
else if (this.dayGrid) {
return this.dayGrid.renderDrag(dropLocation, seg);
}
},
destroyDrag: function() {
this.timeGrid.destroyDrag();
if (this.dayGrid) {
this.dayGrid.destroyDrag();
}
},
/* Selection
------------------------------------------------------------------------------------------------------------------*/
// Renders a visual indication of a selection
renderSelection: function(range) {
if (range.start.hasTime() || range.end.hasTime()) {
this.timeGrid.renderSelection(range);
}
else if (this.dayGrid) {
this.dayGrid.renderSelection(range);
}
},
// Unrenders a visual indications of a selection
destroySelection: function() {
this.timeGrid.destroySelection();
if (this.dayGrid) {
this.dayGrid.destroySelection();
}
}
});
AgendaView.defaults = AGENDA_DEFAULTS;