-
Notifications
You must be signed in to change notification settings - Fork 17
/
SimpleColumnView.js
2314 lines (1867 loc) · 65.2 KB
/
SimpleColumnView.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([
"./ViewBase",
"dijit/_TemplatedMixin",
"./_ScrollBarBase",
"dojo/text!./templates/ColumnView.html",
"dojo/_base/declare",
"dojo/_base/event",
"dojo/_base/lang",
"dojo/_base/array",
"dojo/_base/sniff",
"dojo/_base/fx",
"dojo/_base/html",
"dojo/on",
"dojo/dom",
"dojo/dom-class",
"dojo/dom-style",
"dojo/dom-geometry",
"dojo/dom-construct",
"dojo/mouse",
"dojo/query",
"dojox/html/metrics"],
function(
ViewBase,
_TemplatedMixin,
_ScrollBarBase,
template,
declare,
event,
lang,
arr,
has,
fx,
html,
on,
dom,
domClass,
domStyle,
domGeometry,
domConstruct,
mouse,
query,
metrics){
/*=====
var __ColumnClickEventArgs = {
// summary:
// A column click event.
// index: Integer
// The column index.
// date: Date
// The date displayed by the column.
// triggerEvent: Event
// The origin event.
};
=====*/
return declare("dojox.calendar.SimpleColumnView", [ViewBase, _TemplatedMixin], {
// summary:
// The simple column view is displaying a day per column. Each cell of a column is a time slot.
baseClass: "dojoxCalendarColumnView",
templateString: template,
// viewKind: String
// Type of the view. Used by the calendar widget to determine how to configure the view.
// This view kind is "columns".
viewKind: "columns",
// scroll container is the focusable item to enable scrolling using up and down arrows
_setTabIndexAttr: "domNode",
// renderData: Object
// The render data is the object that contains all the properties needed to render the component.
renderData: null,
// startDate: Date
// The start date of the time interval displayed.
// If not set at initialization time, will be set to current day.
startDate: null,
// columnCount: Integer
// The number of column to display (from the startDate).
columnCount: 7,
// subcolumns: String[]
// Array of sub columns values.
subColumns: null,
// minHours: Integer
// The minimum hour to be displayed. It must be in the [0,23] interval and must be lower than the maxHours.
minHours: 8,
// maxHours: Integer
// The maximum hour to be displayed. It must be in the [1,36] interval and must be greater than the minHours.
maxHours: 18,
// hourSize: Integer
// The desired size in pixels of an hour on the screen.
// Note that the effective size may be different as the time slot size must be an integer.
hourSize: 100,
// timeSlotDuration: Integer
// Duration of the time slot in minutes. Must be a divisor of 60.
timeSlotDuration: 15,
// rowHeaderGridSlotDuration: Integer
// Duration of the time slot in minutes in the row header. Must be a divisor of 60 and a multiple/divisor of timeSlotDuration.
rowHeaderGridSlotDuration: 60,
// rowHeaderLabelSlotDuration: Integer
// Duration of the time slot in minutes in the row header labels. Must be a divisor of 60 and a multiple/divisor of timeSlotDuration.
rowHeaderLabelSlotDuration: 60,
// rowHeaderLabelOffset: Integer
// Offset of the row label from the top of the row header cell in pixels.
rowHeaderLabelOffset: 2,
// rowHeaderFirstLabelOffset: Integer
// Offset of the first row label from the top of the first row header cell in pixels.
rowHeaderFirstLabelOffset: 2,
// verticalRenderer: Class
// The class use to create vertical renderers.
verticalRenderer: null,
// verticalDecorationRenderer: Class
// The class use to create decoration renderers.
verticalDecorationRenderer: null,
// minColumnWidth: Integer
// The minimum column width. If the number of columns and sub columns displayed makes the
// width of a column greater than this property, a horizontal scroll bar is displayed.
// If value <= 0, this constraint is ignored and the columns are using the available space.
minColumnWidth: -1,
// percentOverlap: Integer
// The percentage of the renderer width used to superimpose one item renderer on another
// when two events are overlapping.
percentOverlap: 70,
// horizontalGap: Integer
// The number of pixels between two item renderers that are overlapping each other if the percentOverlap property is 0.
horizontalGap: 4,
_showSecondarySheet: false,
_columnHeaderHandlers: null,
constructor: function(){
this.invalidatingProperties = ["columnCount", "startDate", "minHours", "maxHours", "hourSize", "verticalRenderer", "verticalDecorationRenderer",
"rowHeaderTimePattern", "columnHeaderDatePattern", "timeSlotDuration", "rowHeaderGridSlotDuration", "rowHeaderLabelSlotDuration",
"rowHeaderLabelOffset", "rowHeaderFirstLabelOffset","percentOverlap", "horizontalGap", "scrollBarRTLPosition","itemToRendererKindFunc",
"layoutPriorityFunction", "formatItemTimeFunc", "textDir", "items", "subColumns", "minColumnWidth"];
this._columnHeaderHandlers = [];
},
destroy: function(preserveDom){
this._cleanupColumnHeader();
if(this.scrollBar){
this.scrollBar.destroy(preserveDom);
}
this.inherited(arguments);
},
_scrollBar_onScroll: function(value){
this._setScrollPosition(value);
},
_hscrollBar_onScroll: function(value){
this._setHScrollPosition(value);
},
buildRendering: function(){
this.inherited(arguments);
if(this.vScrollBar){
this.scrollBar = new _ScrollBarBase(
{content: this.vScrollBarContent},
this.vScrollBar);
this.scrollBar.on("scroll", lang.hitch(this, this._scrollBar_onScroll));
}
if(this.hScrollBar){
this.hScrollBarW = new _ScrollBarBase(
{content: this.hScrollBarContent, direction: "horizontal", value: 0},
this.hScrollBar);
this.hScrollBarW.on("scroll", lang.hitch(this, this._hscrollBar_onScroll));
this._hScrollNodes = [this.columnHeaderTable, this.subColumnHeaderTable, this.gridTable, this.itemContainerTable];
}
this._viewHandles.push(
on(this.scrollContainer, mouse.wheel,
dojo.hitch(this, this._mouseWheelScrollHander)));
},
postscript: function(){
this.inherited(arguments);
this._initialized = true;
if(!this.invalidRendering){
this.refreshRendering();
}
},
_setVerticalRendererAttr: function(value){
this._destroyRenderersByKind("vertical");
this._set("verticalRenderer", value);
},
_createRenderData: function(){
var rd = {};
rd.minHours = this.get("minHours");
rd.maxHours = this.get("maxHours");
rd.hourSize = this.get("hourSize");
rd.hourCount = rd.maxHours - rd.minHours;
rd.slotDuration = this.get("timeSlotDuration"); // must be consistent with previous statement
rd.rowHeaderGridSlotDuration = this.get("rowHeaderGridSlotDuration");
rd.slotSize = Math.ceil(rd.hourSize / (60 / rd.slotDuration));
rd.hourSize = rd.slotSize * (60 / rd.slotDuration);
rd.sheetHeight = rd.hourSize * rd.hourCount;
if(!this._rowHeaderWidth){
this._rowHeaderWidth = domGeometry.getMarginBox(this.rowHeader).w;
}
rd.rowHeaderWidth = this._rowHeaderWidth;
var sbMetrics = metrics.getScrollbar();
rd.scrollbarWidth = sbMetrics.w + 1;
rd.scrollbarHeight = sbMetrics.h + 1;
rd.dateLocaleModule = this.dateLocaleModule;
rd.dateClassObj = this.dateClassObj;
rd.dateModule = this.dateModule; // arithmetics on Dates
rd.dates = [];
rd.columnCount = this.get("columnCount");
rd.subColumns = this.get("subColumns");
rd.subColumnCount = rd.subColumns ? rd.subColumns.length : 1;
rd.hScrollPaneWidth = domGeometry.getMarginBox(this.grid).w;
rd.minSheetWidth = this.minColumnWidth < 0 ? -1 : this.minColumnWidth * rd.subColumnCount * rd.columnCount;
rd.hScrollBarEnabled = this.minColumnWidth > 0 && rd.hScrollPaneWidth < rd.minSheetWidth;
var d = this.get("startDate");
if (d == null){
d = new rd.dateClassObj();
}
d = this.floorToDay(d, false, rd);
this.startDate = d;
for(var col = 0; col < rd.columnCount ; col++){
rd.dates.push(d);
d = this.addAndFloor(d, "day", 1);
}
rd.startTime = new rd.dateClassObj(rd.dates[0]);
rd.startTime.setHours(rd.minHours);
rd.endTime = new rd.dateClassObj(rd.dates[rd.columnCount-1]);
rd.endTime.setHours(rd.maxHours);
if(this.displayedItemsInvalidated && !this._isEditing){
// while editing in no live layout we must not to recompute items (duplicate renderers)
rd.items = this.storeManager._computeVisibleItems(rd);
}else if (this.renderData){
rd.items = this.renderData.items;
}
if(this.displayedDecorationItemsInvalidated){
// while editing in no live layout we must not to recompute items (duplicate renderers)
rd.decorationItems = this.decorationStoreManager._computeVisibleItems(rd);
}else if (this.renderData){
rd.decorationItems = this.renderData.decorationItems;
}
return rd;
},
_validateProperties: function() {
this.inherited(arguments);
var v = this.minHours;
if(v < 0 || v>23 || isNaN(v)){
this.minHours = 0;
}
v = this.maxHours;
if (v < 1 || v>36 || isNaN(v)){
this.minHours = 36;
}
if(this.minHours > this.maxHours){
var t = this.maxHours;
this.maxHours = this.minHours;
this.minHours = t;
}
if (this.maxHours - this.minHours < 1){
this.minHours = 0;
this.maxHours = 24;
}
if (this.columnCount<1 || isNaN(this.columnCount)){
this.columnCount = 1;
}
v = this.percentOverlap;
if(v < 0 ||v > 100 || isNaN(v)){
this.percentOverlap = 70;
}
if(this.hourSize<5 || isNaN(this.hourSize)){
this.hourSize = 10;
}
v = this.timeSlotDuration;
if (v < 1 || v > 60 || isNaN(v)) {
this.timeSlotDuration = 15;
}
},
_setStartDateAttr: function(value){
this.displayedItemsInvalidated = true;
this._set("startDate", value);
},
_setColumnCountAttr: function(value){
this.displayedItemsInvalidated = true;
this._set("columnCount", value);
},
__fixEvt:function(e){
// tags:
// private
e.sheet = "primary";
e.source = this;
return e;
},
//////////////////////////////////////////
//
// Formatting functions
//
//////////////////////////////////////////
// rowHeaderTimePattern: String
// Custom date/time pattern for the row header labels to override default one coming from the CLDR.
// See dojo/date/locale documentation for format string.
rowHeaderTimePattern: null,
_formatRowHeaderLabel: function(/*Date*/d){
// summary:
// Computes the row header label for the specified time of day.
// By default a formatter is used, optionally the <code>rowHeaderTimePattern</code> property can be used to set a custom time pattern to the formatter.
// d: Date
// The date to format
// tags:
// protected
return this.renderData.dateLocaleModule.format(d, {
selector: "time",
timePattern: this.rowHeaderTimePattern
});
},
// columnHeaderDatePattern: String
// Custom date/time pattern for column header labels to override default one coming from the CLDR.
// See dojo/date/locale documentation for format string.
columnHeaderDatePattern: null,
_formatColumnHeaderLabel: function(/*Date*/d){
// summary:
// Computes the column header label for the specified date.
// By default a formatter is used, optionally the <code>columnHeaderDatePattern</code> property can be used to set a custom date pattern to the formatter.
// d: Date
// The date to format
// tags:
// protected
return this.renderData.dateLocaleModule.format(d, {
selector: "date",
datePattern: this.columnHeaderDatePattern,
formatLength: "medium"
});
},
//////////////////////////////////////////
//
// Time of day management
//
//////////////////////////////////////////
// scrollBarRTLPosition: String
// Position of the scroll bar in right-to-left display.
// Valid values are "left" and "right", default value is "left".
scrollBarRTLPosition: "left",
_getStartTimeOfDay: function(){
// summary:
// Returns the visible first time of day.
// tags:
// protected
// returns: Object
var v = (this.get("maxHours") - this.get("minHours")) *
this._getScrollPosition() / this.renderData.sheetHeight;
return {
hours: this.renderData.minHours + Math.floor(v),
minutes: (v - Math.floor(v)) * 60
};
},
_getEndTimeOfDay: function(){
// summary:
// Returns the visible last time of day.
// tags:
// protected
// returns: Integer[]
var v = (this.get("maxHours") - this.get("minHours")) *
(this._getScrollPosition() + this.scrollContainer.offsetHeight) / this.renderData.sheetHeight;
return {
hours: this.renderData.minHours + Math.floor(v),
minutes: (v - Math.floor(v)) * 60
};
},
// startTimeOfDay: Object
// First time (hour/minute) of day displayed, if reachable.
// An object containing "hours" and "minutes" properties.
startTimeOfDay: 0,
_setStartTimeOfDayAttr: function(value){
if(this.renderData){
this._setStartTimeOfDay(value.hours, value.minutes, value.duration, value.easing);
}else{
this._startTimeOfDayInvalidated = true;
}
this._set("startTimeOfDay", value);
},
_getStartTimeOfDayAttr: function(){
if(this.renderData){
return this._getStartTimeOfDay();
}else{
return this._get("startTimeOfDay");
}
},
_setStartTimeOfDay: function(hour, minutes, maxDuration, easing){
// summary:
// Scrolls the view to show the specified first time of day.
// hour: Integer
// The hour of the start time of day.
// minutes: Integer
// The minutes part of the start time of day.
// maxDuration: Integer
// The max duration of the scroll animation.
// tags:
// protected
var rd = this.renderData;
hour = hour || rd.minHours;
minutes = minutes || 0;
maxDuration = maxDuration || 0;
if (minutes < 0){
minutes = 0;
}else if (minutes > 59){
minutes = 59;
}
if (hour < 0){
hour = 0;
}else if (hour > rd.maxHours){
hour = rd.maxHours;
}
var timeInMinutes = hour * 60 + minutes;
var minH = rd.minHours*60;
var maxH = rd.maxHours*60;
if (timeInMinutes < minH){
timeInMinutes = minH;
}else if(timeInMinutes > maxH){
timeInMinutes = maxH;
}
var pos = (timeInMinutes - minH) * rd.sheetHeight / (maxH - minH);
pos = Math.min(rd.sheetHeight - this.scrollContainer.offsetHeight, pos);
this._scrollToPosition(pos, maxDuration, easing);
},
_scrollToPosition: function(position, maxDuration, easing){
// summary:
// Scrolls the view to show the specified first time of day.
// position: Integer
// The position in pixels.
// maxDuration: Integer
// The max duration of the scroll animation.
// tags:
// protected
if (maxDuration) {
if(this._scrollAnimation){
this._scrollAnimation.stop();
}
var scrollPos = this._getScrollPosition();
var duration = Math.abs(((position - scrollPos) * maxDuration) / this.renderData.sheetHeight);
this._scrollAnimation = new fx.Animation({
curve: [scrollPos, position],
duration: duration,
easing: easing,
onAnimate: lang.hitch(this, function(position) {
this._setScrollImpl(position);
})
});
this._scrollAnimation.play();
}else{
this._setScrollImpl(position);
}
},
_setScrollImpl: function(v){
this._setScrollPosition(v);
if(this.scrollBar){
this.scrollBar.set("value", v);
}
},
ensureVisibility: function(start, end, visibilityTarget, margin, duration){
// summary:
// Scrolls the view if the [start, end] time range is not visible or only partially visible.
// start: Date
// Start time of the range of interest.
// end: Date
// End time of the range of interest.
// margin: Integer
// 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.
margin = margin == undefined ? this.renderData.slotDuration : margin;
if(this.scrollable && this.autoScroll){
var s = start.getHours() * 60 + start.getMinutes() - margin;
var e = end.getHours() * 60 + end.getMinutes() + margin;
var vs = this._getStartTimeOfDay();
var ve = this._getEndTimeOfDay();
var viewStart = vs.hours * 60 + vs.minutes;
var viewEnd = ve.hours * 60 + ve.minutes;
var visible = false;
var target = null;
switch(visibilityTarget){
case "start":
visible = s >= viewStart && s <= viewEnd;
target = s ;
break;
case "end":
visible = e >= viewStart && e <= viewEnd;
target = e - (viewEnd - viewStart);
break;
case "both":
visible = s >= viewStart && e <= viewEnd;
target = s;
break;
}
if(!visible){
this._setStartTimeOfDay(Math.floor(target/60), target%60, duration);
}
}
},
scrollView: function(dir){
// summary:
// Scrolls the view to the specified direction of one time slot duration.
// dir: Integer
// Direction of the scroll. Valid values are -1 and 1.
//
var t = this._getStartTimeOfDay();
t = t.hours*60 + t.minutes + (dir * this.timeSlotDuration);
this._setStartTimeOfDay(Math.floor(t/60), t%60);
},
scrollViewHorizontal: function(dir){
// summary:
// Scrolls the view horizontally to the specified direction of one column or sub column (if set).
// dir: Integer
// Direction of the scroll. Valid values are -1 and 1.
//
this._setHScrollPosition(this._getHScrollPosition() + (dir * this.minColumnWidth));
if(this.hScrollBarW){
this.hScrollBarW.set("value", this._getHScrollPosition());
}
},
_hScrollNodes: null,
_setHScrollPositionImpl: function(pos, useDom, cssProp){
var elts = [this.columnHeaderTable, this.subColumnHeaderTable, this.gridTable, this.itemContainerTable];
var css = useDom ? null : "translateX(-"+pos+"px)";
arr.forEach(elts, function(elt){
if(useDom){
elt.scrollLeft = pos;
domStyle.set(elt, "left", (-pos) + "px");
}else{
domStyle.set(elt, cssProp, css);
}
}, this);
},
_mouseWheelScrollHander: function(e){
// summary:
// Mouse wheel handler.
// tags:
// protected
if(this.renderData.hScrollBarEnabled && e.altKey){
this.scrollViewHorizontal(e.wheelDelta > 0 ? -1 : 1);
}else{
this.scrollView(e.wheelDelta > 0 ? -1 : 1);
}
event.stop(e);
},
//////////////////////////////////////////
//
// HTML structure management
//
//////////////////////////////////////////
refreshRendering: function(){
if(!this._initialized){
return;
}
this._validateProperties();
var oldRd = this.renderData;
var rd = this._createRenderData();
this.renderData = rd;
this._createRendering(rd, oldRd);
this._layoutDecorationRenderers(rd);
this._layoutRenderers(rd);
},
_createRendering: function(/*Object*/renderData, /*Object*/oldRenderData){
// tags:
// private
domStyle.set(this.sheetContainer, "height", renderData.sheetHeight + "px");
// padding for the scroll bar.
this._configureVisibleParts(renderData);
this._configureScrollBar(renderData);
this._buildColumnHeader(renderData, oldRenderData);
this._buildSubColumnHeader(renderData, oldRenderData);
this._buildRowHeader(renderData, oldRenderData);
this._buildGrid(renderData, oldRenderData);
this._buildItemContainer(renderData, oldRenderData);
this._layoutTimeIndicator(renderData);
this._commitProperties(renderData);
},
_configureVisibleParts: function(renderData){
if(this.secondarySheetNode){
domStyle.set(this.secondarySheetNode, "display", this._showSecondarySheet ? "block" : "none");
}
domClass[this.subColumns == null?"remove":"add"](this.domNode, "subColumns");
domClass[this._showSecondarySheet?"add":"remove"](this.domNode, "secondarySheet");
},
_commitProperties: function(renderData){
if(this._startTimeOfDayInvalidated){
this._startTimeOfDayInvalidated = false;
var v = this.startTimeOfDay;
if(v != null){
this._setStartTimeOfDay(v.hours, v.minutes == undefined ? 0 : v.minutes); // initial position, no animation
}
}
},
_configureScrollBar: function(renderData){
// summary:
// Sets the scroll bar size and position.
// renderData: Object
// The render data.
// tags:
// protected
if(has("ie") && this.scrollBar){
domStyle.set(this.vScrollBar, "width", (renderData.scrollbarWidth + 1) + "px");
}
var atRight = this.isLeftToRight() ? true : this.scrollBarRTLPosition == "right";
var rPos = atRight ? "right" : "left";
var lPos = atRight ? "left" : "right";
if(this.scrollBar){
this.scrollBar.set("maximum", renderData.sheetHeight);
domStyle.set(this.vScrollBar, rPos, 0);
domStyle.set(this.vScrollBar, atRight? "left" : "right", "auto");
domStyle.set(this.vScrollBar, "bottom", renderData.hScrollBarEnabled? renderData.scrollbarHeight + "px" : "0");
}
domStyle.set(this.scrollContainer, rPos, renderData.scrollbarWidth + "px");
domStyle.set(this.scrollContainer, lPos, "0");
domStyle.set(this.header, rPos, renderData.scrollbarWidth + "px");
domStyle.set(this.header, lPos, "0");
domStyle.set(this.subHeader, rPos, renderData.scrollbarWidth + "px");
domStyle.set(this.subHeader, lPos, "0");
if(this.buttonContainer && this.owner != null && this.owner.currentView == this){
domStyle.set(this.buttonContainer, rPos, renderData.scrollbarWidth + "px");
domStyle.set(this.buttonContainer, lPos, "0");
}
if(this.hScrollBar){
arr.forEach(this._hScrollNodes, function(elt){
domClass[renderData.hScrollBarEnabled ? "add" : "remove"](elt.parentNode, "dojoxCalendarHorizontalScroll");
}, this);
if(!renderData.hScrollBarEnabled){
this._setHScrollPosition(0);
this.hScrollBarW.set("value", 0);
}
domStyle.set(this.hScrollBar, {
"display": renderData.hScrollBarEnabled ? "block" : "none",
"height": renderData.scrollbarHeight + "px",
"left": (atRight ? renderData.rowHeaderWidth : renderData.scrollbarWidth) + "px",
"right": (atRight ? renderData.scrollbarWidth : renderData.rowHeaderWidth) + "px"
});
domStyle.set(this.scrollContainer, "bottom", renderData.hScrollBarEnabled ? (renderData.scrollbarHeight + 1) + "px" : "0");
this._configureHScrollDomNodes(renderData.hScrollBarEnabled ? renderData.minSheetWidth + "px" : "100%");
this.hScrollBarW.set("maximum", renderData.minSheetWidth);
this.hScrollBarW.set("containerSize", renderData.hScrollPaneWidth);
}
},
_configureHScrollDomNodes: function(styleWidth){
arr.forEach(this._hScrollNodes, function(elt){
domStyle.set(elt, "width", styleWidth);
}, this);
},
resize: function(e){
this._resizeHandler(e);
},
_resizeHandler: function(e, apply){
// summary:
// Refreshes the scroll bars after a resize of the widget.
// e: Event
// The resize event (optional)
// apply: Boolean
// Whether apply the changes or wait for 100 ms
// tags:
// private
var rd = this.renderData;
if(rd == null){
return;
}
if(apply){
var hScrollPaneWidth = domGeometry.getMarginBox(this.grid).w;
if(rd.hScrollPaneWidth != hScrollPaneWidth){
// refresh values
rd.hScrollPaneWidth = hScrollPaneWidth;
rd.minSheetWidth = this.minColumnWidth < 0 ? -1 : this.minColumnWidth * rd.subColumnCount * rd.columnCount;
rd.hScrollBarEnabled = this.minColumnWidth > 0 && domGeometry.getMarginBox(this.grid).w < rd.minSheetWidth;
}
this._configureScrollBar(rd);
}else{
if(this._resizeTimer != undefined){
clearTimeout(this._resizeTimer);
}
this._resizeTimer = setTimeout(lang.hitch(this, function(){
this._resizeHandler(e, true);
}), 100);
}
},
_columnHeaderClick: function(e){
// tags:
// private
event.stop(e);
var index = query("td", this.columnHeaderTable).indexOf(e.currentTarget);
this._onColumnHeaderClick({
index: index,
date: this.renderData.dates[index],
triggerEvent: e
});
},
_buildColumnHeader: function(renderData, oldRenderData){
// summary:
// Creates incrementally the HTML structure of the column header and configures its content.
//
// renderData:
// The render data to display.
//
// oldRenderData:
// The previously render data displayed, if any.
// tags:
// private
var table = this.columnHeaderTable;
if (!table){
return;
}
var count = renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0);
if(has("ie") == 8){
// workaround Internet Explorer 8 bug.
// if on the table, width: 100% and table-layout: fixed are set
// and columns are removed, width of remaining columns is not
// recomputed: must rebuild all.
if(this._colTableSave == null){
this._colTableSave = lang.clone(table);
}else if(count < 0){
this._cleanupColumnHeader();
this.columnHeader.removeChild(table);
domConstruct.destroy(table);
table = lang.clone(this._colTableSave);
this.columnHeaderTable = table;
this.columnHeader.appendChild(table);
count = renderData.columnCount;
}
} // else incremental dom add/remove for real browsers.
var tbodies = query("tbody", table);
var trs = query("tr", table);
var tbody, tr, td;
if (tbodies.length == 1){
tbody = tbodies[0];
}else{
tbody = html.create("tbody", null, table);
}
if (trs.length == 1){
tr = trs[0];
}else{
tr = domConstruct.create("tr", null, tbody);
}
// Build HTML structure (incremental)
if(count > 0){ // creation
for(var i=0; i < count; i++){
td = domConstruct.create("td", null, tr);
var h = [];
h.push(on(td, "click", lang.hitch(this, this._columnHeaderClick)));
if(has("touch-events")){
h.push(on(td, "touchstart", function(e){
event.stop(e);
domClass.add(e.currentTarget, "Active");
}));
h.push(on(td, "touchend", function(e){
event.stop(e);
domClass.remove(e.currentTarget, "Active");
}));
}else{
h.push(on(td, "mousedown", function(e){
event.stop(e);
domClass.add(e.currentTarget, "Active");
}));
h.push(on(td, "mouseup", function(e){
event.stop(e);
domClass.remove(e.currentTarget, "Active");
}));
h.push(on(td, "mouseover", function(e){
event.stop(e);
domClass.add(e.currentTarget, "Hover");
}));
h.push(on(td, "mouseout", function(e){
event.stop(e);
domClass.remove(e.currentTarget, "Hover");
}));
}
this._columnHeaderHandlers.push(h);
}
}else{ // deletion
count = -count;
for(var i=0; i < count; i++){
td = tr.lastChild;
tr.removeChild(td);
domConstruct.destroy(td);
var list = this._columnHeaderHandlers.pop();
while(list.length>0){
list.pop().remove();
}
}
}
// fill & configure
query("td", table).forEach(function(td, i){
td.className = "";
if(i == 0){
domClass.add(td, "first-child");
}else if(i == this.renderData.columnCount-1){
domClass.add(td, "last-child");
}
var d = renderData.dates[i];
this._setText(td, this._formatColumnHeaderLabel(d));
this.styleColumnHeaderCell(td, d, renderData);
}, this);
if(this.yearColumnHeaderContent){
var d = renderData.dates[0];
this._setText(this.yearColumnHeaderContent, renderData.dateLocaleModule.format(d,
{selector: "date", datePattern:"yyyy"}));
}
},
_cleanupColumnHeader: function(){
while(this._columnHeaderHandlers.length > 0){
var list = this._columnHeaderHandlers.pop();
while(list.length > 0){
list.pop().remove();
}
}
},
styleColumnHeaderCell: function(node, date, renderData){
// summary:
// Styles the CSS classes to the node that displays a column header cell.
// By default this method is setting:
// - "dojoxCalendarToday" class name if the date displayed is the current date,
// - "dojoxCalendarWeekend" if the date represents a weekend,
// - the CSS class corresponding of the displayed day of week ("Sun", "Mon" and so on).
// node: Node
// The DOM node that displays the column in the grid.
// date: Date
// The date displayed by this column
// renderData: Object
// The render data.
// tags:
// protected
domClass.add(node, this._cssDays[date.getDay()]);
if(this.isToday(date)){
domClass.add(node, "dojoxCalendarToday");
} else if(this.isWeekEnd(date)){