forked from damiengarbarino/dojo-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarBase.js
1659 lines (1439 loc) · 46.2 KB
/
CalendarBase.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([
"dojo/_base/declare",
"dojo/_base/sniff",
"dojo/_base/event",
"dojo/_base/lang",
"dojo/_base/array",
"dojo/cldr/supplemental",
"dojo/dom",
"dojo/dom-class",
"dojo/dom-style",
"dojo/dom-construct",
"dojo/dom-geometry",
"dojo/date",
"dojo/date/locale",
"dojo/_base/fx",
"dojo/fx",
"dojo/on",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"./StoreMixin",
"./StoreManager",
"dojox/widget/_Invalidating",
"dojox/widget/Selection",
"./time",
"dojo/i18n!./nls/buttons"],
function(
declare,
has,
event,
lang,
arr,
cldr,
dom,
domClass,
domStyle,
domConstruct,
domGeometry,
date,
locale,
coreFx,
fx,
on,
_WidgetBase,
_TemplatedMixin,
_WidgetsInTemplateMixin,
StoreMixin,
StoreManager,
_Invalidating,
Selection,
timeUtil,
_nls){
/*=====
var __HeaderClickEventArgs = {
// summary:
// A column click event.
// index: Integer
// The column index.
// date: Date
// The date displayed by the column.
// triggerEvent: Event
// The origin event.
};
=====*/
/*=====
var __TimeIntervalChangeArgs = {
// summary:
// An time interval change event, dispatched when the calendar displayed time range has changed.
// oldStartTime: Date
// The start of the previously displayed time interval, if any.
// startTime: Date
// The new start of the displayed time interval.
// oldEndTime: Date
// The end of the previously displayed time interval, if any.
// endTime: Date
// The new end of the displayed time interval.
};
=====*/
/*=====
var __GridClickEventArgs = {
// summary:
// The event dispatched when the grid is clicked or double-clicked.
// date: Date
// 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: dojox/calendar/_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: Date[]
// The computed date/time of the during the event editing. One entry per edited date (touch use case).
// startTime: Date?
// The start time of data item.
// endTime: Date?
// The end time of data item.
// sheet: String
// For views with several sheets (columns view for example), the sheet when the event occurred.
// source: dojox/calendar/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:
// A renderer lifecycle event.
// renderer: Object
// The renderer.
// source: dojox/calendar/ViewBase
// The view where the event occurred.
// item:Object?
// The item that will be displayed by the renderer for the "rendererCreated" and "rendererReused" events.
};
=====*/
/*=====
var __ExpandRendererClickEventArgs = {
// summary:
// A expand renderer click event.
// columnIndex: Integer
// The column index of the cell.
// rowIndex: Integer
// The row index of the cell.
// date: Date
// The date displayed by the cell.
// triggerEvent: Event
// The origin event.
};
=====*/
return declare("dojox.calendar.CalendarBase", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, StoreMixin, _Invalidating, Selection], {
// summary:
// This class defines a generic calendar widget that manages several views to display event in time.
baseClass: "dojoxCalendar",
// datePackage: Object
// JavaScript namespace to find Calendar routines. Uses Gregorian Calendar routines at dojo.date by default.
datePackage: date,
// startDate: Date
// The start date of the displayed time interval.
startDate: null,
// endDate: Date
// The end date of the displayed time interval (included).
endDate: null,
// date: Date
// The reference date used to determine along with the <code>dateInterval</code>
// and <code>dateIntervalSteps</code> properties the time interval to display.
date: null,
// minDate: Date
// The minimum date.
// If date property is set, the displayed time interval the most in the past
// will the time interval containing this date.
// If startDate property is set, this mininum value of startDate.
minDate: null,
// maxDate: Date
// The maximum date.
// If date is set, the displayed time interval the most in the future
// will the time interval containing this date.
// If endDate property is set, this mininum value of endDate.
maxDate: null,
// dateInterval:String
// The date interval used to compute along with the <code>date</code> and
// <code>dateIntervalSteps</code> the time interval to display.
// Valid values are "day", "week" (default value) and "month".
dateInterval: "week",
// dateIntervalSteps:Integer
// The number of date intervals used to compute along with the <code>date</code> and
// <code>dateInterval</code> the time interval to display.
// Default value is 1.
dateIntervalSteps: 1,
// viewContainer: Node
// The DOM node that will contains the views.
viewContainer: null,
// firstDayOfWeek: Integer
// (Optional) The first day of week override. By default the first day of week is determined
// for the current locale (extracted from the CLDR).
// Special value -1 (default value), means use locale dependent value.
firstDayOfWeek: -1,
// formatItemTimeFunc: 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.
formatItemTimeFunc: null,
// editable: Boolean
// A flag that indicates whether or not the user can edit
// items in the data provider.
// If <code>true</code>, the item renderers in the control are editable.
// The user can click on an item renderer, or use the keyboard or touch devices, to move or resize the associated event.
editable: true,
// moveEnabled: Boolean
// A flag that indicates whether the user can move items displayed.
// If <code>true</code>, the user can move the items.
moveEnabled: true,
// resizeEnabled: Boolean
// A flag that indicates whether the items can be resized.
// If <code>true</code>, the control supports resizing of items.
resizeEnabled: true,
// columnView: dojox/calendar/ColumnView
// The column view is displaying one day to seven days time intervals.
columnView: null,
// matrixView: dojox/calendar/MatrixView
// The column view is displaying time intervals that lasts more than seven days.
matrixView: null,
// columnViewProps: Object
// Map of property/value passed to the constructor of the column view.
columnViewProps: null,
// matrixViewProps: Object
// Map of property/value passed to the constructor of the matrix view.
matrixViewProps: null,
// createOnGridClick: Boolean
// Indicates whether the user can create new event by clicking and dragging the grid.
// A createItem function must be defined on the view or the calendar object.
createOnGridClick: false,
// createItemFunc: Function
// A user supplied function that creates a new event.
// This function is used when createOnGridClick is set to true and the user is clicking and dragging on the grid.
// This view takes two parameters:
//
// - view: the current view,
// - d: the date at the clicked location.
createItemFunc: null,
// currentView: ViewBase
// The current view displayed by the Calendar object.
// The currentViewChange event can be used to react on a view change.
currentView: null,
_currentViewIndex: -1,
_calendar: "gregorian",
constructor: function(/*Object*/args){
this.views = [];
this.invalidatingProperties = ["store", "items", "startDate", "endDate", "views",
"date", "minDate", "maxDate", "dateInterval", "dateIntervalSteps", "firstDayOfWeek"];
args = args || {};
this._calendar = args.datePackage ? args.datePackage.substr(args.datePackage.lastIndexOf(".")+1) : this._calendar;
this.dateModule = args.datePackage ? lang.getObject(args.datePackage, false) : date;
this.dateClassObj = this.dateModule.Date || Date;
this.dateLocaleModule = args.datePackage ? lang.getObject(args.datePackage+".locale", false) : locale;
this.invalidateRendering();
this.storeManager = new StoreManager({owner: this, _ownerItemsProperty: "items"});
this.storeManager.on("layoutInvalidated", lang.hitch(this, this._refreshItemsRendering));
this.storeManager.on("renderersInvalidated", lang.hitch(this, this._updateRenderers));
this.storeManager.on("dataLoaded", lang.hitch(this, function(items){
this.set("items", items);
}));
this.decorationStoreManager = new StoreManager({owner: this, _ownerItemsProperty: "decorationItems"});
this.decorationStoreManager.on("layoutInvalidated", lang.hitch(this, this._refreshDecorationItemsRendering));
this.decorationStoreManager.on("dataLoaded", lang.hitch(this, function(items){
this.set("decorationItems", items);
}));
},
buildRendering: function(){
this.inherited(arguments);
if(this.views == null || this.views.length == 0){
this.set("views", this._createDefaultViews());
}
},
_applyAttributes: function(){
this._applyAttr = true;
this.inherited(arguments);
delete this._applyAttr;
},
////////////////////////////////////////////////////
//
// Getter / setters
//
////////////////////////////////////////////////////
_setStartDateAttr: function(value){
this._set("startDate", value);
this._timeRangeInvalidated = true;
this._startDateChanged = true;
},
_setEndDateAttr: function(value){
this._set("endDate", value);
this._timeRangeInvalidated = true;
this._endDateChanged = true;
},
_setDateAttr: function(value){
this._set("date", value);
this._timeRangeInvalidated = true;
this._dateChanged = true;
},
_setDateIntervalAttr: function(value){
this._set("dateInterval", value);
this._timeRangeInvalidated = true;
},
_setDateIntervalStepsAttr: function(value){
this._set("dateIntervalSteps", value);
this._timeRangeInvalidated = true;
},
_setFirstDayOfWeekAttr: function(value){
this._set("firstDayOfWeek", value);
if(this.get("date") != null && this.get("dateInterval") == "week"){
this._timeRangeInvalidated = true;
}
},
_setTextDirAttr: function(value){
arr.forEach(this.views, function(view){
view.set("textDir", value);
});
},
///////////////////////////////////////////////////
//
// Validating
//
///////////////////////////////////////////////////
refreshRendering: function(){
// summary:
// Refreshes all the visual rendering of the calendar.
// tags:
// protected
this.inherited(arguments);
this._validateProperties();
},
_refreshItemsRendering: function(){
if(this.currentView){
this.currentView._refreshItemsRendering();
}
},
_updateRenderers: function(item){
if(this.currentView){
this.currentView.updateRenderers(item);
}
},
_refreshDecorationItemsRendering: function(){
if(this.currentView){
this.currentView._refreshDecorationItemsRendering();
}
},
resize: function(changeSize){
if(changeSize){
domGeometry.setMarginBox(this.domNode, changeSize);
}
if(this.currentView){
// must not pass the size, children are sized depending on the parent by CSS.
this.currentView.resize();
}
},
_validateProperties: function(){
// tags:
// private
var cal = this.dateModule;
var startDate = this.get("startDate");
var endDate = this.get("endDate");
var date = this.get("date");
if(this.firstDayOfWeek < -1 || this.firstDayOfWeek > 6){
this._set("firstDayOfWeek", 0);
}
var minDate = this.get("minDate");
var maxDate = this.get("maxDate");
if(minDate && maxDate){
if(cal.compare(minDate, maxDate) > 0){
var t = minDate;
this._set("minDate", maxDate);
this._set("maxDate", t);
}
}
if(date == null && (startDate != null || endDate != null)){
if(startDate == null){
startDate = new this.dateClassObj();
this._set("startDate", startDate);
this._timeRangeInvalidated = true;
}
if(endDate == null){
endDate = new this.dateClassObj();
this._set("endDate", endDate);
this._timeRangeInvalidated = true;
}
if(cal.compare(startDate, endDate) > 0){
endDate = cal.add(startDate, "day", 1);
this._set("endDate", endDate);
this._timeRangeInvalidated = true;
}
}else{
if(this.date == null){
this._set("date", new this.dateClassObj());
this._timeRangeInvalidated = true;
}
var dint = this.get("dateInterval");
if(dint != "day" && dint != "week" && dint != "month"){
this._set("dateInterval", "day");
this._timeRangeInvalidated = true;
}
var dis = this.get("dateIntervalSteps");
if(lang.isString(dis)){
dis = parseInt(dis);
this._set("dateIntervalSteps", dis);
}
if(dis <= 0) {
this.set("dateIntervalSteps", 1);
this._timeRangeInvalidated = true;
}
}
if(this._timeRangeInvalidated){
this._timeRangeInvalidated = false;
var timeInterval = this.computeTimeInterval();
if(this._timeInterval == null ||
cal.compare(this._timeInterval[0], timeInterval[0]) != 0 ||
cal.compare(this._timeInterval[1], timeInterval[1]) != 0){
if(this._dateChanged){
this._lastValidDate = this.get("date");;
this._dateChanged = false;
}else if(this._startDateChanged || this._endDateChanged){
this._lastValidStartDate = this.get("startDate");
this._lastValidEndDate = this.get("endDate");
this._startDateChanged = false;
this._endDateChanged = false;
}
this.onTimeIntervalChange({
oldStartTime: this._timeInterval == null ? null : this._timeInterval[0],
oldEndTime: this._timeInterval == null ? null : this._timeInterval[1],
startTime: timeInterval[0],
endTime: timeInterval[1]
});
}else{
if(this._dateChanged){
this._dateChanged = false;
if(this.lastValidDate != null){
this._set("date", this.lastValidDate);
}
}else if(this._startDateChanged || this._endDateChanged){
this._startDateChanged = false;
this._endDateChanged = false;
this._set("startDate", this._lastValidStartDate);
this._set("endDate", this._lastValidEndDate);
}
return;
}
this._timeInterval = timeInterval;
var duration = this.dateModule.difference(this._timeInterval[0], this._timeInterval[1], "day");
var view = this._computeCurrentView(timeInterval[0], timeInterval[1], duration);
var index = arr.indexOf(this.views, view);
if(view == null || index == -1){
return;
}
this._performViewTransition(view, index, timeInterval, duration);
}
},
_performViewTransition: function(view, index, timeInterval, duration){
var oldView = this.currentView;
if(this.animateRange && (!has("ie") || has("ie")>8) ){
if(oldView){ // there's a view to animate
oldView.beforeDeactivate();
var ltr = this.isLeftToRight();
var inLeft = this._animRangeInDir=="left" || this._animRangeInDir == null;
var outLeft = this._animRangeOutDir=="left" || this._animRangeOutDir == null;
this._animateRange(this.currentView.domNode, outLeft && ltr, false, 0, outLeft ? -100 : 100,
lang.hitch(this, function(){
oldView.afterDeactivate();
view.beforeActivate();
this.animateRangeTimer = setTimeout(lang.hitch(this, function(){
this._applyViewChange(view, index, timeInterval, duration);
this._animateRange(this.currentView.domNode, inLeft && ltr, true, inLeft ? -100 : 100, 0, function(){
view.afterActivate();
});
this._animRangeInDir = null;
this._animRangeOutDir = null;
}), 100); // setTimeout give time for layout of view.
}));
}else{
view.beforeActivate();
this._applyViewChange(view, index, timeInterval, duration);
view.afterActivate();
}
}else{
if(oldView){
oldView.beforeDeactivate();
}
view.beforeActivate();
this._applyViewChange(view, index, timeInterval, duration);
if(oldView){
oldView.afterDeactivate();
}
view.afterActivate();
}
},
onViewConfigurationChange: function(view){
// summary:
// Event dispatched when the view has been configured after the queried
// time range and before the current view is changed (if needed).
//
// view: ViewBase
// The view that has been configured.
// tags:
// callback
},
_applyViewChange: function(view, index, timeInterval, duration){
// summary:
// Applies the changes of a view time and changes the currently visible view if needed.
// view: ViewBase
// The view that is configured and is or will be shown.
// index: Integer
// The view index in the internal structure.
// timeInterval: Date[]
// The time interval displayed by the calendar.
// duration: Integer
// The duration in days of the time interval.
// tags:
// protected
this._configureView(view, index, timeInterval, duration);
this.onViewConfigurationChange(view);
if(index != this._currentViewIndex){
if(this.currentView == null){
view.set("items", this.items);
view.set("decorationItems", this.decorationItems);
this.set("currentView", view);
}else{
if(this.items == null || this.items.length == 0){
this.set("currentView", view);
if(this.animateRange && (!has("ie") || has("ie")>8) ){
domStyle.set(this.currentView.domNode, "opacity", 0);
}
view.set("items", this.items);
view.set("decorationItems", this.decorationItems);
}else{
this.currentView = view;
view.set("items", this.items);
view.set("decorationItems", this.decorationItems);
this.set("currentView", view);
if(this.animateRange && (!has("ie") || has("ie")>8) ){
domStyle.set(this.currentView.domNode, "opacity", 0);
}
}
}
}
},
_timeInterval: null,
computeTimeInterval: function(){
var d = this.get("date");
var minDate = this.get("minDate");
var maxDate = this.get("maxDate");
var cal = this.dateModule;
if(d == null){
var startDate = this.get("startDate");
var endDate = cal.add(this.get("endDate"), "day", 1);
if(minDate != null || maxDate != null){
var dur = this.dateModule.difference(startDate, endDate, "day");
if(cal.compare(minDate, startDate) > 0){
startDate = minDate;
endDate = cal.add(startDate, "day", dur);
}
if(cal.compare(maxDate, endDate) < 0){
endDate = maxDate;
startDate = cal.add(endDate, "day", -dur);
}
if(cal.compare(minDate, startDate) > 0){
startDate = minDate;
endDate = maxDate;
}
}
return [ this.floorToDay(startDate), this.floorToDay(endDate) ];
}else{
var interval = this._computeTimeIntervalImpl(d);
if(minDate != null){
var minInterval = this._computeTimeIntervalImpl(minDate);
if(cal.compare(minInterval[0], interval[0]) > 0){
interval = minInterval;
}
}
if(maxDate != null){
var maxInterval = this._computeTimeIntervalImpl(maxDate);
if(cal.compare(maxInterval[1], interval[1]) < 0){
interval = maxInterval;
}
}
return interval;
}
},
_computeTimeIntervalImpl: function(d){
// summary:
// Computes the displayed time interval according to the date, dateInterval and
// dateIntervalSteps if date is not null or startDate and endDate properties otherwise.
// tags:
// protected
var cal = this.dateModule;
var s = this.floorToDay(d);
var di = this.get("dateInterval");
var dis = this.get("dateIntervalSteps");
var e;
switch(di){
case "day":
e = cal.add(s, "day", dis);
break;
case "week":
s = this.floorToWeek(s);
e = cal.add(s, "week", dis);
break;
case "month":
s.setDate(1);
e = cal.add(s, "month", dis);
break;
default:
e = cal.add(s, "day", 1);
}
return [s, e];
},
onTimeIntervalChange: function(e){
// summary:
// Event dispatched when the displayed time interval has changed.
// e: __TimeIntervalChangeArgs
// The time interval change event.
// tags:
// callback
},
/////////////////////////////////////////////////////
//
// View Management
//
/////////////////////////////////////////////////////
// views: dojox.calendar.ViewBase[]
// The views displayed by the widget.
// To add/remove only one view, prefer, respectively, the addView() or removeView() methods.
views: null,
_setViewsAttr: function(views){
if(!this._applyAttr){
// 1/ in create() the constructor parameters are mixed in the widget
// 2/ in _applyAttributes(), every property with a setter is called.
// So no need to call on view removed for a non added view....
for(var i=0;i<this.views.length;i++){
this._onViewRemoved(this.views[i]);
}
}
if(views != null){
for(var i=0;i<views.length;i++){
this._onViewAdded(views[i]);
}
}
this._set("views", views == null ? [] : views.concat());
},
_getViewsAttr: function(){
return this.views.concat();
},
_createDefaultViews: function(){
// summary:
// Creates the default views.
// This method does nothing and is designed to be overridden.
// tags:
// protected
},
addView: function(view, index){
// summary:
// Add a view to the calendar's view list.
// view: dojox/calendar/ViewBase
// The view to add to the calendar.
// index: Integer
// Optional, the index where to insert the view in current view list.
// tags:
// protected
if(index <= 0 || index > this.views.length){
index = this.views.length;
}
this.views.splice(index, view);
this._onViewAdded(view);
},
removeView: function(view){
// summary:
// Removes a view from the calendar's view list.
// view: dojox/calendar/ViewBase
// The view to remove from the calendar.
// tags:
// protected
if(index < 0 || index >= this.views.length){
return;
}
this._onViewRemoved(this.views[index]);
this.views.splice(index, 1);
},
_onViewAdded: function(view){
view.owner = this;
view.buttonContainer = this.buttonContainer;
view._calendar = this._calendar;
view.datePackage = this.datePackage;
view.dateModule = this.dateModule;
view.dateClassObj = this.dateClassObj;
view.dateLocaleModule = this.dateLocaleModule;
domStyle.set(view.domNode, "display", "none");
domClass.add(view.domNode, "view");
domConstruct.place(view.domNode, this.viewContainer);
this.onViewAdded(view);
},
onViewAdded: function(view){
// summary:
// Event dispatched when a view is added from the calendar.
// view: dojox/calendar/ViewBase
// The view that has been added to the calendar.
// tags:
// callback
},
_onViewRemoved: function(view){
view.owner = null;
view.buttonContainer = null;
domClass.remove(view.domNode, "view");
this.viewContainer.removeChild(view.domNode);
this.onViewRemoved(view);
},
onViewRemoved: function(view){
// summary:
// Event dispatched when a view is removed from the calendar.
// view: dojox/calendar/ViewBase
// The view that has been removed from the calendar.
// tags:
// callback
},
_setCurrentViewAttr: function(view){
var index = arr.indexOf(this.views, view);
if(index != -1){
var oldView = this.get("currentView");
this._currentViewIndex = index;
this._set("currentView", view);
this._showView(oldView, view);
this.onCurrentViewChange({
oldView: oldView,
newView: view
});
}
},
_getCurrentViewAttr: function(){
return this.views[this._currentViewIndex];
},
onCurrentViewChange: function(e){
// summary:
// Event dispatched when the current view has changed.
// e: Event
// Object that contains the oldView and newView properties.
// tags:
// callback
},
_configureView: function(view, index, timeInterval, duration){
// summary:
// Configures the view to show the specified time interval.
// This method is computing and setting the following properties:
// - "startDate", "columnCount" for a column view,
// - "startDate", "columnCount", "rowCount", "refStartTime" and "refEndTime" for a matrix view.
// This method can be extended to configure other properties like layout properties for example.
// view: dojox/calendar/ViewBase
// The view to configure.
// index: Integer
// The index of the view in the Calendar view list.
// timeInterval: Date[]
// The time interval that will be displayed by the view.
// duration: Integer
// The duration, in days, of the displayed time interval.
// tags:
// protected
var cal = this.dateModule;
if(view.viewKind == "columns"){
view.set("startDate", timeInterval[0]);
view.set("columnCount", duration);
}else if(view.viewKind == "matrix"){
if(duration > 7){ // show only full weeks.
var s = this.floorToWeek(timeInterval[0]);
var e = this.floorToWeek(timeInterval[1]);
if(cal.compare(e, timeInterval[1]) != 0){
e = this.dateModule.add(e, "week", 1);
}
duration = this.dateModule.difference(s, e, "day");
view.set("startDate", s);
view.set("columnCount", 7);
view.set("rowCount", Math.ceil(duration/7));
view.set("refStartTime", timeInterval[0]);
view.set("refEndTime", timeInterval[1]);
}else{
view.set("startDate", timeInterval[0]);
view.set("columnCount", duration);
view.set("rowCount", 1);
view.set("refStartTime", null);
view.set("refEndTime", null);
}
}
},
_computeCurrentView: function(startDate, endDate, duration){
// summary:
// If the time range is lasting less than seven days returns the column view or the matrix view otherwise.
// startDate: Date
// The start date of the displayed time interval
// endDate: Date
// The end date of the displayed time interval
// duration: Integer
// Duration of the
// returns: dojox/calendar/ViewBase
// The view to display.
// tags:
// protected
return duration <= 7 ? this.columnView : this.matrixView;
},
matrixViewRowHeaderClick: function(e){
// summary:
// Function called when the cell of a row header of the matrix view is clicked.
// The implementation is doing the foolowing actions:
// - If another row is already expanded, collapse it and then expand the clicked row.
// - If the clicked row is already expadned, collapse it.
// - If no row is expanded, expand the click row.
// e: Object
// The row header click event.
// tags:
// protected
var expIndex = this.matrixView.getExpandedRowIndex();
if(expIndex == e.index){
this.matrixView.collapseRow();
}else if(expIndex == -1){
this.matrixView.expandRow(e.index);
}else{
var h = this.matrixView.on("expandAnimationEnd", lang.hitch(this, function(){
h.remove();
this.matrixView.expandRow(e.index);
}));
this.matrixView.collapseRow();
}
},
columnViewColumnHeaderClick: function(e){
// summary:
// Function called when the cell of a column header of the column view is clicked.
// Show the time range defined by the clicked date.
// e: Object
// The column header click event.
// tags:
// protected
var cal = this.dateModule;
if(cal.compare(e.date, this._timeInterval[0]) == 0 && this.dateInterval == "day" && this.dateIntervalSteps == 1){
this.set("dateInterval", "week");
}else{
this.set("date", e.date);
this.set("dateInterval", "day");
this.set("dateIntervalSteps", 1);
}
},
// viewFadeDuration: Integer
// The duration in milliseconds of the fade animation when the current view is changing.
viewChangeDuration: 0,
_showView: function(oldView, newView){
// summary:
// Displays the current view.
// oldView: dojox/calendar/ViewBase
// The previously displayed view or null.
// newView: dojox/calendar/ViewBase
// The view to display.
// tags:
// protected
if(oldView != null){
domStyle.set(oldView.domNode, "display", "none");
}
if(newView != null){
domStyle.set(newView.domNode, "display", "block");
newView.resize();
if(!has("ie") || has("ie") > 7){