forked from damiengarbarino/dojo-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewBase.js
executable file
·2154 lines (1781 loc) · 57.2 KB
/
ViewBase.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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
define([
"dcl/dcl",
"luxon",
"dojo/_base/lang",
"ibm-decor/sniff",
"dojo/dom-style",
"dojo/dom-class",
"dojo/dom-construct",
"dojo/dom-geometry",
"delite/Selection",
"./StoreBase",
"./TimeBase",
"./RendererManager"
], function (
dcl,
luxon,
lang,
has,
domStyle,
domClass,
domConstruct,
domGeometry,
Selection,
StoreBase,
TimeBase,
RendererManager
) {
var DateTime = luxon.DateTime,
Interval = luxon.Interval;
/*=====
var __GridClickEventArgs = {
// summary:
// The event dispatched when the grid is clicked or double-clicked.
// date: DateTime
// The start of the previously displayed time interval, if any.
// triggerEvent: Event
// The event at the origin of this event.
};
=====*/
/*=====
var __ItemMouseEventArgs = {
// summary:
// The event dispatched when an item is clicked, double-clicked or context-clicked.
// item: Object
// The item clicked.
// renderer: dcalendar/_RendererMixin
// The item renderer clicked.
// triggerEvent: Event
// The event at the origin of this event.
};
=====*/
/*=====
var __itemEditingEventArgs = {
// summary:
// An item editing event.
// item: Object
// The render item that is being edited. Set/get the startTime and/or endTime properties
// to customize editing behavior.
// storeItem: Object
// The real data from the store. DO NOT change properties, but you may use properties of this item
// in the editing behavior logic.
// editKind: String
// Kind of edit: "resizeBoth", "resizeStart", "resizeEnd" or "move".
// dates: DateTime[]
// The computed date/time of the during the event editing. One entry per edited date (touch use case).
// startTime: DateTime?
// The start time of data item.
// endTime: DateTime?
// The end time of data item.
// sheet: String
// For views with several sheets (columns view for example), the sheet when the event occurred.
// source: dcalendar/ViewBase
// The view where the event occurred.
// eventSource: String
// The device that triggered the event. This property can take the following values:
//
// - "mouse",
// - "keyboard",
// - "touch"
// triggerEvent: Event
// The event at the origin of this event.
};
=====*/
/*=====
var __rendererLifecycleEventArgs = {
// summary:
// An renderer lifecycle event.
// renderer: Object
// The renderer.
// source: dcalendar/ViewBase
// The view where the event occurred.
// item:Object?
// The item that will be displayed by the renderer for the
// "renderer-created" and "renderer-reused" events.
};
=====*/
return dcl([StoreBase, TimeBase, Selection], {
// summary:
// Base class of the views (ColumnView, MatrixView, etc.).
// viewKind: String
// Kind of the view. Used by the calendar widget to determine how to configure the view.
viewKind: null,
// _layoutStep: [protected] Integer
// The number of units displayed by a visual layout unit (i.e. a column or a row)
_layoutStep: 1,
// _layoutStep: [protected] Integer
// The unit displayed by a visual layout unit (i.e. a column or a row)
_layoutUnit: "day",
// resizeCursor: String
// CSS value to apply to the cursor while resizing an item renderer.
resizeCursor: "n-resize",
// formatItemTime: Function
// Optional function to format the time of day of the item renderers.
// The function takes the date, the render data object,
// the view and the data item as arguments and returns a String.
formatItemTime: null,
_cssDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
// The listeners added by the view itself.
_viewHandles: null,
// doubleTapDelay: Integer
// The maximum time amount in milliseconds between to touchstart events that trigger a double-tap event.
doubleTapDelay: 300,
////////////////////////////////////////////////////////
//
// Computed properties, not to be set directly.
// Most of these used to be inside renderData.
//
////////////////////////////////////////////////////////
// Range of dates currently displayed by the view
startTime: null,
endTime: null,
dates: null,
sheetHeight: -1,
// visibleItems: Object[]
// List of events that appear on the calendar given the current time constraints
// (determined by startDate, columnCount, rowCount, etc.)
visibleItems: null,
// visibleDecorationItems: Object[]
// List of decorations that appear on the calendar given the current time constraints
// (determined by startDate, columnCount, rowCount, etc.)
visibleDecorationItems: null,
constructor: function () {
this._viewHandles = [];
this.rendererManager = new RendererManager({owner: this});
this.rendererManager.on("renderer-created", this.emit.bind(this, "renderer-created"));
this.rendererManager.on("renderer-reused", this.emit.bind(this, "renderer-reused"));
this.rendererManager.on("renderer-recycled", this.emit.bind(this, "renderer-recycled"));
this.rendererManager.on("renderer-destroyed", this.emit.bind(this, "renderer-destroyed"));
this.decorationRendererManager = new RendererManager({owner: this});
this._setupDayRefresh();
},
refreshRendering: function (oldVals) {
// Create the grid/boilerplate initially, and update it whenever we move to a new month etc.
if ("dates" in oldVals || "attached" in oldVals) {
this._createRendering();
}
// Add the events.
if ("dates" in oldVals || "visibleItems" in oldVals || "attached" in oldVals) {
this._layoutRenderers();
}
if ("dates" in oldVals || "visibleDecorationItems" in oldVals || "attached" in oldVals) {
this._layoutDecorationRenderers();
}
},
destroy: function () {
this.rendererManager.destroy();
this.decorationRendererManager.destroy();
while (this._viewHandles.length > 0) {
this._viewHandles.pop().remove();
}
},
_setupDayRefresh: function () {
// Refresh the view when the current day changes.
var now = +DateTime.local();
var tomorrow = +DateTime.local().startOf("day").plus({ day: 1 });
this.defer(function () {
if (!this._isEditing) {
this.notifyCurrentValue("dates"); // make refreshRendering() rerender
}
this._setupDayRefresh();
}, tomorrow - now + 5000); // add 5 seconds to be sure to be tomorrow
},
resize: function (changeSize) {
// summary:
// Function to call when the view is resized.
// If the view is in a Dijit container or in a Dojo mobile container,
// it will be automatically called.
// On other use cases, this method must called when the window is resized and/or
// when the orientation has changed.
if (changeSize) {
domGeometry.setMarginBox(this, changeSize);
}
},
// view lifecycle methods
beforeActivate: function () {
// summary:
// Function invoked just before the view is displayed by the calendar.
// tags:
// protected
},
afterActivate: function () {
// summary:
// Function invoked just after the view is displayed by the calendar.
// tags:
// protected
},
beforeDeactivate: function () {
// summary:
// Function invoked just before the view is hidden or removed by the calendar.
// tags:
// protected
},
afterDeactivate: function () {
// summary:
// Function invoked just after the view is the view is hidden or removed by the calendar.
// tags:
// protected
},
_setText: function (node, text, allowHTML) {
// summary:
// Creates a text node under the parent node after having removed children nodes if any.
// node: Node
// The node that will contain the text node.
// text: String
// The text to set to the text node.
if (text != null) {
if (!allowHTML && node.hasChildNodes()) {
// span > textNode
node.childNodes[0].childNodes[0].nodeValue = text;
} else {
while (node.hasChildNodes()) {
node.removeChild(node.lastChild);
}
var tNode = this.ownerDocument.createElement("span");
if (allowHTML) {
tNode.innerHTML = text;
} else {
tNode.appendChild(this.ownerDocument.createTextNode(text));
}
node.appendChild(tNode);
}
}
},
isAscendantHasClass: function (node, ancestor, className) {
// summary:
// Determines if a node has an ascendant node that has the css class specified.
// node: Node
// The DOM node.
// ancestor: Node
// The ancestor node used to limit the search in hierarchy.
// className: String
// The css class name.
// returns: Boolean
while (node != ancestor && node != document) {
if (domClass.contains(node, className)) {
return true;
}
node = node.parentNode;
}
return false;
},
computeRangeOverlap: function (start1, end1, start2, end2, includeLimits) {
// summary:
// Computes the overlap time range of the time ranges.
// Returns a vector of DateTime with at index 0 the start time and at index 1 the end time.
// start1: DateTime
// The start time of the first time range.
// end1: DateTime
// The end time of the first time range.
// start2: DateTime
// The start time of the second time range.
// end2: DateTime
// The end time of the second time range.
// includeLimits: Boolean
// Whether include the end time or not.
// returns: DateTime[]
if (start1 == null || start2 == null || end1 == null || end2 == null) {
return null;
}
var comp1 = +start1 - +end2;
var comp2 = +start2 - +end1;
if (includeLimits) {
if (comp1 === 0 || comp1 === 1 || comp2 === 0 || comp2 === 1) {
return null;
}
} else if (comp1 === 1 || comp2 === 1) {
return null;
}
return [
start1 > start2 ? start1 : start2,
end1 > end2 ? end2 : end1
];
},
computeProjectionOnDate: function (refDate, date, max) {
// summary:
// Computes the time to pixel projection in a day.
// refDate: DateTime
// The reference date that defines the destination date.
// date: DateTime
// The date to project.
// max: Integer
// The size in pixels of the representation of a day.
// tags:
// protected
// returns: Number
var minH = this.minHours;
var maxH = this.maxHours;
if (max <= 0 || date < refDate) {
return 0;
}
var gt = function (d) {
return d.hour * 3600 + d.minute * 60 + d.second;
};
var referenceDate = refDate.startOf("day");
if (date.day != referenceDate.day) {
if (date.month == referenceDate.month) {
if (date.day < referenceDate.day) {
return 0;
} else if (date.day > referenceDate.day && maxH < 24) {
return max;
}
} else {
if (date.year == referenceDate.year) {
if (date.month < referenceDate.month) {
return 0;
} else if (date.month > referenceDate.month) {
return max;
}
} else {
if (date.year < referenceDate.year) {
return 0;
} else if (date.year > referenceDate.year) {
return max;
}
}
}
}
var res;
var ONE_DAY = 86400; // 24h x 60m x 60s
if (this.isSameDay(refDate, date) || maxH > 24) {
var minTime = 0;
if (minH) {
minTime = gt(refDate.set({ hour: minH }));
}
var d = refDate.set({ hour: maxH });
var maxTime;
if (maxH === null || maxH === 24) {
maxTime = ONE_DAY;
} else if (maxH > 24) {
maxTime = ONE_DAY + gt(d);
} else {
maxTime = gt(d);
}
//precision is the second
//use this API for daylight time issues.
var delta = 0;
if (maxH > 24 && refDate.day != date.day) {
delta = ONE_DAY + gt(date);
} else {
delta = gt(date);
}
if (delta < minTime) {
return 0;
}
if (delta > maxTime) {
return max;
}
delta -= minTime;
res = (max * delta) / (maxTime - minTime);
} else {
if (date.day < refDate.day && date.month == refDate.month) {
return 0;
}
var d2 = date.startOf("day");
var dp1 = refDate.plus({ day: 1 }).startOf("day");
if (d2 > refDate && +d2 === +dp1 || d2 > dp1) {
res = max;
} else {
res = 0;
}
}
return res;
},
getTime: function (/*===== e, x, y, touchIndex =====*/) {
// summary:
// Returns the time displayed at the specified point by this component.
// e: Event
// Optional mouse event.
// x: Number
// Position along the x-axis with respect to the sheet container used if event is not defined.
// y: Number
// Position along the y-axis with respect to the sheet container (scroll included)
// used if event is not defined.
// touchIndex: Integer
// If parameter 'e' is not null and a touch event, the index of the touch to use.
// returns: DateTime
return null;
},
getSubColumn: function (/*===== e, x, y, touchIndex =====*/) {
// summary:
// Returns the sub column at the specified point by this component.
// e: Event
// Optional mouse event.
// x: Number
// Position along the x-axis with respect to the sheet container used if event is not defined.
// y: Number
// Position along the y-axis with respect to the sheet container (scroll included)
// used if event is not defined.
// touchIndex: Integer
// If parameter 'e' is not null and a touch event, the index of the touch to use.
// returns: Object
return null;
},
getSubColumnIndex: function (value) {
// summary:
// Returns the sub column index that has the specified value, if any. -1 otherwise.
// value: String
// The sub column index.
if (this.subColumns) {
for (var i = 0; i < this.subColumns.length; i++) {
if (this.subColumns[i] == value) {
return i;
}
}
}
return -1;
},
_isItemInView: function (item) {
// summary:
// Computes whether the specified item is entirely in the view or not.
// item: Object
// The item to test
// returns: Boolean
return item.startTime >= this.startTime && item.endTime <= this.endTime;
},
_ensureItemInView: function (item) {
// summary:
// If needed, moves the item to be entirely in view.
// item: Object
// The item to test
// returns: Boolean
// Whether the item has been moved to be in view or not.
// tags:
// protected
var duration = item.endTime.diff(item.startTime);
var fixed = false;
if (item.startTime < this.startTime) {
item.startTime = this.startTime;
item.endTime = this.startTime.plus(duration);
fixed = true;
} else if (item.endTime > this.endTime) {
item.startTime = this.endTime.minus(duration);
item.endTime = this.endTime;
fixed = true;
}
return fixed;
},
/////////////////////////////////////////////////////////
//
// Scrollable
//
/////////////////////////////////////////////////////////
// scrollable: Boolean
// Indicates whether the view can be scrolled or not.
scrollable: true,
// autoScroll: Boolean
// Indicates whether the view can be scrolled automatically.
// Auto scrolling is used when moving focus to a non visible renderer using keyboard
// and while editing an item.
autoScroll: true,
_startAutoScroll: function (step) {
// summary:
// Starts the auto scroll of the view (if it's scrollable). Used only during editing.
// tags:
// protected
var sp = this._scrollProps;
if (!sp) {
sp = this._scrollProps = {};
}
sp.scrollStep = step;
if (!sp.isScrolling) {
sp.isScrolling = true;
sp.scrollTimer = setInterval(this._onScrollTimerTick.bind(this), 10);
}
},
_stopAutoScroll: function () {
// summary:
// Stops the auto scroll of the view (if it's scrollable). Used only during editing.
// tags:
// protected
var sp = this._scrollProps;
if (sp && sp.isScrolling) {
clearInterval(sp.scrollTimer);
sp.scrollTimer = null;
}
this._scrollProps = null;
},
_onScrollTimerTick: function (/*===== pos =====*/) {
},
scrollView: function (/*===== dir =====*/) {
// summary:
// If the view is scrollable, scrolls it vertically to the specified direction.
// dir: Integer
// Direction of the scroll. Valid values are -1 and 1.
// tags:
// extension
},
ensureVisibility: function (/*===== start, end, margin, visibilityTarget, duration =====*/) {
// summary:
// Scrolls the view if the [start, end] time range is not visible or only partially visible.
// start: DateTime
// Start time of the range of interest.
// end: DateTime
// End time of the range of interest.
// margin: int
// Margin in minutes around the time range.
// visibilityTarget: String
// The end(s) of the time range to make visible.
// Valid values are: "start", "end", "both".
// duration: Number
// Optional, the maximum duration of the scroll animation.
// tags:
// extension
},
////////////////////////////////////////////////////////
//
// Store & Items
//
////////////////////////////////////////////////////////
_refreshDecorationItemsRendering: function () {
this._computeVisibleItems();
this._layoutDecorationRenderers();
},
invalidateLayout: function () {
// summary:
// Triggers a re-layout of the renderers.
// Generally this shouldn't be used; layout happens automatically on property changes.
this._layoutRenderers();
this._layoutDecorationRenderers();
},
////////////////////////////////////////////////////////
//
// Layout
//
////////////////////////////////////////////////////////
computeOverlapping: function (layoutItems, func) {
// summary:
// Computes the overlap layout of a list of items.
// A lane and extent properties are added to each layout item.
// layoutItems: Object[]
// List of layout items, each item must have a start and end properties.
// addedPass: Function
// Whether computes the extent of each item renderer on free sibling lanes.
// returns: Object
// tags:
// protected
if (layoutItems.length === 0) {
return {
numLanes: 0,
addedPassRes: [1]
};
}
var lanes = [];
for (var i = 0; i < layoutItems.length; i++) {
var layoutItem = layoutItems[i];
this._layoutPass1(layoutItem, lanes);
}
var addedPassRes = null;
if (func) {
addedPassRes = func.call(this, lanes);
}
return {
numLanes: lanes.length,
addedPassRes: addedPassRes
};
},
_layoutPass1: function (layoutItem, lanes) {
// summary:
// First pass of the overlap layout. Find a lane where the item can be placed or create a new one.
// layoutItem: Object
// An object that contains a start and end properties at least.
// lanes:
// The array of lanes.
// tags:
// protected
var stop = true;
for (var i = 0; i < lanes.length; i++) {
var lane = lanes[i];
stop = false;
for (var j = 0; j < lane.length && !stop; j++) {
if (lane[j].start < layoutItem.end && layoutItem.start < lane[j].end) {
// one already placed item is overlapping
stop = true;
lane[j].extent = 1;
}
}
if (!stop) {
//we have found a place
layoutItem.lane = i;
layoutItem.extent = -1;
lane.push(layoutItem);
return;
}
}
//no place found -> add a lane
lanes.push([layoutItem]);
layoutItem.lane = lanes.length - 1;
layoutItem.extent = -1;
},
_layoutInterval: function (/*===== index, start, end, items =====*/) {
// summary:
// For each item in the items list: retrieve a renderer,
// compute its location and size and add it to the DOM.
// index: Integer
// The index of the interval.
// start: DateTime
// The start time of the displayed date interval.
// end: DateTime
// The end time of the displayed date interval.
// items: Object[]
// The list of the items to represent.
// tags:
// extension
},
layoutPriorityFunction: function (a, b) {
// summary:
// Comparison function use to determine the order the item will be laid out
// The function is used to sort an array and must, as any sorting function, take two items
// as argument and must return an integer whose sign define order between arguments.
// By default, a comparison by start time then end time is used.
return (+a.startTime - +b.startTime) || (+b.endTime - a.endTime);
},
_layoutRenderers: function () {
this._layoutRenderersImpl(this.rendererManager, this.visibleItems, "dataItems");
},
_layoutDecorationRenderers: function () {
this._layoutRenderersImpl(this.decorationRendererManager, this.visibleDecorationItems,
"decorationItems");
},
_layoutRenderersImpl: function (rendererManager, items, itemType) {
// summary:
// Renders the data items. This method will call the _layoutInterval() method.
// tags:
// protected
if (!items) {
return;
}
// Remove all the old renderers from the screen (but saving them for reuse later).
rendererManager.recycleItemRenderers();
// Date
var startDate = this.startTime;
// Date and time
var startTime = startDate;
var endDate;
items = items.concat();
var itemsTemp = [], events;
var processing = {};
var index = 0;
var duration = {};
duration[this._layoutUnit] = this._layoutStep;
while (startDate < this.endTime && items.length > 0) {
endDate = startDate.plus(duration);
var endTime = endDate;
if (this.minHours) {
startTime = startTime.set({
hour: this.minHours
});
}
if (this.maxHours !== undefined && this.maxHours != 24) {
if (this.maxHours < 24) {
endTime = endDate.minus({ day: 1 });
} // else > 24
endTime = endTime.startOf("day").set({
hour: this.maxHours - (this.maxHours < 24 ? 0 : 24)
});
}
var subInterval = Interval.fromDateTimes(startTime, endTime);
// look for events that overlap the current sub interval
events = items.filter(function (item) {
var itemInterval = Interval.fromDateTimes(item.startTime, item.endTime);
var r = itemInterval.overlaps(subInterval);
if (r) {
processing[item.id] = true;
itemsTemp.push(item);
} else {
if (processing[item.id]) {
delete processing[item.id];
} else {
itemsTemp.push(item);
}
}
return r;
}, this);
items = itemsTemp;
itemsTemp = [];
// if event are in the current sub interval, layout them
if (events.length > 0) {
// Sort the item according a sorting function,
// by default start time then end time comparison are used.
events.sort(this.layoutPriorityFunction.bind(this));
this._layoutInterval(index, startTime, endTime, events, itemType);
}
startDate = endDate;
startTime = startDate;
index++;
}
this.emit("renderers-layout-done");
},
/////////////////////////////////////////////////////////////////
//
// Renderers management
//
////////////////////////////////////////////////////////////////
_recycleItemRenderers: function () {
this.rendererManager.recycleItemRenderers();
},
getRenderers: function (item) {
// summary:
// Returns the renderers that are currently used to displayed the specified item.
// Returns an array of objects that contains two properties:
// - container: The DOM node that contains the renderer.
// - renderer: The dojox.calendar._RendererMixin instance.
// Do not keep references on the renderers are they are recycled and reused for other items.
// item: Object
// The data or render item.
// returns: Object[]
return this.rendererManager.getRenderers(item);
},
// itemToRendererKind: Function
// An optional function to associate a kind of renderer ("horizontal", "label" or null)
// with the specified item.
// By default, if an item is lasting more that 24 hours an horizontal item is used,
// otherwise a label is used.
itemToRendererKind: null,
_itemToRendererKind: function (item) {
// summary:
// Associates a kind of renderer with a data item.
// item: Object
// The data item.
// returns: String
// tags:
// protected
if (this.itemToRendererKind) {
return this.itemToRendererKind(item);
}
return this._defaultItemToRendererKindFunc(item); // String
},
_defaultItemToRendererKindFunc: function (/*===== item =====*/) {
// tags:
// extension
return null;
},
_createRenderer: function (item, kind, rendererClass, cssClass) {
// summary:
// Creates an item renderer of the specified kind.
// A renderer is an object with the "container" and "instance" properties.
// item: Object
// The data item.
// kind: String
// The kind of renderer.
// rendererClass: Object
// The class to instantiate to create the renderer.
// returns: Object
// tags:
// protected
return this.rendererManager.createRenderer(item, kind, rendererClass, cssClass);
},
_destroyRenderersByKind: function (kind) {
// tags:
// private
if (!this.renderManager) {
// Avoid failure from dcl (or delite?) problem where SimpleColumnView#_setVerticalRendererAttr() is
// called while creating a subclass of SimpleColumnView.
return;
}
this.rendererManager.destroyRenderersByKind(kind);
},
_updateEditingCapabilities: function (item, renderer) {
// summary:
// Update the moveEnabled and resizeEnabled properties of a renderer
// according to its event current editing state.
// item: Object
// The store data item.
// renderer: dcalendar/_RendererMixin
// The item renderer.
// tags:
// protected
renderer.moveEnabled = this.isItemMoveEnabled(item, renderer.rendererKind);
renderer.resizeEnabled = this.isItemResizeEnabled(item, renderer.rendererKind);
renderer.deliver();
},
updateRenderers: function (obj, stateOnly) {
// summary:
// Updates all the renderers that represent the specified item(s).
// obj: Object
// An item or an array of items.
// stateOnly: Boolean
// Whether only the state of the item has changed (selected, edited, edited, focused)
// or a more global change has occurred.
// tags:
// protected
if (obj == null) {
return;
}
var items = lang.isArray(obj) ? obj : [obj];
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item == null || item.id == null) {
continue;
}
var list = this.rendererManager.itemToRenderer[item.id];
if (list == null) {
continue;
}
var selected = this.isSelected(item);
var hovered = this.isItemHovered(item);
var edited = this.isItemBeingEdited(item);
var focused = this.showFocus ? this.isItemFocused(item) : false;
for (var j = 0; j < list.length; j++) {
var renderer = list[j].renderer;
renderer.hovered = hovered;
renderer.selected = selected;
renderer.edited = edited;
renderer.focused = focused;
renderer.storeState = this.getItemStoreState(item);
this.applyRendererZIndex(item, list[j], hovered, selected, edited, focused);
if (!stateOnly) {
renderer.notifyCurrentValue("item"); // force content refresh
renderer.deliver();
}
}
}
},
applyRendererZIndex: function (item, renderer, hovered, selected, edited /*=====, focused =====*/) {
// summary:
// Applies the z-index to the renderer based on the state of the item.
// This methods is setting a z-index of 20 is the item is selected or edited
// and the current lane value computed by the overlap layout (i.e. the renderers
// are stacked according to their lane).