Debian Codegraph @

dojox/calendar/SimpleColumnView.js

raw symbols SCIP
1 define([
2 "./ViewBase",
3 "dijit/_TemplatedMixin",
4 "./_ScrollBarBase",
5 "dojo/text!./templates/ColumnView.html",
6 "dojo/_base/declare",
7 "dojo/_base/event",
8 "dojo/_base/lang",
9 "dojo/_base/array",
10 "dojo/_base/sniff",
11 "dojo/_base/fx",
12 "dojo/_base/html",
13 "dojo/on",
14 "dojo/dom",
15 "dojo/dom-class",
16 "dojo/dom-style",
17 "dojo/dom-geometry",
18 "dojo/dom-construct",
19 "dojo/mouse",
20 "dojo/query",
21 "dojox/html/metrics"],
22
23 function(
24 ViewBase,
25 _TemplatedMixin,
26 _ScrollBarBase,
27 template,
28 declare,
29 event,
30 lang,
31 arr,
32 has,
33 fx,
34 html,
35 on,
36 dom,
37 domClass,
38 domStyle,
39 domGeometry,
40 domConstruct,
41 mouse,
42 query,
43 metrics){
44
45 /*=====
46 var __ColumnClickEventArgs = {
47 // summary:
48 // A column click event.
49 // index: Integer
50 // The column index.
51 // date: Date
52 // The date displayed by the column.
53 // triggerEvent: Event
54 // The origin event.
55 };
56 =====*/
57
58 return declare("dojox.calendar.SimpleColumnView", [ViewBase, _TemplatedMixin], {
59
60 // summary:
61 // The simple column view is displaying a day per column. Each cell of a column is a time slot.
62
63 baseClass: "dojoxCalendarColumnView",
64
65 templateString: template,
66
67 // viewKind: String
68 // Type of the view. Used by the calendar widget to determine how to configure the view.
69 // This view kind is "columns".
70 viewKind: "columns",
71
72 // scroll container is the focusable item to enable scrolling using up and down arrows
73 _setTabIndexAttr: "domNode",
74
75 // renderData: Object
76 // The render data is the object that contains all the properties needed to render the component.
77 renderData: null,
78
79 // startDate: Date
80 // The start date of the time interval displayed.
81 // If not set at initialization time, will be set to current day.
82 startDate: null,
83
84 // columnCount: Integer
85 // The number of column to display (from the startDate).
86 columnCount: 7,
87
88 // subcolumns: String[]
89 // Array of sub columns values.
90 subColumns: null,
91
92 // minHours: Integer
93 // The minimum hour to be displayed. It must be in the [0,23] interval and must be lower than the maxHours.
94 minHours: 8,
95
96 // maxHours: Integer
97 // The maximum hour to be displayed. It must be in the [1,36] interval and must be greater than the minHours.
98 maxHours: 18,
99
100 // hourSize: Integer
101 // The desired size in pixels of an hour on the screen.
102 // Note that the effective size may be different as the time slot size must be an integer.
103 hourSize: 100,
104
105 // timeSlotDuration: Integer
106 // Duration of the time slot in minutes. Must be a divisor of 60.
107 timeSlotDuration: 15,
108
109 // rowHeaderGridSlotDuration: Integer
110 // Duration of the time slot in minutes in the row header. Must be a divisor of 60 and a multiple/divisor of timeSlotDuration.
111 rowHeaderGridSlotDuration: 60,
112
113 // rowHeaderLabelSlotDuration: Integer
114 // Duration of the time slot in minutes in the row header labels. Must be a divisor of 60 and a multiple/divisor of timeSlotDuration.
115 rowHeaderLabelSlotDuration: 60,
116
117 // rowHeaderLabelOffset: Integer
118 // Offset of the row label from the top of the row header cell in pixels.
119 rowHeaderLabelOffset: 2,
120
121 // rowHeaderFirstLabelOffset: Integer
122 // Offset of the first row label from the top of the first row header cell in pixels.
123 rowHeaderFirstLabelOffset: 2,
124
125 // verticalRenderer: Class
126 // The class use to create vertical renderers.
127 verticalRenderer: null,
128
129 // verticalDecorationRenderer: Class
130 // The class use to create decoration renderers.
131 verticalDecorationRenderer: null,
132
133 // minColumnWidth: Integer
134 // The minimum column width. If the number of columns and sub columns displayed makes the
135 // width of a column greater than this property, a horizontal scroll bar is displayed.
136 // If value <= 0, this constraint is ignored and the columns are using the available space.
137 minColumnWidth: -1,
138
139 // percentOverlap: Integer
140 // The percentage of the renderer width used to superimpose one item renderer on another
141 // when two events are overlapping.
142 percentOverlap: 70,
143
144 // horizontalGap: Integer
145 // The number of pixels between two item renderers that are overlapping each other if the percentOverlap property is 0.
146 horizontalGap: 4,
147
148 _showSecondarySheet: false,
149
150 _columnHeaderHandlers: null,
151
152 constructor: function(){
153 this.invalidatingProperties = ["columnCount", "startDate", "minHours", "maxHours", "hourSize", "verticalRenderer", "verticalDecorationRenderer",
154 "rowHeaderTimePattern", "columnHeaderDatePattern", "timeSlotDuration", "rowHeaderGridSlotDuration", "rowHeaderLabelSlotDuration",
155 "rowHeaderLabelOffset", "rowHeaderFirstLabelOffset","percentOverlap", "horizontalGap", "scrollBarRTLPosition","itemToRendererKindFunc",
156 "layoutPriorityFunction", "formatItemTimeFunc", "textDir", "items", "subColumns", "minColumnWidth"];
157 this._columnHeaderHandlers = [];
158 },
159
160 destroy: function(preserveDom){
161 this._cleanupColumnHeader();
162 if(this.scrollBar){
163 this.scrollBar.destroy(preserveDom);
164 }
165 this.inherited(arguments);
166 },
167
168 _scrollBar_onScroll: function(value){
169 this._setScrollPosition(value);
170 },
171
172 _hscrollBar_onScroll: function(value){
173 this._setHScrollPosition(value);
174 },
175
176 buildRendering: function(){
177 this.inherited(arguments);
178 if(this.vScrollBar){
179 this.scrollBar = new _ScrollBarBase(
180 {content: this.vScrollBarContent},
181 this.vScrollBar);
182
183 this.scrollBar.on("scroll", lang.hitch(this, this._scrollBar_onScroll));
184 }
185
186 if(this.hScrollBar){
187 this.hScrollBarW = new _ScrollBarBase(
188 {content: this.hScrollBarContent, direction: "horizontal", value: 0},
189 this.hScrollBar);
190
191 this.hScrollBarW.on("scroll", lang.hitch(this, this._hscrollBar_onScroll));
192
193 this._hScrollNodes = [this.columnHeaderTable, this.subColumnHeaderTable, this.gridTable, this.itemContainerTable];
194 }
195
196 this._viewHandles.push(
197 on(this.scrollContainer, mouse.wheel,
198 dojo.hitch(this, this._mouseWheelScrollHander)));
199
200
201 },
202
203 postscript: function(){
204 this.inherited(arguments);
205 this._initialized = true;
206 if(!this.invalidRendering){
207 this.refreshRendering();
208 }
209 },
210
211 _setVerticalRendererAttr: function(value){
212 this._destroyRenderersByKind("vertical");
213 this._set("verticalRenderer", value);
214 },
215
216 _createRenderData: function(){
217
218 var rd = {};
219
220 rd.minHours = this.get("minHours");
221 rd.maxHours = this.get("maxHours");
222 rd.hourSize = this.get("hourSize");
223 rd.hourCount = rd.maxHours - rd.minHours;
224 rd.slotDuration = this.get("timeSlotDuration"); // must be consistent with previous statement
225 rd.rowHeaderGridSlotDuration = this.get("rowHeaderGridSlotDuration");
226 rd.slotSize = Math.ceil(rd.hourSize / (60 / rd.slotDuration));
227 rd.hourSize = rd.slotSize * (60 / rd.slotDuration);
228 rd.sheetHeight = rd.hourSize * rd.hourCount;
229
230 if(!this._rowHeaderWidth){
231 this._rowHeaderWidth = domGeometry.getMarginBox(this.rowHeader).w;
232 }
233 rd.rowHeaderWidth = this._rowHeaderWidth;
234
235 var sbMetrics = metrics.getScrollbar();
236 rd.scrollbarWidth = sbMetrics.w + 1;
237 rd.scrollbarHeight = sbMetrics.h + 1;
238
239 rd.dateLocaleModule = this.dateLocaleModule;
240 rd.dateClassObj = this.dateClassObj;
241 rd.dateModule = this.dateModule; // arithmetics on Dates
242
243 rd.dates = [];
244
245 rd.columnCount = this.get("columnCount");
246 rd.subColumns = this.get("subColumns");
247 rd.subColumnCount = rd.subColumns ? rd.subColumns.length : 1;
248
249 rd.hScrollPaneWidth = domGeometry.getMarginBox(this.grid).w;
250 rd.minSheetWidth = this.minColumnWidth < 0 ? -1 : this.minColumnWidth * rd.subColumnCount * rd.columnCount;
251 rd.hScrollBarEnabled = this.minColumnWidth > 0 && rd.hScrollPaneWidth < rd.minSheetWidth;
252
253 var d = this.get("startDate");
254
255 if (d == null){
256 d = new rd.dateClassObj();
257 }
258
259 d = this.floorToDay(d, false, rd);
260
261 this.startDate = d;
262
263 for(var col = 0; col < rd.columnCount ; col++){
264 rd.dates.push(d);
265 d = this.addAndFloor(d, "day", 1);
266 }
267
268 rd.startTime = new rd.dateClassObj(rd.dates[0]);
269 rd.startTime.setHours(rd.minHours);
270 rd.endTime = new rd.dateClassObj(rd.dates[rd.columnCount-1]);
271 rd.endTime.setHours(rd.maxHours);
272
273 if(this.displayedItemsInvalidated && !this._isEditing){
274 // while editing in no live layout we must not to recompute items (duplicate renderers)
275 rd.items = this.storeManager._computeVisibleItems(rd);
276
277 }else if (this.renderData){
278 rd.items = this.renderData.items;
279 }
280
281 if(this.displayedDecorationItemsInvalidated){
282 // while editing in no live layout we must not to recompute items (duplicate renderers)
283 rd.decorationItems = this.decorationStoreManager._computeVisibleItems(rd);
284
285 }else if (this.renderData){
286 rd.decorationItems = this.renderData.decorationItems;
287 }
288
289 return rd;
290 },
291
292 _validateProperties: function() {
293
294 this.inherited(arguments);
295
296 var v = this.minHours;
297 if(v < 0 || v>23 || isNaN(v)){
298 this.minHours = 0;
299 }
300 v = this.maxHours;
301 if (v < 1 || v>36 || isNaN(v)){
302 this.minHours = 36;
303 }
304
305 if(this.minHours > this.maxHours){
306 var t = this.maxHours;
307 this.maxHours = this.minHours;
308 this.minHours = t;
309 }
310 if (this.maxHours - this.minHours < 1){
311 this.minHours = 0;
312 this.maxHours = 24;
313 }
314 if (this.columnCount<1 || isNaN(this.columnCount)){
315 this.columnCount = 1;
316 }
317
318 v = this.percentOverlap;
319 if(v < 0 ||v > 100 || isNaN(v)){
320 this.percentOverlap = 70;
321 }
322 if(this.hourSize<5 || isNaN(this.hourSize)){
323 this.hourSize = 10;
324 }
325 v = this.timeSlotDuration;
326 if (v < 1 || v > 60 || isNaN(v)) {
327 this.timeSlotDuration = 15;
328 }
329 },
330
331 _setStartDateAttr: function(value){
332 this.displayedItemsInvalidated = true;
333 this._set("startDate", value);
334 },
335
336 _setColumnCountAttr: function(value){
337 this.displayedItemsInvalidated = true;
338 this._set("columnCount", value);
339 },
340
341 __fixEvt:function(e){
342 // tags:
343 // private
344 e.sheet = "primary";
345 e.source = this;
346 return e;
347 },
348
349 //////////////////////////////////////////
350 //
351 // Formatting functions
352 //
353 //////////////////////////////////////////
354
355 // rowHeaderTimePattern: String
356 // Custom date/time pattern for the row header labels to override default one coming from the CLDR.
357 // See dojo/date/locale documentation for format string.
358 rowHeaderTimePattern: null,
359
360 _formatRowHeaderLabel: function(/*Date*/d){
361 // summary:
362 // Computes the row header label for the specified time of day.
363 // By default a formatter is used, optionally the <code>rowHeaderTimePattern</code> property can be used to set a custom time pattern to the formatter.
364 // d: Date
365 // The date to format
366 // tags:
367 // protected
368
369 return this.renderData.dateLocaleModule.format(d, {
370 selector: "time",
371 timePattern: this.rowHeaderTimePattern
372 });
373 },
374
375 // columnHeaderDatePattern: String
376 // Custom date/time pattern for column header labels to override default one coming from the CLDR.
377 // See dojo/date/locale documentation for format string.
378 columnHeaderDatePattern: null,
379
380 _formatColumnHeaderLabel: function(/*Date*/d){
381 // summary:
382 // Computes the column header label for the specified date.
383 // By default a formatter is used, optionally the <code>columnHeaderDatePattern</code> property can be used to set a custom date pattern to the formatter.
384 // d: Date
385 // The date to format
386 // tags:
387 // protected
388
389 return this.renderData.dateLocaleModule.format(d, {
390 selector: "date",
391 datePattern: this.columnHeaderDatePattern,
392 formatLength: "medium"
393 });
394 },
395
396 //////////////////////////////////////////
397 //
398 // Time of day management
399 //
400 //////////////////////////////////////////
401
402 // scrollBarRTLPosition: String
403 // Position of the scroll bar in right-to-left display.
404 // Valid values are "left" and "right", default value is "left".
405 scrollBarRTLPosition: "left",
406
407 _getStartTimeOfDay: function(){
408 // summary:
409 // Returns the visible first time of day.
410 // tags:
411 // protected
412 // returns: Object
413
414 var v = (this.get("maxHours") - this.get("minHours")) *
415 this._getScrollPosition() / this.renderData.sheetHeight;
416
417 return {
418 hours: this.renderData.minHours + Math.floor(v),
419 minutes: (v - Math.floor(v)) * 60
420 };
421 },
422
423 _getEndTimeOfDay: function(){
424 // summary:
425 // Returns the visible last time of day.
426 // tags:
427 // protected
428 // returns: Integer[]
429
430 var v = (this.get("maxHours") - this.get("minHours")) *
431 (this._getScrollPosition() + this.scrollContainer.offsetHeight) / this.renderData.sheetHeight;
432
433 return {
434 hours: this.renderData.minHours + Math.floor(v),
435 minutes: (v - Math.floor(v)) * 60
436 };
437 },
438
439 // startTimeOfDay: Object
440 // First time (hour/minute) of day displayed, if reachable.
441 // An object containing "hours" and "minutes" properties.
442 startTimeOfDay: 0,
443
444 _setStartTimeOfDayAttr: function(value){
445 if(this.renderData){
446 this._setStartTimeOfDay(value.hours, value.minutes, value.duration, value.easing);
447 }else{
448 this._startTimeOfDayInvalidated = true;
449 }
450 this._set("startTimeOfDay", value);
451
452 },
453
454 _getStartTimeOfDayAttr: function(){
455 if(this.renderData){
456 return this._getStartTimeOfDay();
457 }else{
458 return this._get("startTimeOfDay");
459 }
460 },
461
462 _setStartTimeOfDay: function(hour, minutes, maxDuration, easing){
463 // summary:
464 // Scrolls the view to show the specified first time of day.
465 // hour: Integer
466 // The hour of the start time of day.
467 // minutes: Integer
468 // The minutes part of the start time of day.
469 // maxDuration: Integer
470 // The max duration of the scroll animation.
471 // tags:
472 // protected
473
474 var rd = this.renderData;
475
476 hour = hour || rd.minHours;
477 minutes = minutes || 0;
478 maxDuration = maxDuration || 0;
479
480 if (minutes < 0){
481 minutes = 0;
482 }else if (minutes > 59){
483 minutes = 59;
484 }
485
486 if (hour < 0){
487 hour = 0;
488 }else if (hour > rd.maxHours){
489 hour = rd.maxHours;
490 }
491
492 var timeInMinutes = hour * 60 + minutes;
493
494 var minH = rd.minHours*60;
495 var maxH = rd.maxHours*60;
496
497 if (timeInMinutes < minH){
498 timeInMinutes = minH;
499 }else if(timeInMinutes > maxH){
500 timeInMinutes = maxH;
501 }
502
503 var pos = (timeInMinutes - minH) * rd.sheetHeight / (maxH - minH);
504 pos = Math.min(rd.sheetHeight - this.scrollContainer.offsetHeight, pos);
505
506 this._scrollToPosition(pos, maxDuration, easing);
507 },
508
509 _scrollToPosition: function(position, maxDuration, easing){
510 // summary:
511 // Scrolls the view to show the specified first time of day.
512 // position: Integer
513 // The position in pixels.
514 // maxDuration: Integer
515 // The max duration of the scroll animation.
516 // tags:
517 // protected
518
519 if (maxDuration) {
520
521 if(this._scrollAnimation){
522 this._scrollAnimation.stop();
523 }
524
525 var scrollPos = this._getScrollPosition();
526
527 var duration = Math.abs(((position - scrollPos) * maxDuration) / this.renderData.sheetHeight);
528
529 this._scrollAnimation = new fx.Animation({
530 curve: [scrollPos, position],
531 duration: duration,
532 easing: easing,
533 onAnimate: lang.hitch(this, function(position) {
534 this._setScrollImpl(position);
535 })
536 });
537
538 this._scrollAnimation.play();
539
540 }else{
541 this._setScrollImpl(position);
542 }
543 },
544
545 _setScrollImpl: function(v){
546 this._setScrollPosition(v);
547 if(this.scrollBar){
548 this.scrollBar.set("value", v);
549 }
550 },
551
552 ensureVisibility: function(start, end, visibilityTarget, margin, duration){
553
554 // summary:
555 // Scrolls the view if the [start, end] time range is not visible or only partially visible.
556 // start: Date
557 // Start time of the range of interest.
558 // end: Date
559 // End time of the range of interest.
560 // margin: Integer
561 // Margin in minutes around the time range.
562 // visibilityTarget: String
563 // The end(s) of the time range to make visible.
564 // Valid values are: "start", "end", "both".
565 // duration: Number
566 // Optional, the maximum duration of the scroll animation.
567
568 margin = margin == undefined ? this.renderData.slotDuration : margin;
569
570 if(this.scrollable && this.autoScroll){
571
572 var s = start.getHours() * 60 + start.getMinutes() - margin;
573 var e = end.getHours() * 60 + end.getMinutes() + margin;
574
575 var vs = this._getStartTimeOfDay();
576 var ve = this._getEndTimeOfDay();
577
578 var viewStart = vs.hours * 60 + vs.minutes;
579 var viewEnd = ve.hours * 60 + ve.minutes;
580
581 var visible = false;
582 var target = null;
583
584 switch(visibilityTarget){
585 case "start":
586 visible = s >= viewStart && s <= viewEnd;
587 target = s ;
588 break;
589 case "end":
590 visible = e >= viewStart && e <= viewEnd;
591 target = e - (viewEnd - viewStart);
592 break;
593 case "both":
594 visible = s >= viewStart && e <= viewEnd;
595 target = s;
596 break;
597 }
598
599 if(!visible){
600 this._setStartTimeOfDay(Math.floor(target/60), target%60, duration);
601 }
602 }
603 },
604
605 scrollView: function(dir){
606 // summary:
607 // Scrolls the view to the specified direction of one time slot duration.
608 // dir: Integer
609 // Direction of the scroll. Valid values are -1 and 1.
610 //
611 var t = this._getStartTimeOfDay();
612 t = t.hours*60 + t.minutes + (dir * this.timeSlotDuration);
613 this._setStartTimeOfDay(Math.floor(t/60), t%60);
614 },
615
616 scrollViewHorizontal: function(dir){
617 // summary:
618 // Scrolls the view horizontally to the specified direction of one column or sub column (if set).
619 // dir: Integer
620 // Direction of the scroll. Valid values are -1 and 1.
621 //
622 this._setHScrollPosition(this._getHScrollPosition() + (dir * this.minColumnWidth));
623 if(this.hScrollBarW){
624 this.hScrollBarW.set("value", this._getHScrollPosition());
625 }
626 },
627
628 _hScrollNodes: null,
629
630 _setHScrollPositionImpl: function(pos, useDom, cssProp){
631 var elts = [this.columnHeaderTable, this.subColumnHeaderTable, this.gridTable, this.itemContainerTable];
632 var css = useDom ? null : "translateX(-"+pos+"px)";
633 arr.forEach(elts, function(elt){
634 if(useDom){
635 elt.scrollLeft = pos;
636 domStyle.set(elt, "left", (-pos) + "px");
637 }else{
638 domStyle.set(elt, cssProp, css);
639 }
640 }, this);
641 },
642
643 _mouseWheelScrollHander: function(e){
644 // summary:
645 // Mouse wheel handler.
646 // tags:
647 // protected
648 if(this.renderData.hScrollBarEnabled && e.altKey){
649 this.scrollViewHorizontal(e.wheelDelta > 0 ? -1 : 1);
650 }else{
651 this.scrollView(e.wheelDelta > 0 ? -1 : 1);
652 }
653 event.stop(e);
654 },
655
656 //////////////////////////////////////////
657 //
658 // HTML structure management
659 //
660 //////////////////////////////////////////
661
662 refreshRendering: function(){
663 if(!this._initialized){
664 return;
665 }
666
667 this._validateProperties();
668
669 var oldRd = this.renderData;
670 var rd = this._createRenderData();
671 this.renderData = rd;
672 this._createRendering(rd, oldRd);
673 this._layoutDecorationRenderers(rd);
674 this._layoutRenderers(rd);
675 },
676
677 _createRendering: function(/*Object*/renderData, /*Object*/oldRenderData){
678 // tags:
679 // private
680 domStyle.set(this.sheetContainer, "height", renderData.sheetHeight + "px");
681 // padding for the scroll bar.
682 this._configureVisibleParts(renderData);
683 this._configureScrollBar(renderData);
684 this._buildColumnHeader(renderData, oldRenderData);
685 this._buildSubColumnHeader(renderData, oldRenderData);
686 this._buildRowHeader(renderData, oldRenderData);
687 this._buildGrid(renderData, oldRenderData);
688 this._buildItemContainer(renderData, oldRenderData);
689 this._layoutTimeIndicator(renderData);
690 this._commitProperties(renderData);
691 },
692
693 _configureVisibleParts: function(renderData){
694
695 if(this.secondarySheetNode){
696 domStyle.set(this.secondarySheetNode, "display", this._showSecondarySheet ? "block" : "none");
697 }
698
699 domClass[this.subColumns == null?"remove":"add"](this.domNode, "subColumns");
700 domClass[this._showSecondarySheet?"add":"remove"](this.domNode, "secondarySheet");
701 },
702
703 _commitProperties: function(renderData){
704 if(this._startTimeOfDayInvalidated){
705 this._startTimeOfDayInvalidated = false;
706 var v = this.startTimeOfDay;
707 if(v != null){
708 this._setStartTimeOfDay(v.hours, v.minutes == undefined ? 0 : v.minutes); // initial position, no animation
709 }
710 }
711 },
712
713 _configureScrollBar: function(renderData){
714 // summary:
715 // Sets the scroll bar size and position.
716 // renderData: Object
717 // The render data.
718 // tags:
719 // protected
720
721 if(has("ie") && this.scrollBar){
722 domStyle.set(this.vScrollBar, "width", (renderData.scrollbarWidth + 1) + "px");
723 }
724
725 var atRight = this.isLeftToRight() ? true : this.scrollBarRTLPosition == "right";
726 var rPos = atRight ? "right" : "left";
727 var lPos = atRight ? "left" : "right";
728
729 if(this.scrollBar){
730 this.scrollBar.set("maximum", renderData.sheetHeight);
731 domStyle.set(this.vScrollBar, rPos, 0);
732 domStyle.set(this.vScrollBar, atRight? "left" : "right", "auto");
733 domStyle.set(this.vScrollBar, "bottom", renderData.hScrollBarEnabled? renderData.scrollbarHeight + "px" : "0");
734 }
735 domStyle.set(this.scrollContainer, rPos, renderData.scrollbarWidth + "px");
736 domStyle.set(this.scrollContainer, lPos, "0");
737 domStyle.set(this.header, rPos, renderData.scrollbarWidth + "px");
738 domStyle.set(this.header, lPos, "0");
739 domStyle.set(this.subHeader, rPos, renderData.scrollbarWidth + "px");
740 domStyle.set(this.subHeader, lPos, "0");
741 if(this.buttonContainer && this.owner != null && this.owner.currentView == this){
742 domStyle.set(this.buttonContainer, rPos, renderData.scrollbarWidth + "px");
743 domStyle.set(this.buttonContainer, lPos, "0");
744 }
745
746 if(this.hScrollBar){
747
748 arr.forEach(this._hScrollNodes, function(elt){
749 domClass[renderData.hScrollBarEnabled ? "add" : "remove"](elt.parentNode, "dojoxCalendarHorizontalScroll");
750 }, this);
751
752 if(!renderData.hScrollBarEnabled){
753 this._setHScrollPosition(0);
754 this.hScrollBarW.set("value", 0);
755 }
756
757 domStyle.set(this.hScrollBar, {
758 "display": renderData.hScrollBarEnabled ? "block" : "none",
759 "height": renderData.scrollbarHeight + "px",
760 "left": (atRight ? renderData.rowHeaderWidth : renderData.scrollbarWidth) + "px",
761 "right": (atRight ? renderData.scrollbarWidth : renderData.rowHeaderWidth) + "px"
762 });
763
764 domStyle.set(this.scrollContainer, "bottom", renderData.hScrollBarEnabled ? (renderData.scrollbarHeight + 1) + "px" : "0");
765 this._configureHScrollDomNodes(renderData.hScrollBarEnabled ? renderData.minSheetWidth + "px" : "100%");
766
767 this.hScrollBarW.set("maximum", renderData.minSheetWidth);
768 this.hScrollBarW.set("containerSize", renderData.hScrollPaneWidth);
769
770 }
771 },
772
773 _configureHScrollDomNodes: function(styleWidth){
774 arr.forEach(this._hScrollNodes, function(elt){
775 domStyle.set(elt, "width", styleWidth);
776 }, this);
777 },
778
779 resize: function(e){
780 this._resizeHandler(e);
781 },
782
783 _resizeHandler: function(e, apply){
784 // summary:
785 // Refreshes the scroll bars after a resize of the widget.
786 // e: Event
787 // The resize event (optional)
788 // apply: Boolean
789 // Whether apply the changes or wait for 100 ms
790 // tags:
791 // private
792
793 var rd = this.renderData;
794
795 if(rd == null){
796 return;
797 }
798
799
800 if(apply){
801
802 var hScrollPaneWidth = domGeometry.getMarginBox(this.grid).w;
803
804 if(rd.hScrollPaneWidth != hScrollPaneWidth){
805 // refresh values
806 rd.hScrollPaneWidth = hScrollPaneWidth;
807 rd.minSheetWidth = this.minColumnWidth < 0 ? -1 : this.minColumnWidth * rd.subColumnCount * rd.columnCount;
808 rd.hScrollBarEnabled = this.minColumnWidth > 0 && domGeometry.getMarginBox(this.grid).w < rd.minSheetWidth;
809 }
810
811 this._configureScrollBar(rd);
812
813 }else{
814 if(this._resizeTimer != undefined){
815 clearTimeout(this._resizeTimer);
816 }
817 this._resizeTimer = setTimeout(lang.hitch(this, function(){
818 this._resizeHandler(e, true);
819 }), 100);
820 }
821
822 },
823
824 _columnHeaderClick: function(e){
825 // tags:
826 // private
827
828 event.stop(e);
829 var index = query("td", this.columnHeaderTable).indexOf(e.currentTarget);
830 this._onColumnHeaderClick({
831 index: index,
832 date: this.renderData.dates[index],
833 triggerEvent: e
834 });
835 },
836
837 _buildColumnHeader: function(renderData, oldRenderData){
838 // summary:
839 // Creates incrementally the HTML structure of the column header and configures its content.
840 //
841 // renderData:
842 // The render data to display.
843 //
844 // oldRenderData:
845 // The previously render data displayed, if any.
846 // tags:
847 // private
848
849 var table = this.columnHeaderTable;
850
851 if (!table){
852 return;
853 }
854
855 var count = renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0);
856
857 if(has("ie") == 8){
858 // workaround Internet Explorer 8 bug.
859 // if on the table, width: 100% and table-layout: fixed are set
860 // and columns are removed, width of remaining columns is not
861 // recomputed: must rebuild all.
862 if(this._colTableSave == null){
863 this._colTableSave = lang.clone(table);
864 }else if(count < 0){
865 this._cleanupColumnHeader();
866 this.columnHeader.removeChild(table);
867 domConstruct.destroy(table);
868 table = lang.clone(this._colTableSave);
869 this.columnHeaderTable = table;
870 this.columnHeader.appendChild(table);
871 count = renderData.columnCount;
872 }
873
874 } // else incremental dom add/remove for real browsers.
875
876 var tbodies = query("tbody", table);
877
878 var trs = query("tr", table);
879 var tbody, tr, td;
880
881 if (tbodies.length == 1){
882 tbody = tbodies[0];
883 }else{
884 tbody = html.create("tbody", null, table);
885 }
886
887 if (trs.length == 1){
888 tr = trs[0];
889 }else{
890 tr = domConstruct.create("tr", null, tbody);
891 }
892
893 // Build HTML structure (incremental)
894 if(count > 0){ // creation
895 for(var i=0; i < count; i++){
896
897 td = domConstruct.create("td", null, tr);
898
899 var h = [];
900 h.push(on(td, "click", lang.hitch(this, this._columnHeaderClick)));
901
902 if(has("touch-events")){
903 h.push(on(td, "touchstart", function(e){
904 event.stop(e);
905 domClass.add(e.currentTarget, "Active");
906 }));
907
908 h.push(on(td, "touchend", function(e){
909 event.stop(e);
910 domClass.remove(e.currentTarget, "Active");
911 }));
912 }else{
913 h.push(on(td, "mousedown", function(e){
914 event.stop(e);
915 domClass.add(e.currentTarget, "Active");
916 }));
917
918 h.push(on(td, "mouseup", function(e){
919 event.stop(e);
920 domClass.remove(e.currentTarget, "Active");
921 }));
922
923 h.push(on(td, "mouseover", function(e){
924 event.stop(e);
925 domClass.add(e.currentTarget, "Hover");
926 }));
927
928 h.push(on(td, "mouseout", function(e){
929 event.stop(e);
930 domClass.remove(e.currentTarget, "Hover");
931 }));
932
933 }
934
935 this._columnHeaderHandlers.push(h);
936
937 }
938 }else{ // deletion
939 count = -count;
940 for(var i=0; i < count; i++){
941 td = tr.lastChild;
942 tr.removeChild(td);
943 domConstruct.destroy(td);
944 var list = this._columnHeaderHandlers.pop();
945 while(list.length>0){
946 list.pop().remove();
947 }
948 }
949 }
950
951 // fill & configure
952 query("td", table).forEach(function(td, i){
953 td.className = "";
954 if(i == 0){
955 domClass.add(td, "first-child");
956 }else if(i == this.renderData.columnCount-1){
957 domClass.add(td, "last-child");
958 }
959 var d = renderData.dates[i];
960 this._setText(td, this._formatColumnHeaderLabel(d));
961 this.styleColumnHeaderCell(td, d, renderData);
962 }, this);
963
964 if(this.yearColumnHeaderContent){
965 var d = renderData.dates[0];
966 this._setText(this.yearColumnHeaderContent, renderData.dateLocaleModule.format(d,
967 {selector: "date", datePattern:"yyyy"}));
968 }
969 },
970
971 _cleanupColumnHeader: function(){
972 while(this._columnHeaderHandlers.length > 0){
973 var list = this._columnHeaderHandlers.pop();
974 while(list.length > 0){
975 list.pop().remove();
976 }
977 }
978 },
979
980 styleColumnHeaderCell: function(node, date, renderData){
981 // summary:
982 // Styles the CSS classes to the node that displays a column header cell.
983 // By default this method is setting:
984 // - "dojoxCalendarToday" class name if the date displayed is the current date,
985 // - "dojoxCalendarWeekend" if the date represents a weekend,
986 // - the CSS class corresponding of the displayed day of week ("Sun", "Mon" and so on).
987 // node: Node
988 // The DOM node that displays the column in the grid.
989 // date: Date
990 // The date displayed by this column
991 // renderData: Object
992 // The render data.
993 // tags:
994 // protected
995
996 domClass.add(node, this._cssDays[date.getDay()]);
997
998 if(this.isToday(date)){
999 domClass.add(node, "dojoxCalendarToday");
1000 } else if(this.isWeekEnd(date)){
1001 domClass.add(node, "dojoxCalendarWeekend");
1002 }
1003 },
1004
1005 _buildSubColumnHeader: function(renderData, oldRenderData){
1006 // summary:
1007 // Creates incrementally the HTML structure of the column header and configures its content.
1008 //
1009 // renderData:
1010 // The render data to display.
1011 //
1012 // oldRenderData:
1013 // The previously render data displayed, if any.
1014 // tags:
1015 // private
1016
1017 var table = this.subColumnHeaderTable;
1018
1019 if (!table || this.subColumns == null){
1020 return;
1021 }
1022
1023 var count = renderData.columnCount - query("td", table).length;
1024
1025 if(has("ie") == 8){
1026 // workaround Internet Explorer 8 bug.
1027 // if on the table, width: 100% and table-layout: fixed are set
1028 // and columns are removed, width of remaining columns is not
1029 // recomputed: must rebuild all.
1030 if(this._colSubTableSave == null){
1031 this._colSubTableSave = lang.clone(table);
1032 }else if(count < 0){
1033 this.subColumnHeader.removeChild(table);
1034 domConstruct.destroy(table);
1035 table = lang.clone(this._colSubTableSave);
1036 this.subColumnHeaderTable = table;
1037 this.subColumnHeader.appendChild(table);
1038 count = renderData.columnCount;
1039 }
1040
1041 } // else incremental dom add/remove for real browsers.
1042
1043 var tbodies = query(">tbody", table);
1044
1045 var tbody, tr, td;
1046
1047 if (tbodies.length == 1){
1048 tbody = tbodies[0];
1049 }else{
1050 tbody = html.create("tbody", null, table);
1051 }
1052
1053 var trs = query(">tr", tbody);
1054 if (trs.length == 1){
1055 tr = trs[0];
1056 }else{
1057 tr = domConstruct.create("tr", null, tbody);
1058 }
1059
1060 var subCount = renderData.subColumnCount;
1061
1062 // Build HTML structure (incremental)
1063 if(count > 0){ // creation
1064 for(var i=0; i < count; i++){
1065 td = domConstruct.create("td", null, tr);
1066 domConstruct.create("div", {"className": "dojoxCalendarSubHeaderContainer"}, td);
1067 }
1068 }else{ // deletion
1069 count = -count;
1070 for(var i=0; i < count; i++){
1071 td = tr.lastChild;
1072 tr.removeChild(td);
1073 domConstruct.destroy(td);
1074 }
1075 }
1076
1077 // fill & configure
1078 query("td", table).forEach(function(td, i){
1079 td.className = "";
1080 if(i == 0){
1081 domClass.add(td, "first-child");
1082 }else if(i == this.renderData.columnCount-1){
1083 domClass.add(td, "last-child");
1084 }
1085
1086 query(".dojoxCalendarSubHeaderContainer", td).forEach(function(div, i){
1087
1088 var count = query(".dojoxCalendarSubHeaderContainer", div).length - subCount;
1089 if(count != 0){
1090 var len = div.childNodes.length;
1091 for(var i=0; i<len; i++){
1092 div.removeChild(div.lastChild);
1093 }
1094 for(var j=0; j<subCount; j++){
1095 domConstruct.create("div", {"className": "dojoxCalendarSubHeaderCell dojoxCalendarSubHeaderLabel"}, div);
1096 }
1097 }
1098
1099 var colW = (100/subCount) + "%";
1100 query(".dojoxCalendarSubHeaderCell", div).forEach(function(div, i){
1101 div.className = "dojoxCalendarSubHeaderCell dojoxCalendarSubHeaderLabel";
1102 var col = subCount == 1 ? i : Math.floor(i / subCount);
1103 subColIdx = subCount == 1 ? 0 : i - col * subCount;
1104 domStyle.set(div, {width: colW, left: ((subColIdx * 100)/subCount)+"%"});
1105 domClass[subColIdx<subCount-1 && subCount !== 1?"add":"remove"](div, "subColumn");
1106 domClass.add(div, this.subColumns[subColIdx]);
1107 this._setText(div, this.subColumnLabelFunc(this.subColumns[subColIdx]));
1108 }, this);
1109
1110 }, this);
1111
1112 var d = renderData.dates[i];
1113
1114 this.styleSubColumnHeaderCell(td, d, renderData);
1115
1116 }, this);
1117
1118 },
1119
1120
1121 subColumnLabelFunc: function(value){
1122 // summary:
1123 // Computes the label for a sub column from the subColumns property.
1124 // By default, return the value.
1125 return value;
1126 },
1127
1128 styleSubColumnHeaderCell: function(node, date, renderData){
1129 // summary:
1130 // Styles the CSS classes to the node that displays a sub column header cell.
1131 // By default this method is not setting anythin:
1132 // node: Node
1133 // The DOM node that displays the column in the grid.
1134 // subColumnIndex: Integer
1135 // The cub column index.
1136 // renderData: Object
1137 // The render data.
1138 // tags:
1139 // protected
1140 domClass.add(node, this._cssDays[date.getDay()]);
1141
1142 if(this.isToday(date)){
1143 domClass.add(node, "dojoxCalendarToday");
1144 } else if(this.isWeekEnd(date)){
1145 domClass.add(node, "dojoxCalendarWeekend");
1146 }
1147 },
1148
1149 _addMinutesClasses: function(node, minutes){
1150 switch(minutes){
1151 case 0:
1152 domClass.add(node, "hour");
1153 break;
1154 case 30:
1155 domClass.add(node, "halfhour");
1156 break;
1157 case 15:
1158 case 45:
1159 domClass.add(node, "quarterhour");
1160 break;
1161 }
1162 },
1163
1164 _buildRowHeader: function(renderData, oldRenderData){
1165
1166 // summary:
1167 // Creates incrementally the HTML structure of the row header and configures its content.
1168 //
1169 // renderData:
1170 // The render data to display.
1171 //
1172 // oldRenderData:
1173 // The previously render data displayed, if any.
1174 // tags:
1175 // private
1176
1177
1178 var rowHeaderTable = this.rowHeaderTable;
1179
1180 if (!rowHeaderTable){
1181 return;
1182 }
1183
1184 if(this._rowHeaderLabelContainer == null){
1185 this._rowHeaderLabelContainer = domConstruct.create("div", {"class": "dojoxCalendarRowHeaderLabelContainer"}, this.rowHeader);
1186 }
1187
1188
1189 domStyle.set(rowHeaderTable, "height", renderData.sheetHeight + "px");
1190
1191 var tbodies = query("tbody", rowHeaderTable);
1192 var tbody, tr, td;
1193
1194 if (tbodies.length == 1){
1195 tbody = tbodies[0];
1196 }else{
1197 tbody = domConstruct.create("tbody", null, rowHeaderTable);
1198 }
1199
1200 var nbRows = Math.floor(60 / renderData.rowHeaderGridSlotDuration) * renderData.hourCount;
1201
1202 var count = nbRows -
1203 (oldRenderData ? Math.floor(60 / oldRenderData.rowHeaderGridSlotDuration) * oldRenderData.hourCount : 0);
1204
1205 // Build HTML structure
1206 if(count>0){ // creation
1207 for(var i=0; i < count; i++){
1208 tr = domConstruct.create("tr", null, tbody);
1209 td = domConstruct.create("td", null, tr);
1210 }
1211 }else{
1212 count = -count;
1213 // deletion of existing nodes
1214 for(var i=0; i < count; i++){
1215 tbody.removeChild(tbody.lastChild);
1216 }
1217 }
1218
1219 // fill labels
1220
1221
1222 var rd = this.renderData;
1223 var size = Math.ceil(renderData.hourSize / (60 / renderData.rowHeaderGridSlotDuration));
1224 var d = new Date(2000, 0, 1, 0, 0, 0);
1225
1226 query("tr", rowHeaderTable).forEach(function(tr, i){
1227 var td = query("td", tr)[0];
1228 td.className = "";
1229
1230 domStyle.set(tr, "height", (has("ie") == 7)?size-2*(60 / renderData.rowHeaderGridSlotDuration):size + "px");
1231
1232 var h = renderData.minHours + (i * this.renderData.rowHeaderGridSlotDuration) / 60;
1233 var m = (i * this.renderData.rowHeaderGridSlotDuration) % 60;
1234
1235 this.styleRowHeaderCell(td, h, m, rd);
1236
1237 this._addMinutesClasses(td, m);
1238
1239 }, this);
1240
1241 var lc = this._rowHeaderLabelContainer;
1242 count = (Math.floor(60 / this.rowHeaderLabelSlotDuration) * renderData.hourCount) - lc.childNodes.length;
1243
1244 var span;
1245 if(count>0){ // creation
1246 for(var i=0; i < count; i++){
1247 span = domConstruct.create("span", null, lc);
1248 domClass.add(span, "dojoxCalendarRowHeaderLabel");
1249 }
1250 }else{
1251 count = -count;
1252 // deletion of existing nodes
1253 for(var i=0; i < count; i++){
1254 lc.removeChild(lc.lastChild);
1255 }
1256 }
1257
1258 size = Math.ceil(renderData.hourSize / (60 / this.rowHeaderLabelSlotDuration));
1259
1260 query(">span", lc).forEach(function(span, i){
1261 d.setHours(0);
1262 d.setMinutes(renderData.minHours * 60 + (i*this.rowHeaderLabelSlotDuration));
1263 this._configureRowHeaderLabel(span, d, i, size*i, rd);
1264 }, this);
1265
1266 },
1267
1268 _configureRowHeaderLabel: function(node, d, index, pos, renderData){
1269 // summary:
1270 // Configures the label of a row header cell.
1271 // node: DOMNode
1272 // The DOM node that is the parent of the label.
1273 // d:Date
1274 // A date object that contains the hours and minutes displayed by this row header cell.
1275 // index: Integer
1276 // The index of this row header cell
1277 // pos: Integer
1278 // The computed position of the row header cell
1279 // renderData: Object
1280 // The render data.
1281
1282 this._setText(node, this._formatRowHeaderLabel(d));
1283 domStyle.set(node, "top", (pos + (index==0?this.rowHeaderFirstLabelOffset:this.rowHeaderLabelOffset))+"px");
1284 var h = renderData.minHours + (index * this.rowHeaderLabelSlotDuration) / 60;
1285 var m = (index * this.rowHeaderLabelSlotDuration) % 60;
1286 domClass.remove(node, ["hour", "halfhour", "quarterhour"]);
1287 this._addMinutesClasses(node, m);
1288 this.styleRowHeaderCell(node, h, m, renderData);
1289 },
1290
1291 styleRowHeaderCell: function(node, h, m, renderData){
1292 // summary:
1293 // Styles the CSS classes to the node that displays a row header cell.
1294 // By default this method is doing nothing.
1295 // node: Node
1296 // The DOM node that displays the column in the grid.
1297 // h: Integer
1298 // The time of day displayed by this row header cell.
1299 // renderData: Object
1300 // The render data.
1301 // tags:
1302 // protected
1303 },
1304
1305 _buildGrid: function (renderData, oldRenderData){
1306 // summary:
1307 // Creates incrementally the HTML structure of the grid and configures its content.
1308 //
1309 // renderData:
1310 // The render data to display.
1311 //
1312 // oldRenderData:
1313 // The previously render data displayed, if any.
1314 // tags:
1315 // private
1316
1317
1318 var table = this.gridTable;
1319
1320 if (!table){
1321 return;
1322 }
1323
1324 domStyle.set(table, "height", renderData.sheetHeight + "px");
1325
1326 var nbRows = Math.floor(60 / renderData.slotDuration) * renderData.hourCount;
1327
1328 var rowDiff = nbRows -
1329 (oldRenderData ? Math.floor(60 / oldRenderData.slotDuration) * oldRenderData.hourCount : 0);
1330
1331 var addRows = rowDiff > 0;
1332
1333 var colDiff = (renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0));
1334
1335 if(has("ie") == 8){
1336 // workaround Internet Explorer 8 bug.
1337 // if on the table, width: 100% and table-layout: fixed are set
1338 // and columns are removed, width of remaining columns is not
1339 // recomputed: must rebuild all.
1340 if(this._gridTableSave == null){
1341 this._gridTableSave = lang.clone(table);
1342 }else if(colDiff < 0){
1343 this.grid.removeChild(table);
1344 domConstruct.destroy(table);
1345 table = lang.clone(this._gridTableSave);
1346 this.gridTable = table;
1347 this.grid.appendChild(table);
1348 colDiff = renderData.columnCount;
1349 rowDiff = nbRows;
1350 addRows = true;
1351 }
1352 }
1353
1354 var tbodies = query("tbody", table);
1355 var tbody;
1356
1357 if (tbodies.length == 1){
1358 tbody = tbodies[0];
1359 }else{
1360 tbody = domConstruct.create("tbody", null, table);
1361 }
1362
1363 // Build time slots (lines) HTML structure (incremental)
1364 if(addRows){ // creation
1365 for(var i=0; i<rowDiff; i++){
1366 domConstruct.create("tr", null, tbody);
1367 }
1368 }else{ // deletion
1369 rowDiff = -rowDiff;
1370 for(var i=0; i<rowDiff; i++){
1371 tbody.removeChild(tbody.lastChild);
1372 }
1373 }
1374
1375 var rowIndex = Math.floor(60 / renderData.slotDuration) * renderData.hourCount - rowDiff;
1376
1377 var addCols = addRows || colDiff >0;
1378 colDiff = addCols ? colDiff : -colDiff;
1379
1380 query("tr", table).forEach(function(tr, i){
1381
1382 if(addCols){ // creation
1383 var len = i >= rowIndex ? renderData.columnCount : colDiff;
1384 for(var i=0; i<len; i++){
1385 domConstruct.create("td", null, tr);
1386 }
1387 }else{ // deletion
1388 for(var i=0; i<colDiff; i++){
1389 tr.removeChild(tr.lastChild);
1390 }
1391 }
1392 });
1393
1394 // Set the CSS classes
1395
1396 query("tr", table).forEach(function (tr, i){
1397
1398 domStyle.set(tr, "height", renderData.slotSize + "px");
1399
1400 if(i == 0){
1401 domClass.add(tr, "first-child");
1402 }else if(i == nbRows-1){
1403 domClass.add(tr, "last-child");
1404 }
1405
1406 // the minutes part of the time of day displayed by the current tr
1407 var m = (i * this.renderData.slotDuration) % 60;
1408 var h = this.minHours + Math.floor((i * this.renderData.slotDuration) / 60);
1409 query("td", tr).forEach(function (td, col){
1410
1411 td.className = "";
1412
1413 if(col == 0){
1414 domClass.add(td, "first-child");
1415 }else if(col == this.renderData.columnCount-1){
1416 domClass.add(td, "last-child");
1417 }
1418
1419 var d = renderData.dates[col];
1420
1421 this.styleGridCell(td, d, h, m, renderData);
1422
1423 this._addMinutesClasses(td, m);
1424
1425 }, this);
1426 }, this);
1427
1428 },
1429
1430 // styleGridCellFunc: Function
1431 // Custom function to customize the appearance of a grid cell by installing custom CSS class on the node.
1432 // The signature of the function must be the same then the styleGridCell one.
1433 // By default the defaultStyleGridCell function is used.
1434 styleGridCellFunc: null,
1435
1436 defaultStyleGridCell: function(node, date, hours, minutes, renderData){
1437 // summary:
1438 // Styles the CSS classes to the node that displays a cell.
1439 // By default this method is setting:
1440 // - "dojoxCalendarToday" class name if the date displayed is the current date,
1441 // - "dojoxCalendarWeekend" if the date represents a weekend,
1442 // - the CSS class corresponding of the displayed day of week ("Sun", "Mon" and so on),
1443 // - the CSS classes corresponfing to the time of day (e.g. "H14" and "M30" for for 2:30pm).
1444 // node: Node
1445 // The DOM node that displays the cell in the grid.
1446 // date: Date
1447 // The date displayed by this cell.
1448 // hours: Integer
1449 // The hours part of time of day displayed by the start of this cell.
1450 // minutes: Integer
1451 // The minutes part of time of day displayed by the start of this cell.
1452 // renderData: Object
1453 // The render data object.
1454 // tags:
1455 // protected
1456
1457 domClass.add(node, [this._cssDays[date.getDay()], "H"+hours, "M"+minutes]);
1458
1459 if(this.isToday(date)){
1460 return domClass.add(node, "dojoxCalendarToday");
1461 } else if(this.isWeekEnd(date)){
1462 return domClass.add(node, "dojoxCalendarWeekend");
1463 }
1464 },
1465
1466 styleGridCell: function(node, date, hours, minutes, renderData){
1467 // summary:
1468 // Styles the CSS classes to the node that displays a cell.
1469 // Delegates to styleGridCellFunc if defined or defaultStyleGridCell otherwise.
1470 // node: Node
1471 // The DOM node that displays the cell in the grid.
1472 // date: Date
1473 // The date displayed by this column
1474 // renderData: Object
1475 // The render data object.
1476 // tags:
1477 // protected
1478
1479 if(this.styleGridCellFunc){
1480 this.styleGridCellFunc(node, date, hours, minutes, renderData);
1481 }else{
1482 this.defaultStyleGridCell(node, date, hours, minutes, renderData);
1483 }
1484 },
1485
1486 _buildItemContainer: function(renderData, oldRenderData){
1487 // summary:
1488 // Creates the HTML structure of the item container and configures its content.
1489 // renderData:
1490 // The render data to display.
1491 // oldRenderData:
1492 // The previously render data displayed, if any.
1493 // tags:
1494 // private
1495
1496 var table = this.itemContainerTable;
1497
1498 if (!table){
1499 return;
1500 }
1501
1502 var bgCols = [], decoCols = [];
1503
1504 domStyle.set(table, "height", renderData.sheetHeight + "px");
1505 var oldCount = oldRenderData ? oldRenderData.columnCount : 0;
1506 var count = renderData.columnCount - oldCount;
1507
1508 if(has("ie") == 8){
1509 // workaround Internet Explorer 8 bug.
1510 // if on the table, width: 100% and table-layout: fixed are set
1511 // and columns are removed, width of remaining columns is not
1512 // recomputed: must rebuild all.
1513 if(this._itemTableSave == null){
1514 this._itemTableSave = lang.clone(table);
1515 }else if(count < 0){
1516 this.itemContainer.removeChild(table);
1517 this._recycleItemRenderers(true);
1518 domConstruct.destroy(table);
1519 table = lang.clone(this._itemTableSave);
1520 this.itemContainerTable = table;
1521 this.itemContainer.appendChild(table);
1522 count = renderData.columnCount;
1523 }
1524
1525 } // else incremental dom add/remove for real browsers.
1526
1527 var tbodies = query("tbody", table);
1528 var trs = query("tr", table);
1529 var tbody, tr, td;
1530
1531 if (tbodies.length == 1){
1532 tbody = tbodies[0];
1533 }else{
1534 tbody = domConstruct.create("tbody", null, table);
1535 }
1536
1537 if (trs.length == 1){
1538 tr = trs[0];
1539 }else{
1540 tr = domConstruct.create("tr", null, tbody);
1541 }
1542
1543 var subCount = renderData.subColumnCount;
1544
1545 // Build HTML structure (incremental)
1546 if(count>0){ // creation
1547 for(var i=0; i < count; i++){
1548 td = domConstruct.create("td", null, tr);
1549 domConstruct.create("div", {"className": "dojoxCalendarContainerColumn"}, td);
1550 }
1551 }else{ // deletion
1552 count = -count;
1553 for(var i=0; i < count; i++){
1554 tr.removeChild(tr.lastChild);
1555 }
1556 }
1557
1558
1559 query("td", table).forEach(function(td, i){
1560
1561 query(".dojoxCalendarContainerColumn", td).forEach(function(div, i){
1562 domStyle.set(div, "height", renderData.sheetHeight + "px");
1563 var count = query(".dojoxCalendarSubContainerColumn", td).length - subCount;
1564 if(count != 0){
1565 var len = div.childNodes.length;
1566 for(var i=0; i<len; i++){
1567 div.removeChild(div.lastChild);
1568 }
1569 for(var j=0; j<subCount; j++){
1570 var subdiv = domConstruct.create("div", {"className": "dojoxCalendarSubContainerColumn"}, div);
1571 domConstruct.create("div", {"className": "dojoxCalendarDecorationContainerColumn"}, subdiv);
1572 domConstruct.create("div", {"className": "dojoxCalendarEventContainerColumn"}, subdiv);
1573 }
1574 }
1575 }, this);
1576
1577 var colW = (100/subCount) + "%";
1578 query(".dojoxCalendarSubContainerColumn", td).forEach(function(div, i){
1579 var col = subCount == 1 ? i : Math.floor(i / subCount);
1580 subColIdx = subCount == 1 ? 0 : i - col * subCount;
1581 domStyle.set(div, {width: colW, left: ((subColIdx * 100)/subCount)+"%"});
1582 domClass[subColIdx<subCount-1 && subCount !== 1?"add":"remove"](div, "subColumn");
1583
1584 query(".dojoxCalendarEventContainerColumn", div).forEach(function(eventContainer, i){
1585 bgCols.push(eventContainer);
1586 }, this);
1587
1588 query(".dojoxCalendarDecorationContainerColumn", div).forEach(function(decoContainer, i){
1589 decoCols.push(decoContainer);
1590 }, this);
1591 }, this);
1592
1593
1594
1595 }, this);
1596
1597 renderData.cells = bgCols;
1598 renderData.decorationCells = decoCols;
1599 },
1600
1601 // showTimeIndicator: Boolean
1602 // Whether show or not an indicator (default a red line) at the current time.
1603 showTimeIndicator: true,
1604
1605 // timeIndicatorRefreshInterval: Integer
1606 // Maximal interval between two refreshes of time indicator, in milliseconds.
1607 timeIndicatorRefreshInterval: 60000,
1608
1609 _setShowTimeIndicatorAttr: function(value){
1610 this._set("showTimeIndicator", value);
1611 this._layoutTimeIndicator(this.renderData);
1612 },
1613
1614 _layoutTimeIndicator: function(renderData){
1615 if(!renderData){
1616 return;
1617 }
1618
1619 if(this.showTimeIndicator){
1620
1621 var now = new renderData.dateClassObj();
1622
1623 var visible = this.isOverlapping(renderData, renderData.startTime, renderData.endTime, now, now) &&
1624 now.getHours() >= this.get("minHours") &&
1625 (now.getHours()*60+now.getMinutes() < this.get("maxHours")*60);
1626
1627 if(visible){
1628
1629 if(!this._timeIndicator){
1630 this._timeIndicator = domConstruct.create("div",
1631 {"className": "dojoxCalendarTimeIndicator"});
1632 }
1633
1634 var node = this._timeIndicator;
1635
1636 for(var column=0; column<this.renderData.columnCount; column++){
1637 if(this.isSameDay(now, this.renderData.dates[column])){
1638 break;
1639 }
1640 }
1641
1642 var top = this.computeProjectionOnDate(renderData, this.floorToDay(now), now, renderData.sheetHeight);
1643
1644 if(top != renderData.sheetHeight){
1645
1646 domStyle.set(node, {top: top+"px", display: "block"});
1647 var parentNode = renderData.cells[column*renderData.subColumnCount].parentNode.parentNode;
1648 if(parentNode != node.parentNode){
1649 if(node.parentNode != null){
1650 node.parentNode.removeChild(node);
1651 }
1652 parentNode.appendChild(node);
1653 }
1654
1655 if(this._timeIndicatorTimer == null){
1656 this._timeIndicatorTimer = setInterval(lang.hitch(this, function(){
1657 this._layoutTimeIndicator(this.renderData);
1658 }), this.timeIndicatorRefreshInterval);
1659 }
1660 return;
1661 }
1662 }
1663
1664 }
1665
1666 // not visible or specifically not shown fallback
1667
1668 if(this._timeIndicatorTimer){
1669 clearInterval(this._timeIndicatorTimer);
1670 this._timeIndicatorTimer = null;
1671 }
1672 if(this._timeIndicator){
1673 domStyle.set(this._timeIndicator, "display", "none");
1674 }
1675
1676 },
1677
1678 beforeDeactivate: function(){
1679 if(this._timeIndicatorTimer){
1680 clearInterval(this._timeIndicatorTimer);
1681 this._timeIndicatorTimer = null;
1682 }
1683 },
1684
1685 ///////////////////////////////////////////////////////////////
1686 //
1687 // Layout
1688 //
1689 ///////////////////////////////////////////////////////////////
1690
1691 _overlapLayoutPass2: function(lanes){
1692 // summary:
1693 // Second pass of the overlap layout (optional). Compute the extent of each layout item.
1694 // lanes:
1695 // The array of lanes.
1696 // tags:
1697 // private
1698 var i,j,lane, layoutItem;
1699 // last lane, no extent possible
1700 lane = lanes[lanes.length-1];
1701
1702 for(j = 0; j < lane.length; j++){
1703 lane[j].extent = 1;
1704 }
1705
1706 for(i=0; i<lanes.length-1; i++){
1707 lane = lanes[i];
1708
1709 for(var j=0; j<lane.length; j++){
1710 layoutItem = lane[j];
1711
1712 // if item was already overlapping another one there is no extent possible.
1713 if(layoutItem.extent == -1){
1714 layoutItem.extent = 1;
1715 var space = 0;
1716
1717 var stop = false;
1718
1719 for(var k = i + 1; k < lanes.length && !stop; k++){
1720 var ccol = lanes[k];
1721 for(var l = 0; l < ccol.length && !stop; l++){
1722 var layoutItem2 = ccol[l];
1723
1724 if(layoutItem.start < layoutItem2.end && layoutItem2.start < layoutItem.end){
1725 stop = true;
1726 }
1727 }
1728 if(!stop){
1729 //no hit in the entire lane
1730 space++;
1731 }
1732 }
1733 layoutItem.extent += space;
1734 }
1735 }
1736 }
1737 },
1738
1739 _defaultItemToRendererKindFunc: function(item){
1740 // tags:
1741 // private
1742 return "vertical"; // String
1743 },
1744
1745 _layoutInterval: function(/*Object*/renderData, /*Integer*/index, /*Date*/start, /*Date*/end, /*Object[]*/items, /*String*/itemsType){
1746 // tags:
1747 // private
1748
1749 var verticalItems = [];
1750
1751 renderData.colW = this.itemContainer.offsetWidth / renderData.columnCount;
1752
1753 if(itemsType === "dataItems"){
1754
1755 for(var i=0; i<items.length; i++){
1756 var item = items[i];
1757 var kind = this._itemToRendererKind(item);
1758 if(kind === "vertical"){
1759 verticalItems.push(item);
1760 }
1761 }
1762
1763 this._layoutRendererWithSubColumns(renderData, "vertical", true, index, start, end, verticalItems, itemsType);
1764
1765 }else{ // itemsType === "decorationItems"
1766
1767 // no different rendererKind for decoration yet
1768 this._layoutRendererWithSubColumns(renderData, "decoration", false, index, start, end, items, itemsType);
1769 }
1770 },
1771
1772 _layoutRendererWithSubColumns: function(renderData, rendererKind, computeOverlap, index, start, end, items, itemsType){
1773 if(items.length > 0){
1774 if(renderData.subColumnCount > 1){
1775 var subColumnItems = {};
1776 var subCols = this.subColumns;
1777 arr.forEach(subCols, function(subCol){
1778 subColumnItems[subCol] = [];
1779 });
1780 arr.forEach(items, function(item){
1781 if(itemsType === "decorationItems"){
1782 if(item.subColumn){
1783 if(subColumnItems[item.subColumn]){
1784 subColumnItems[item.subColumn].push(item);
1785 }
1786 }else{ // for decorations, if no sub column is set, apply to all sub columns
1787 arr.forEach(subCols, function(subCol){
1788 var clonedItem = lang.mixin({}, item);
1789 clonedItem.subColumn = subCol;
1790 subColumnItems[subCol].push(clonedItem);
1791 });
1792 }
1793 }else if(item.subColumn && subColumnItems[item.subColumn]){
1794 subColumnItems[item.subColumn].push(item);
1795 }
1796 });
1797 var subColIndex = 0;
1798 arr.forEach(this.subColumns, function(subCol){
1799 this._layoutVerticalItems(renderData, rendererKind, computeOverlap, index, subColIndex++, start, end, subColumnItems[subCol], itemsType);
1800 }, this);
1801 }else{
1802 this._layoutVerticalItems(renderData, rendererKind, computeOverlap, index, 0, start, end, items, itemsType);
1803 }
1804 }
1805 },
1806
1807 _getColumn: function(renderData, index, subIndex, itemsType){
1808 var cols = itemsType === "dataItems" ? renderData.cells : renderData.decorationCells;
1809 return cols[index * renderData.subColumnCount + subIndex];
1810 },
1811
1812 _layoutVerticalItems: function(/*Object*/renderData, /*String*/ rendererKind, /*boolean*/ computeOverlap,
1813 /*Integer*/index, /*Integer*/subIndex, /*Date*/startTime, /*Date*/endTime, /*Object[]*/items, /*String*/itemsType){
1814 // tags:
1815 // private
1816
1817 if(itemsType === "dataItems" && this.verticalRenderer == null ||
1818 itemsType === "decorationItems" && this.verticalDecorationRenderer == null){
1819 return;
1820 }
1821
1822 var cell = this._getColumn(renderData, index, subIndex, itemsType);
1823
1824 var layoutItems = [];
1825
1826 // step 1 compute projected position and size
1827 for(var i = 0; i < items.length; i++){
1828
1829 var item = items[i];
1830 var overlap = this.computeRangeOverlap(renderData, item.startTime, item.endTime, startTime, endTime);
1831
1832 var top = this.computeProjectionOnDate(renderData, startTime, overlap[0], renderData.sheetHeight);
1833 var bottom = this.computeProjectionOnDate(renderData, startTime, overlap[1], renderData.sheetHeight);
1834
1835 if (bottom > top){
1836 var litem = lang.mixin({
1837 start: top,
1838 end: bottom,
1839 range: overlap,
1840 item: item
1841 }, item);
1842 layoutItems.push(litem);
1843 }
1844 }
1845
1846 // step 2: compute overlapping layout
1847 var numLanes = itemsType === "dataItems" ? this.computeOverlapping(layoutItems, this._overlapLayoutPass2).numLanes : 1;
1848
1849 var hOverlap = this.percentOverlap / 100;
1850
1851 // step 3: create renderers and apply layout
1852 for(i=0; i<layoutItems.length; i++){
1853
1854 item = layoutItems[i];
1855 var w, posX, ir, renderer;
1856
1857 if(itemsType === "dataItems"){
1858
1859 var lane = item.lane;
1860 var extent = item.extent;
1861
1862 if(hOverlap == 0) {
1863 //no overlap and a padding between each event
1864 w = numLanes == 1 ? renderData.colW : ((renderData.colW - (numLanes - 1) * this.horizontalGap)/ numLanes);
1865 posX = lane * (w + this.horizontalGap);
1866 w = extent == 1 ? w : w * extent + (extent-1) * this.horizontalGap;
1867 w = 100 * w / renderData.colW;
1868 posX = 100 * posX / renderData.colW;
1869 } else {
1870 // an overlap
1871 w = numLanes == 1 ? 100 : (100 / (numLanes - (numLanes - 1) * hOverlap));
1872 posX = lane * (w - hOverlap*w);
1873 w = extent == 1 ? w : w * ( extent - (extent-1) * hOverlap);
1874 }
1875
1876 ir = this._createRenderer(item, "vertical", this.verticalRenderer, "dojoxCalendarVertical");
1877
1878 var edited = this.isItemBeingEdited(item);
1879 var selected = this.isItemSelected(item);
1880 var hovered = this.isItemHovered(item);
1881 var focused = this.isItemFocused(item);
1882
1883 renderer = ir.renderer;
1884
1885 renderer.set("hovered", hovered);
1886 renderer.set("selected", selected);
1887 renderer.set("edited", edited);
1888 renderer.set("focused", this.showFocus ? focused : false);
1889 renderer.set("storeState", this.getItemStoreState(item));
1890
1891 renderer.set("moveEnabled", this.isItemMoveEnabled(item._item, "vertical"));
1892 renderer.set("resizeEnabled", this.isItemResizeEnabled(item._item, "vertical"));
1893
1894 this.applyRendererZIndex(item, ir, hovered, selected, edited, focused);
1895
1896 } else {
1897 w = 100;
1898 posX = 0;
1899 ir = this.decorationRendererManager.createRenderer(item, "vertical", this.verticalDecorationRenderer, "dojoxCalendarDecoration");
1900 renderer = ir.renderer;
1901 }
1902
1903 domStyle.set(ir.container, {
1904 "top": item.start + "px",
1905 "left": posX + "%",
1906 "width": w + "%",
1907 "height": (item.end-item.start+1) + "px"
1908 });
1909
1910 if(renderer.updateRendering){
1911 renderer.updateRendering(w, item.end-item.start+1);
1912 }
1913
1914 domConstruct.place(ir.container, cell);
1915 domStyle.set(ir.container, "display", "block");
1916 }
1917 },
1918
1919 _sortItemsFunction: function(a, b){
1920 // tags:
1921 // private
1922
1923 var res = this.dateModule.compare(a.startTime, b.startTime);
1924 if(res == 0){
1925 res = -1 * this.dateModule.compare(a.endTime, b.endTime);
1926 }
1927 return this.isLeftToRight() ? res : -res;
1928 },
1929
1930 ///////////////////////////////////////////////////////////////
1931 //
1932 // View to time projection
1933 //
1934 ///////////////////////////////////////////////////////////////
1935
1936 _getNormalizedCoords: function(e, x, y, touchIndex){
1937 if (e != null){
1938 var refPos = domGeometry.position(this.itemContainer, true);
1939
1940 if(e.touches){
1941
1942 touchIndex = touchIndex==undefined ? 0 : touchIndex;
1943
1944 x = e.touches[touchIndex].pageX - refPos.x;
1945 y = e.touches[touchIndex].pageY - refPos.y;
1946
1947 }else{
1948
1949 x = e.pageX - refPos.x;
1950 y = e.pageY - refPos.y;
1951 }
1952 }
1953
1954 var r = domGeometry.getContentBox(this.itemContainer);
1955
1956 if(!this.isLeftToRight()){
1957 x = r.w - x;
1958 }
1959
1960 if (x < 0){
1961 x = 0;
1962 }else if(x > r.w){
1963 x = r.w-1;
1964 }
1965
1966 if (y < 0){
1967 y = 0;
1968 }else if(y > r.h){
1969 y = r.h-1;
1970 }
1971
1972 return {x: x, y: y};
1973 },
1974
1975 getTime: function(e, x, y, touchIndex){
1976 // summary:
1977 // Returns the time displayed at the specified point by this component.
1978 // e: Event
1979 // Optional mouse event.
1980 // x: Number
1981 // Position along the x-axis with respect to the sheet container used if event is not defined.
1982 // y: Number
1983 // Position along the y-axis with respect to the sheet container (scroll included) used if event is not defined.
1984 // touchIndex: Integer
1985 // If parameter 'e' is not null and a touch event, the index of the touch to use.
1986 // returns: Date
1987
1988 var o = this._getNormalizedCoords(e, x, y, touchIndex);
1989 var t = this.getTimeOfDay(o.y, this.renderData);
1990 var colW = domGeometry.getMarginBox(this.itemContainer).w / this.renderData.columnCount;
1991 var col = Math.floor(o.x / colW);
1992
1993 var date = null;
1994 if(col < this.renderData.dates.length){
1995 date = this.newDate(this.renderData.dates[col]);
1996 date = this.floorToDay(date, true);
1997 date.setHours(t.hours);
1998 date.setMinutes(t.minutes);
1999 }
2000
2001 return date;
2002 },
2003
2004 getSubColumn: function(e, x, y, touchIndex){
2005 // summary:
2006 // Returns the sub column at the specified point by this component.
2007 // e: Event
2008 // Optional mouse event.
2009 // x: Number
2010 // Position along the x-axis with respect to the sheet container used if event is not defined.
2011 // y: Number
2012 // Position along the y-axis with respect to the sheet container (scroll included) used if event is not defined.
2013 // touchIndex: Integer
2014 // If parameter 'e' is not null and a touch event, the index of the touch to use.
2015 // returns: Object
2016
2017 if(this.subColumns == null || this.subColumns.length == 1){
2018 return null;
2019 }
2020 var o = this._getNormalizedCoords(e, x, y, touchIndex);
2021 var rd = this.renderData;
2022 var colW = domGeometry.getMarginBox(this.itemContainer).w / this.renderData.columnCount;
2023 var col = Math.floor(o.x / colW);
2024 var idx = Math.floor((o.x - col*colW) / (colW / rd.subColumnCount));
2025 return this.subColumns[idx];
2026 },
2027
2028 ///////////////////////////////////////////////////////////////
2029 //
2030 // Events
2031 //
2032 ///////////////////////////////////////////////////////////////
2033
2034 _onGridMouseUp: function(e){
2035 // tags:
2036 // private
2037
2038 this.inherited(arguments);
2039
2040 if (this._gridMouseDown) {
2041 this._gridMouseDown = false;
2042
2043 this._onGridClick({
2044 date: this.getTime(e),
2045 triggerEvent: e
2046 });
2047 }
2048 },
2049
2050 _onGridTouchStart: function(e){
2051 // tags:
2052 // private
2053
2054 this.inherited(arguments);
2055
2056 var g = this._gridProps;
2057
2058 g.moved= false;
2059 g.start= e.touches[0].screenY;
2060 g.scrollTop= this._getScrollPosition();
2061 },
2062
2063 _onGridTouchMove: function(e){
2064 // tags:
2065 // private
2066
2067 this.inherited(arguments);
2068
2069 if (e.touches.length > 1 && !this._isEditing){
2070 event.stop(e);
2071 return;
2072 }
2073
2074 if(this._gridProps && !this._isEditing){
2075
2076 var touch = {x: e.touches[0].screenX, y: e.touches[0].screenY};
2077
2078 var p = this._edProps;
2079
2080 if (!p || p &&
2081 (Math.abs(touch.x - p.start.x) > 25 ||
2082 Math.abs(touch.y - p.start.y) > 25)) {
2083
2084 this._gridProps.moved = true;
2085 var d = e.touches[0].screenY - this._gridProps.start;
2086 var value = this._gridProps.scrollTop - d;
2087 var max = this.itemContainer.offsetHeight - this.scrollContainer.offsetHeight;
2088 if (value < 0){
2089 this._gridProps.start = e.touches[0].screenY;
2090 this._setScrollImpl(0);
2091 this._gridProps.scrollTop = 0;
2092 }else if(value > max){
2093 this._gridProps.start = e.touches[0].screenY;
2094 this._setScrollImpl(max);
2095 this._gridProps.scrollTop = max;
2096 }else{
2097 this._setScrollImpl(value);
2098 }
2099 }
2100 }
2101 },
2102
2103 _onGridTouchEnd: function(e){
2104 // tags:
2105 // private
2106
2107 //event.stop(e);
2108
2109 this.inherited(arguments);
2110
2111 var g = this._gridProps;
2112
2113 if(g){
2114 if(!this._isEditing){
2115 if(!g.moved){
2116
2117 // touched on grid and on touch start editing was ongoing.
2118 if(!g.fromItem && !g.editingOnStart){
2119 this.selectFromEvent(e, null, null, true);
2120 }
2121
2122 if(!g.fromItem){
2123
2124 if(this._pendingDoubleTap && this._pendingDoubleTap.grid){
2125
2126 this._onGridDoubleClick({
2127 date: this.getTime(this._gridProps.event),
2128 triggerEvent: this._gridProps.event
2129 });
2130
2131 clearTimeout(this._pendingDoubleTap.timer);
2132
2133 delete this._pendingDoubleTap;
2134
2135 }else{
2136
2137 this._onGridClick({
2138 date: this.getTime(this._gridProps.event),
2139 triggerEvent: this._gridProps.event
2140 });
2141
2142 this._pendingDoubleTap = {
2143 grid: true,
2144 timer: setTimeout(lang.hitch(this, function(){
2145 delete this._pendingDoubleTap;
2146 }), this.doubleTapDelay)
2147 };
2148 }
2149 }
2150 }
2151 }
2152
2153 this._gridProps = null;
2154 }
2155 },
2156
2157 _onColumnHeaderClick: function(e){
2158 // tags:
2159 // private
2160
2161 this._dispatchCalendarEvt(e, "onColumnHeaderClick");
2162 },
2163
2164
2165
2166 onColumnHeaderClick: function(e){
2167 // summary:
2168 // Event dispatched when a column header cell is dispatched.
2169 // e: __ColumnClickEventArgs
2170 // The event has the following properties
2171 // tags:
2172 // callback
2173 },
2174
2175
2176 getTimeOfDay: function (pos, rd) {
2177 // summary:
2178 // Return the time of day associated to the specified position.
2179 // pos: Integer
2180 // The position in pixels.
2181 // rd: Object
2182 // The render data.
2183 var minH = rd.minHours*60;
2184 var maxH = rd.maxHours*60;
2185 var minutes = minH + (pos * (maxH - minH) / rd.sheetHeight);
2186 return {
2187 hours: Math.floor(minutes / 60),
2188 minutes: Math.floor(minutes % 60)
2189 };
2190 },
2191
2192 ///////////////////////////////////////////////////////////////
2193 //
2194 // View limits
2195 //
2196 ///////////////////////////////////////////////////////////////
2197
2198 _isItemInView: function(item){
2199
2200 // subclassed to add some tests
2201
2202 var res = this.inherited(arguments);
2203
2204 if(res){
2205
2206 // test if time range is overlapping [maxHours, next day min hours]
2207 var rd = this.renderData;
2208
2209 var len = rd.dateModule.difference(item.startTime, item.endTime, "millisecond");
2210 var vLen = (24 - rd.maxHours + rd.minHours) * 3600000; // 60 * 60 * 1000, number of milliseconds in 1 minute
2211
2212 if(len > vLen){ // longer events are always visible
2213 return true;
2214 }
2215
2216 var sMin = item.startTime.getHours()*60 + item.startTime.getMinutes();
2217 var eMin = item.endTime.getHours()*60 + item.endTime.getMinutes();
2218 var sV = rd.minHours * 60;
2219 var eV = rd.maxHours * 60;
2220
2221 if(sMin > 0 && sMin < sV || sMin > eV && sMin <= 1440){
2222 return false;
2223 }
2224
2225 if(eMin > 0 && eMin < sV || eMin > eV && eMin <= 1440){
2226 return false;
2227 }
2228 }
2229 return res;
2230 },
2231
2232 _ensureItemInView: function(item){
2233
2234 var fixed;
2235
2236 var startTime = item.startTime;
2237 var endTime = item.endTime;
2238
2239 // test if time range is overlapping [maxHours, next day min hours]
2240 var rd = this.renderData;
2241 var cal = rd.dateModule;
2242
2243 var len = Math.abs(cal.difference(item.startTime, item.endTime, "millisecond"));
2244 var vLen = (24 - rd.maxHours + rd.minHours) * 3600000;
2245
2246 if(len > vLen){ // longer events are always visible
2247 return false;
2248 }
2249
2250 var sMin = startTime.getHours()*60 + startTime.getMinutes();
2251 var eMin = endTime.getHours()*60 + endTime.getMinutes();
2252 var sV = rd.minHours * 60;
2253 var eV = rd.maxHours * 60;
2254
2255 if(sMin > 0 && sMin < sV){
2256 this.floorToDay(item.startTime, true, rd);
2257 item.startTime.setHours(rd.minHours);
2258 item.endTime = cal.add(item.startTime, "millisecond", len);
2259 fixed = true;
2260 }else if(sMin > eV && sMin <= 1440){
2261 // go on next visible time
2262 this.floorToDay(item.startTime, true, rd);
2263 item.startTime = cal.add(item.startTime, "day", 1);
2264 // if we are going out of the view, the super() will fix it
2265 item.startTime.setHours(rd.minHours);
2266 item.endTime = cal.add(item.startTime, "millisecond", len);
2267 fixed = true;
2268 }
2269
2270 if(eMin > 0 && eMin < sV){
2271 // go on previous day
2272 this.floorToDay(item.endTime, true, rd);
2273 item.endTime = cal.add(item.endTime, "day", -1);
2274 item.endTime.setHours(rd.maxHours);
2275 item.startTime = cal.add(item.endTime, "millisecond", -len);
2276 fixed = true;
2277 }else if(eMin > eV && eMin <= 1440){
2278 this.floorToDay(item.endTime, true, rd);
2279 item.endTime.setHours(rd.maxHours);
2280 item.startTime = cal.add(item.endTime, "millisecond", -len);
2281 fixed = true;
2282 }
2283
2284 fixed = fixed || this.inherited(arguments);
2285
2286 return fixed;
2287 },
2288
2289 _onScrollTimer_tick: function(){
2290 // tags:
2291 // private
2292
2293 this._scrollToPosition(this._getScrollPosition() + this._scrollProps.scrollStep);
2294 },
2295
2296 ////////////////////////////////////////////
2297 //
2298 // Editing
2299 //
2300 ///////////////////////////////////////////
2301
2302 snapUnit: "minute",
2303 snapSteps: 15,
2304 minDurationUnit: "minute",
2305 minDurationSteps: 15,
2306 liveLayout: false,
2307 stayInView: true,
2308 allowStartEndSwap: true,
2309 allowResizeLessThan24H: true
2310
2311 });
2312 });