Debian Codegraph @

dojox/calendar/MonthColumnView.js

raw symbols SCIP
1 define([
2 "./ViewBase",
3 "dijit/_TemplatedMixin",
4 "./_ScrollBarBase",
5 "dojo/text!./templates/MonthColumnView.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 "dojo/i18n",
22 "dojox/html/metrics"],
23
24 function(
25 ViewBase,
26 _TemplatedMixin,
27 _ScrollBarBase,
28 template,
29 declare,
30 event,
31 lang,
32 arr,
33 has,
34 fx,
35 html,
36 on,
37 dom,
38 domClass,
39 domStyle,
40 domGeometry,
41 domConstruct,
42 mouse,
43 query,
44 i18n,
45 metrics){
46
47 /*=====
48 var __ColumnClickEventArgs = {
49 // summary:
50 // A column click event.
51 // index: Integer
52 // The column index.
53 // date: Date
54 // The date displayed by the column.
55 // triggerEvent: Event
56 // The origin event.
57 };
58 =====*/
59
60 return declare("dojox.calendar.MonthColumnView", [ViewBase, _TemplatedMixin], {
61
62 // summary:
63 // The month column view is a calendar view used to display a month per column where each cell of the column is a day.
64
65 baseClass: "dojoxCalendarMonthColumnView",
66
67 templateString: template,
68
69 // viewKind: String
70 // Type of the view. Used by the calendar widget to determine how to configure the view.
71 // This view kind is "columns".
72 viewKind: "monthColumns",
73
74 // scroll container is the focusable item to enable scrolling using up and down arrows
75 _setTabIndexAttr: "domNode",
76
77 // renderData: Object
78 // The render data is the object that contains all the properties needed to render the component.
79 renderData: null,
80
81 // startDate: Date
82 // The start date of the time interval displayed.
83 // If not set at initialization time, will be set to current day.
84 startDate: null,
85
86 // columnCount: Integer
87 // The number of column to display (from the startDate).
88 columnCount: 6,
89
90 // daySize: Integer
91 // The desired size in pixels of an hour on the screen.
92 // Note that the effective size may be different as the time slot size must be an integer.
93 daySize: 30,
94
95 // showCellLabel: Boolean
96 // Whether display or not the grid cells label (usually the day of month).
97 showCellLabel: true,
98
99 // showHiddenItems: Boolean
100 // Whether show or not the hidden items.
101 // By default the events that are shorter than a day are not displayed using vertical renderers by this widget.
102 // But the grid cells that contains one or several hidden items display a decoration.
103 showHiddenItems: true,
104
105 // verticalRenderer: Class
106 // The class use to create vertical renderers.
107 verticalRenderer: null,
108
109 // verticalDecorationRenderer: Class
110 // The class use to create vertical decoration renderers.
111 verticalDecorationRenderer: null,
112
113 // percentOverlap: Integer
114 // The percentage of the renderer width used to superimpose one item renderer on another
115 // when two events are overlapping.
116 percentOverlap: 0,
117
118 // horizontalGap: Integer
119 // The number of pixels between two item renderers.
120 horizontalGap: 4,
121
122 // columnHeaderFormatLength: String
123 // Length of the column labels. Valid values are "wide" or "abbr".
124 columnHeaderFormatLength: null,
125
126 // gridCellDatePattern: String
127 // The date pattern of the cell labels. By default a custom function is used to compute the label.
128 gridCellDatePattern: null,
129
130 // roundToDay: [private] Boolean
131 roundToDay: true,
132
133 // _layoutUnit: String
134 // Unit of layout: each column is displaying a month.
135 _layoutUnit: "month",
136
137 _columnHeaderHandlers: null,
138
139 constructor: function(){
140 this.invalidatingProperties = ["columnCount", "startDate", "daySize", "percentOverlap", "verticalRenderer", "verticalDecorationRenderer",
141 "columnHeaderDatePattern", "horizontalGap", "scrollBarRTLPosition", "itemToRendererKindFunc",
142 "layoutPriorityFunction", "textDir", "items", "showCellLabel", "showHiddenItems"];
143 this._columnHeaderHandlers = [];
144 },
145
146 postCreate: function(){
147 this.inherited(arguments);
148 this.keyboardUpDownUnit = "day";
149 this.keyboardUpDownSteps = 1;
150 this.keyboardLeftRightUnit = "month";
151 this.keyboardLeftRightSteps = 1;
152 this.allDayKeyboardUpDownUnit = "day";
153 this.allDayKeyboardUpDownSteps = 1;
154 this.allDayKeyboardLeftRightUnit = "month";
155 this.allDayKeyboardLeftRightSteps = 1;
156 },
157
158 destroy: function(preserveDom){
159 this._cleanupColumnHeader();
160 if(this.scrollBar){
161 this.scrollBar.destroy(preserveDom);
162 }
163 this.inherited(arguments);
164 },
165
166 _scrollBar_onScroll: function(value){
167 // tags:
168 // private
169 this.scrollContainer.scrollTop = value;
170 },
171
172 buildRendering: function(){
173 // tags:
174 // private
175 this.inherited(arguments);
176 if(this.vScrollBar){
177 this.scrollBar = new _ScrollBarBase(
178 {content: this.vScrollBarContent},
179 this.vScrollBar);
180
181 this.scrollBar.on("scroll", lang.hitch(this, this._scrollBar_onScroll));
182 this._viewHandles.push(
183 on(this.scrollContainer, mouse.wheel,
184 dojo.hitch(this, this._mouseWheelScrollHander)));
185 }
186 },
187
188 postscript: function(){
189 this.inherited(arguments);
190 this._initialized = true;
191 if(!this.invalidRendering){
192 this.refreshRendering();
193 }
194 },
195
196 _setVerticalRendererAttr: function(value){
197 this._destroyRenderersByKind("vertical");
198 this._set("verticalRenderer", value);
199 },
200
201 _createRenderData: function(){
202
203 var rd = {};
204
205 rd.daySize = this.get("daySize");
206 rd.scrollbarWidth = metrics.getScrollbar().w + 1;
207
208 rd.dateLocaleModule = this.dateLocaleModule;
209 rd.dateClassObj = this.dateClassObj;
210 rd.dateModule = this.dateModule; // arithmetics on Dates
211
212 rd.dates = [];
213
214 rd.columnCount = this.get("columnCount");
215
216 var d = this.get("startDate");
217
218 if (d == null){
219 d = new rd.dateClassObj();
220 }
221
222 d = this.floorToMonth(d, false, rd);
223
224 this.startDate = d;
225 var currentMonth = d.getMonth();
226 var maxDayCount = 0;
227
228 for(var col = 0; col < rd.columnCount ; col++){
229
230 var dates = [];
231 rd.dates.push(dates);
232
233 while(d.getMonth() == currentMonth){
234 dates.push(d);
235 d = this.addAndFloor(d, "day", 1);
236 }
237
238 currentMonth = d.getMonth();
239
240 if(maxDayCount < dates.length){
241 maxDayCount = dates.length;
242 }
243 }
244
245 rd.startTime = new rd.dateClassObj(rd.dates[0][0]);
246 rd.endTime = new rd.dateClassObj(dates[dates.length-1]);
247 rd.endTime = rd.dateModule.add(rd.endTime, "day", 1);
248
249 rd.maxDayCount = maxDayCount;
250 rd.sheetHeight = rd.daySize * maxDayCount;
251
252 if(this.displayedItemsInvalidated && !this._isEditing){
253 this.displayedItemsInvalidated = false;
254 this._computeVisibleItems(rd);
255
256 }else if (this.renderData){
257 rd.items = this.renderData.items;
258 }
259
260 if(this.displayedDecorationItemsInvalidated){
261 // while editing in no live layout we must not to recompute items (duplicate renderers)
262 rd.decorationItems = this.decorationStoreManager._computeVisibleItems(rd);
263
264 }else if (this.renderData){
265 rd.decorationItems = this.renderData.decorationItems;
266 }
267
268 return rd;
269 },
270
271 _validateProperties: function() {
272
273 this.inherited(arguments);
274
275 if (this.columnCount<1 || isNaN(this.columnCount)){
276 this.columnCount = 1;
277 }
278
279 if(this.daySize<5 || isNaN(this.daySize)){
280 this.daySize = 5;
281 }
282
283 },
284
285 _setStartDateAttr: function(value){
286 this.displayedItemsInvalidated = true;
287 this._set("startDate", value);
288 },
289
290 _setColumnCountAttr: function(value){
291 this.displayedItemsInvalidated = true;
292 this._set("columnCount", value);
293 },
294
295 __fixEvt:function(e){
296 e.sheet = "primary";
297 e.source = this;
298 return e;
299 },
300
301 //////////////////////////////////////////
302 //
303 // Formatting functions
304 //
305 //////////////////////////////////////////
306
307 _formatColumnHeaderLabel: function(/*Date*/d){
308 // summary:
309 // Computes the column header label for the specified date.
310 // d: Date
311 // The date to format
312 // tags:
313 // protected
314
315 var len = "wide";
316
317 if(this.columnHeaderFormatLength){
318 len = this.columnHeaderFormatLength;
319 }
320
321 var months = this.renderData.dateLocaleModule.getNames("months", len, "standAlone");
322
323 return months[d.getMonth()];
324 },
325
326 // gridCellDatePattern: String
327 // Custom date/time pattern for cell labels to override default one coming from the CLDR.
328 // See dojo/date/locale documentation for format string.
329 gridCellDatePattern: null,
330
331 _formatGridCellLabel: function(d, row, col){
332 // summary:
333 // Computes the column header label for the specified date.
334 // By default a formatter is used, optionally the <code>gridCellDatePattern</code>
335 // property can be used to set a custom date pattern to the formatter.
336 // d: Date
337 // The date to format.
338 // row: Integer
339 // The row that displays the current date.
340 // col: Integer
341 // The column that displays the current date.
342 // tags:
343 // protected
344
345 var format, rb;
346
347 if(d == null){
348 return "";
349 }
350
351 if(this.gridCellPattern){
352 return this.renderData.dateLocaleModule.format(d, {
353 selector: 'date',
354 datePattern: this.gridCellDatePattern
355 });
356 }else{
357 rb = i18n.getLocalization("dojo.cldr", this._calendar);
358 format = rb["dateFormatItem-d"];
359
360 var days = this.renderData.dateLocaleModule.getNames("days", "abbr", "standAlone");
361
362 return days[d.getDay()].substring(0, 1) + " " + this.renderData.dateLocaleModule.format(d, {
363 selector: 'date',
364 datePattern: format
365 });
366 }
367 },
368
369 //////////////////////////////////////////
370 //
371 // Time of day management
372 //
373 //////////////////////////////////////////
374
375 // scrollPosition: Integer
376 // The scroll position of the view.
377 scrollPosition: null,
378
379 // scrollBarRTLPosition: String
380 // Position of the scroll bar in right-to-left display.
381 // Valid values are "left" and "right", default value is "left".
382 scrollBarRTLPosition: "left",
383
384 _setScrollPositionAttr: function(value){
385 this._setScrollPosition(value.date, value.duration, value.easing);
386 },
387
388 _getScrollPositionAttr: function(){
389 return {date: (this.scrollContainer.scrollTop / this.daySize) + 1};
390 },
391
392 _setScrollPosition: function(date, maxDuration, easing){
393 // tags:
394 // private
395
396 if(date < 1){
397 date = 1;
398 }else if(date>31){
399 date = 31;
400 }
401
402 var position = (date-1) * this.daySize;
403
404 if(maxDuration) {
405
406 if(this._scrollAnimation){
407 this._scrollAnimation.stop();
408 }
409
410 var duration = Math.abs(((position - this.scrollContainer.scrollTop) * maxDuration) / this.renderData.sheetHeight);
411
412 this._scrollAnimation = new fx.Animation({
413 curve: [this.scrollContainer.scrollTop, position],
414 duration: duration,
415 easing: easing,
416 onAnimate: lang.hitch(this, function(position) {
417 this._setScrollImpl(position);
418 })
419 });
420
421 this._scrollAnimation.play();
422
423 }else{
424 this._setScrollImpl(position);
425 }
426 },
427
428 _setScrollImpl: function(v){
429 // tags:
430 // private
431
432 this.scrollContainer.scrollTop = v;
433 if(this.scrollBar){
434 this.scrollBar.set("value", v);
435 }
436 },
437
438 ensureVisibility: function(start, end, visibilityTarget, margin, duration){
439
440 // summary:
441 // Scrolls the view if the [start, end] time range is not visible or only partially visible.
442 // start: Date
443 // Start time of the range of interest.
444 // end: Date
445 // End time of the range of interest.
446 // margin: Integer
447 // Margin in minutes around the time range.
448 // visibilityTarget: String
449 // The end(s) of the time range to make visible.
450 // Valid values are: "start", "end", "both".
451 // duration: Number
452 // Optional, the maximum duration of the scroll animation.
453
454 margin = margin == undefined ? 1 : margin;
455
456 if(this.scrollable && this.autoScroll){
457
458 var s = start.getDate() - margin; // -1 because day of months starts at 1 and not 0
459 if(this.isStartOfDay(end)){
460 end = this._waDojoxAddIssue(end, "day", -1);
461 }
462 var e = end.getDate() + margin;
463
464 var viewStart = this.get("scrollPosition").date;
465 var r = domGeometry.getContentBox(this.scrollContainer);
466 var viewEnd = (this.get("scrollPosition").date + (r.h/this.daySize));
467
468 var visible = false;
469 var target = null;
470
471 switch(visibilityTarget){
472 case "start":
473 visible = s >= viewStart && s <= viewEnd;
474 target = s ;
475 break;
476 case "end":
477 visible = e >= viewStart && e <= viewEnd;
478 target = e - (viewEnd - viewStart);
479 break;
480 case "both":
481 visible = s >= viewStart && e <= viewEnd;
482 target = s;
483 break;
484 }
485
486 if(!visible){
487 this._setScrollPosition(target, duration);
488 }
489 }
490 },
491
492 scrollView: function(dir){
493 // summary:
494 // Scrolls the view to the specified direction of one time slot duration.
495 // dir: Integer
496 // Direction of the scroll. Valid values are -1 and 1.
497 //
498 var pos = this.get("scrollPosition").date + dir;
499 this._setScrollPosition(pos);
500 },
501
502 _mouseWheelScrollHander: function(e){
503 // summary:
504 // Mouse wheel handler.
505 // tags:
506 // protected
507 this.scrollView(e.wheelDelta > 0 ? -1 : 1);
508 },
509
510 //////////////////////////////////////////
511 //
512 // HTML structure management
513 //
514 //////////////////////////////////////////
515
516 refreshRendering: function(){
517 if(!this._initialized){
518 return;
519 }
520
521 this._validateProperties();
522
523 var oldRd = this.renderData;
524 var rd = this.renderData = this._createRenderData();
525
526 this._createRendering(rd, oldRd);
527 this._layoutDecorationRenderers(rd);
528 this._layoutRenderers(rd);
529 },
530
531 _createRendering: function(/*Object*/renderData, /*Object*/oldRenderData){
532 // tags:
533 // private
534 domStyle.set(this.sheetContainer, "height", renderData.sheetHeight + "px");
535 // padding for the scroll bar.
536 this._configureScrollBar(renderData);
537 this._buildColumnHeader(renderData, oldRenderData);
538 this._buildGrid(renderData, oldRenderData);
539 this._buildItemContainer(renderData, oldRenderData);
540 },
541
542 _configureScrollBar: function(renderData){
543 // summary:
544 // Sets the scroll bar size and position.
545 // renderData: Object
546 // The render data.
547 // tags:
548 // protected
549
550 if(has("ie") && this.scrollBar){
551 domStyle.set(this.scrollBar.domNode, "width", (renderData.scrollbarWidth + 1) + "px");
552 }
553
554 var atRight = this.isLeftToRight() ? true : this.scrollBarRTLPosition == "right";
555 var rPos = atRight ? "right" : "left";
556 var lPos = atRight? "left" : "right";
557
558 if(this.scrollBar){
559 this.scrollBar.set("maximum", renderData.sheetHeight);
560 domStyle.set(this.scrollBar.domNode, rPos, 0);
561 domStyle.set(this.scrollBar.domNode, lPos, "auto");
562 }
563 domStyle.set(this.scrollContainer, rPos, renderData.scrollbarWidth + "px");
564 domStyle.set(this.scrollContainer, lPos, "0");
565 domStyle.set(this.columnHeader, rPos, renderData.scrollbarWidth + "px");
566 domStyle.set(this.columnHeader, lPos, "0");
567 if(this.buttonContainer && this.owner != null && this.owner.currentView == this){
568 domStyle.set(this.buttonContainer, rPos, renderData.scrollbarWidth + "px");
569 domStyle.set(this.buttonContainer, lPos, "0");
570 }
571 },
572
573 _columnHeaderClick: function(e){
574 // tags:
575 // private
576
577 event.stop(e);
578 var index = query("td", this.columnHeaderTable).indexOf(e.currentTarget);
579 this._onColumnHeaderClick({
580 index: index,
581 date: this.renderData.dates[index][0],
582 triggerEvent: e
583 });
584 },
585
586 _buildColumnHeader: function(renderData, oldRenderData){
587 // summary:
588 // Creates incrementally the HTML structure of the column header and configures its content.
589 //
590 // renderData:
591 // The render data to display.
592 //
593 // oldRenderData:
594 // The previously render data displayed, if any.
595 // tags:
596 // private
597
598
599 var table = this.columnHeaderTable;
600
601 if (!table){
602 return;
603 }
604
605 var count = renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0);
606
607 if(has("ie") == 8){
608 // workaround Internet Explorer 8 bug.
609 // if on the table, width: 100% and table-layout: fixed are set
610 // and columns are removed, width of remaining columns is not
611 // recomputed: must rebuild all.
612 if(this._colTableSave == null){
613 this._colTableSave = lang.clone(table);
614 }else if(count < 0){
615 this._cleanupColumnHeader();
616 this.columnHeader.removeChild(table);
617 domConstruct.destroy(table);
618 table = lang.clone(this._colTableSave);
619 this.columnHeaderTable = table;
620 this.columnHeader.appendChild(table);
621 count = renderData.columnCount;
622 }
623
624 } // else incremental dom add/remove for real browsers.
625
626 var tbodies = query("tbody", table);
627
628 var trs = query("tr", table);
629 var tbody, tr, td;
630
631 if (tbodies.length == 1){
632 tbody = tbodies[0];
633 }else{
634 tbody = html.create("tbody", null, table);
635 }
636
637 if (trs.length == 1){
638 tr = trs[0];
639 }else{
640 tr = domConstruct.create("tr", null, tbody);
641 }
642
643 // Build HTML structure (incremental)
644 if(count > 0){ // creation
645 for(var i=0; i < count; i++){
646
647 td = domConstruct.create("td", null, tr);
648
649 var h = [];
650 h.push(on(td, "click", lang.hitch(this, this._columnHeaderClick)));
651
652 if(has("touch-events")){
653 h.push(on(td, "touchstart", function(e){
654 event.stop(e);
655 domClass.add(e.currentTarget, "Active");
656 }));
657
658 h.push(on(td, "touchend", function(e){
659 event.stop(e);
660 domClass.remove(e.currentTarget, "Active");
661 }));
662 }else{
663 h.push(on(td, "mousedown", function(e){
664 event.stop(e);
665 domClass.add(e.currentTarget, "Active");
666 }));
667
668 h.push(on(td, "mouseup", function(e){
669 event.stop(e);
670 domClass.remove(e.currentTarget, "Active");
671 }));
672
673 h.push(on(td, "mouseover", function(e){
674 event.stop(e);
675 domClass.add(e.currentTarget, "Hover");
676 }));
677
678 h.push(on(td, "mouseout", function(e){
679 event.stop(e);
680 domClass.remove(e.currentTarget, "Hover");
681 }));
682
683 }
684
685 this._columnHeaderHandlers.push(h);
686 }
687
688 }else{ // deletion
689 count = -count;
690 for(var i=0; i < count; i++){
691 td = tr.lastChild;
692 tr.removeChild(td);
693 domConstruct.destroy(td);
694 var list = this._columnHeaderHandlers.pop();
695 while(list.length>0){
696 list.pop().remove();
697 }
698 }
699 }
700
701 // fill & configure
702 query("td", table).forEach(function(td, i){
703 td.className = "";
704 if(i == 0){
705 domClass.add(td, "first-child");
706 }else if(i == this.renderData.columnCount-1){
707 domClass.add(td, "last-child");
708 }
709 var d = renderData.dates[i][0];
710 this._setText(td, this._formatColumnHeaderLabel(d));
711 this.styleColumnHeaderCell(td, d, renderData);
712 }, this);
713
714 },
715
716 _cleanupColumnHeader: function(){
717 // tags:
718 // private
719
720 while(this._columnHeaderHandlers.length > 0){
721 var list = this._columnHeaderHandlers.pop();
722 while(list.length > 0){
723 list.pop().remove();
724 }
725 }
726 },
727
728 styleColumnHeaderCell: function(node, date, renderData){
729 // summary:
730 // Styles the CSS classes to the node that displays a column header cell.
731 // By default this method is does nothing and is designed to be overridden.
732 // node: Node
733 // The DOM node that displays the column in the grid.
734 // date: Date
735 // The date displayed by this column
736 // renderData: Object
737 // The render data.
738 // tags:
739 // protected
740
741 },
742
743 _buildGrid: function (renderData, oldRenderData){
744 // summary:
745 // Creates incrementally the HTML structure of the grid and configures its content.
746 //
747 // renderData:
748 // The render data to display.
749 //
750 // oldRenderData:
751 // The previously render data displayed, if any.
752 // tags:
753 // private
754
755
756 var table = this.gridTable;
757
758 if(!table){
759 return;
760 }
761
762 domStyle.set(table, "height", renderData.sheetHeight + "px");
763
764 var rowDiff = renderData.maxDayCount - (oldRenderData ? oldRenderData.maxDayCount : 0);
765 var addRows = rowDiff > 0;
766
767 var colDiff = renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0);
768
769 if(has("ie") == 8){
770 // workaround Internet Explorer 8 bug.
771 // if on the table, width: 100% and table-layout: fixed are set
772 // and columns are removed, width of remaining columns is not
773 // recomputed: must rebuild all.
774 if(this._gridTableSave == null){
775 this._gridTableSave = lang.clone(table);
776 }else if(colDiff < 0){
777 this.grid.removeChild(table);
778 domConstruct.destroy(table);
779 table = lang.clone(this._gridTableSave);
780 this.gridTable = table;
781 this.grid.appendChild(table);
782 colDiff = renderData.columnCount;
783 rowDiff = renderData.maxDayCount;
784 addRows = true;
785 }
786 }
787
788 var tbodies = query("tbody", table);
789 var tbody;
790
791 if(tbodies.length == 1){
792 tbody = tbodies[0];
793 }else{
794 tbody = domConstruct.create("tbody", null, table);
795 }
796
797 // Build rows HTML structure (incremental)
798 if(addRows){ // creation
799 for(var i=0; i<rowDiff; i++){
800 domConstruct.create("tr", null, tbody);
801 }
802 }else{ // deletion
803 rowDiff = -rowDiff;
804 for(var i=0; i<rowDiff; i++){
805 tbody.removeChild(tbody.lastChild);
806 }
807 }
808
809 var rowIndex = renderData.maxDayCount - rowDiff;
810
811 var addCols = addRows || colDiff >0;
812 colDiff = addCols ? colDiff : -colDiff;
813
814 query("tr", table).forEach(function(tr, i){
815
816 if(addCols){ // creation
817 var len = i >= rowIndex ? renderData.columnCount : colDiff;
818 for(var i=0; i<len; i++){
819 var td = domConstruct.create("td", null, tr);
820 domConstruct.create("span", null, td);
821 }
822 }else{ // deletion
823 for(var i=0; i<colDiff; i++){
824 tr.removeChild(tr.lastChild);
825 }
826 }
827 });
828
829 // Set the CSS classes
830
831 query("tr", table).forEach(function (tr, row){
832
833 tr.className = "";
834 // compatibility layer for IE7 & 8 that does not support :first-child and :last-child pseudo selectors
835 if(row == 0){
836 domClass.add(tr, "first-child");
837 }
838 if(row == renderData.maxDayCount-1){
839 domClass.add(tr, "last-child");
840 }
841
842 query("td", tr).forEach(function (td, col){
843
844 td.className = "";
845
846 if(col == 0){
847 domClass.add(td, "first-child");
848 }
849
850 if(col == renderData.columnCount-1){
851 domClass.add(td, "last-child");
852 }
853
854 var d = null;
855 if(row < renderData.dates[col].length) {
856 d = renderData.dates[col][row];
857 }
858
859 var span = query("span", td)[0];
860 this._setText(span, this.showCellLabel ? this._formatGridCellLabel(d, row, col): null);
861
862 this.styleGridCell(td, d, col, row, renderData);
863
864 }, this);
865 }, this);
866
867 },
868
869 // styleGridCellFunc: Function
870 // Custom function to customize the appearance of a grid cell by installing custom CSS class on the node.
871 // The signature of the function must be the same then the styleGridCell one.
872 // By default the defaultStyleGridCell function is used.
873 styleGridCellFunc: null,
874
875 defaultStyleGridCell: function(node, date, col, row, renderData){
876 // summary:
877 // Styles the CSS classes to the node that displays a column.
878 // By default this method is setting the following CSS classes:
879 // - "dojoxCalendarToday" class name if the date displayed is the current date,
880 // - "dojoxCalendarWeekend" if the date represents a weekend,
881 // - the CSS class corresponding of the displayed day of week ("Sun", "Mon" and so on),
882 // node: Node
883 // The DOM node that displays the cell in the grid.
884 // date: Date
885 // The date displayed by this cell.
886 // col: Integer
887 // The column index of this cell.
888 // row: Integer
889 // The row index of this cell.
890 // renderData: Object
891 // The render data.
892 // tags:
893 // protected
894
895 if(date == null){
896 return;
897 }
898 domClass.add(node, this._cssDays[date.getDay()]);
899 if(this.isToday(date)){
900 domClass.add(node, "dojoxCalendarToday");
901 }else if(this.isWeekEnd(date)){
902 domClass.add(node, "dojoxCalendarWeekend");
903 }
904 },
905
906 styleGridCell: function(node, date, col, row, renderData){
907 // summary:
908 // Styles the CSS classes to the node that displays a column.
909 // Delegates to styleGridCellFunc if defined or defaultStyleGridCell otherwise.
910 // node: Node
911 // The DOM node that displays the cell in the grid.
912 // date: Date
913 // The date displayed by this cell.
914 // col: Integer
915 // The column index of this cell.
916 // row: Integer
917 // The row index of this cell.
918 // renderData: Object
919 // The render data.
920 // tags:
921 // protected
922
923 if(this.styleGridCellFunc){
924 this.styleGridCellFunc(node, date, col, row, renderData);
925 }else{
926 this.defaultStyleGridCell(node, date, col, row, renderData);
927 }
928 },
929
930 _buildItemContainer: function(renderData, oldRenderData){
931 // summary:
932 // Creates the HTML structure of the item container and configures its content.
933 // renderData:
934 // The render data to display.
935 // oldRenderData:
936 // The previously render data displayed, if any.
937 // tags:
938 // private
939
940
941 var table = this.itemContainerTable;
942
943 if (!table){
944 return;
945 }
946
947 var bgCols = [];
948
949 domStyle.set(table, "height", renderData.sheetHeight + "px");
950
951 var count = renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0);
952
953 if(has("ie") == 8){
954 // workaround Internet Explorer 8 bug.
955 // if on the table, width: 100% and table-layout: fixed are set
956 // and columns are removed, width of remaining columns is not
957 // recomputed: must rebuild all.
958 if(this._itemTableSave == null){
959 this._itemTableSave = lang.clone(table);
960 }else if(count < 0){
961 this.itemContainer.removeChild(table);
962 this._recycleItemRenderers(true);
963 domConstruct.destroy(table);
964 table = lang.clone(this._itemTableSave);
965 this.itemContainerTable = table;
966 this.itemContainer.appendChild(table);
967 count = renderData.columnCount;
968 }
969
970 } // else incremental dom add/remove for real browsers.
971
972 var tbodies = query("tbody", table);
973 var trs = query("tr", table);
974 var tbody, tr, td;
975
976 if (tbodies.length == 1){
977 tbody = tbodies[0];
978 }else{
979 tbody = domConstruct.create("tbody", null, table);
980 }
981
982 if (trs.length == 1){
983 tr = trs[0];
984 }else{
985 tr = domConstruct.create("tr", null, tbody);
986 }
987
988 // Build HTML structure (incremental)
989 if(count>0){ // creation
990 for(var i=0; i < count; i++){
991 td = domConstruct.create("td", null, tr);
992 domConstruct.create("div", {"className": "dojoxCalendarContainerColumn"}, td);
993 }
994 }else{ // deletion
995 count = -count;
996 for(var i=0; i < count; i++){
997 tr.removeChild(tr.lastChild);
998 }
999 }
1000
1001 query("td>div", table).forEach(function(div, i){
1002
1003 domStyle.set(div, {
1004 "height": renderData.sheetHeight + "px"
1005 });
1006 bgCols.push(div);
1007 }, this);
1008
1009 renderData.cells = bgCols;
1010 },
1011
1012 ///////////////////////////////////////////////////////////////
1013 //
1014 // Layout
1015 //
1016 ///////////////////////////////////////////////////////////////
1017
1018 _overlapLayoutPass2: function(lanes){
1019 // summary:
1020 // Second pass of the overlap layout (optional). Compute the extent of each layout item.
1021 // lanes:
1022 // The array of lanes.
1023 // tags:
1024 // private
1025 var i,j,lane, layoutItem;
1026 // last lane, no extent possible
1027 lane = lanes[lanes.length-1];
1028
1029 for(j = 0; j < lane.length; j++){
1030 lane[j].extent = 1;
1031 }
1032
1033 for(i=0; i<lanes.length-1; i++){
1034 lane = lanes[i];
1035
1036 for(var j=0; j<lane.length; j++){
1037 layoutItem = lane[j];
1038
1039 // if item was already overlapping another one there is no extent possible.
1040 if(layoutItem.extent == -1){
1041 layoutItem.extent = 1;
1042 var space = 0;
1043
1044 var stop = false;
1045
1046 for(var k = i + 1; k < lanes.length && !stop; k++){
1047 var ccol = lanes[k];
1048 for(var l = 0; l < ccol.length && !stop; l++){
1049 var layoutItem2 = ccol[l];
1050
1051 if(layoutItem.start < layoutItem2.end && layoutItem2.start < layoutItem.end){
1052 stop = true;
1053 }
1054 }
1055 if(!stop){
1056 //no hit in the entire lane
1057 space++;
1058 }
1059 }
1060 layoutItem.extent += space;
1061 }
1062 }
1063 }
1064 },
1065
1066 _defaultItemToRendererKindFunc: function(item){
1067 // tags:
1068 // private
1069
1070 if(item.allDay){
1071 return "vertical";
1072 }
1073 var dur = Math.abs(this.renderData.dateModule.difference(item.startTime, item.endTime, "minute"));
1074 return dur >= 1440 ? "vertical" : null;
1075 },
1076
1077 _layoutRenderers: function(renderData){
1078 this.hiddenEvents = {};
1079 this.inherited(arguments);
1080 },
1081
1082 _layoutInterval: function(/*Object*/renderData, /*Integer*/index, /*Date*/start, /*Date*/end, /*Object[]*/items, /*String*/itemsType){
1083 // tags:
1084 // private
1085
1086 var verticalItems = [];
1087 var hiddenItems = [];
1088 renderData.colW = this.itemContainer.offsetWidth / renderData.columnCount;
1089
1090 if(itemsType === "dataItems"){
1091
1092 for(var i=0; i<items.length; i++){
1093 var item = items[i];
1094 if(this._itemToRendererKind(item) == "vertical"){
1095 verticalItems.push(item);
1096 }else if(this.showHiddenItems){
1097 hiddenItems.push(item);
1098 }
1099 }
1100
1101 if(verticalItems.length > 0){
1102 this._layoutVerticalItems(renderData, index, start, end, verticalItems, itemsType);
1103 }
1104 if(hiddenItems.length > 0){
1105 this._layoutBgItems(renderData, index, start, end, hiddenItems);
1106 }
1107 }else{ // itemsType === "decorationItems"
1108 this._layoutVerticalItems(renderData, index, start, end, items, itemsType);
1109 }
1110 },
1111
1112 _dateToYCoordinate: function(renderData, d, start){
1113 // tags:
1114 // private
1115
1116 var pos = 0;
1117 if(start || d.getHours() != 0 || d.getMinutes() != 0){
1118 pos = (d.getDate()-1) * this.renderData.daySize;
1119 }else{
1120 var d2 = this._waDojoxAddIssue(d, "day", -1);
1121 pos = this.renderData.daySize + ((d2.getDate()-1) * this.renderData.daySize);
1122 }
1123 pos += (d.getHours()*60+d.getMinutes())*this.renderData.daySize/1440;
1124
1125 return pos;
1126 },
1127
1128 _layoutVerticalItems: function(/*Object*/renderData, /*Integer*/index, /*Date*/startTime, /*Date*/endTime, /*Object[]*/items, /*String*/itemsType){
1129 // tags:
1130 // private
1131
1132 if(this.verticalRenderer == null){
1133 return;
1134 }
1135
1136 var cell = renderData.cells[index];
1137 var layoutItems = [];
1138
1139 // step 1 compute projected position and size
1140 for(var i = 0; i < items.length; i++){
1141
1142 var item = items[i];
1143 var overlap = this.computeRangeOverlap(renderData, item.startTime, item.endTime, startTime, endTime);
1144
1145 var top = this._dateToYCoordinate(renderData, overlap[0], true);
1146 var bottom = this._dateToYCoordinate(renderData, overlap[1], false);
1147
1148 if (bottom > top){
1149 var litem = lang.mixin({
1150 start: top,
1151 end: bottom,
1152 range: overlap,
1153 item: item
1154 }, item);
1155 layoutItems.push(litem);
1156 }
1157 }
1158
1159
1160
1161 // step 2: compute overlapping layout
1162 var numLanes = itemsType === "dataItems" ? this.computeOverlapping(layoutItems, this._overlapLayoutPass2).numLanes : 1;
1163
1164 var hOverlap = this.percentOverlap / 100;
1165
1166 // step 3: create renderers and apply layout
1167 for(i=0; i<layoutItems.length; i++){
1168
1169 item = layoutItems[i];
1170 var lane = item.lane;
1171 var extent = item.extent;
1172
1173 var ir = null;
1174
1175 if(itemsType === "dataItems"){
1176 var w;
1177 var posX;
1178
1179 if(hOverlap == 0) {
1180 //no overlap and a padding between each event
1181 w = numLanes == 1 ? renderData.colW : ((renderData.colW - (numLanes - 1) * this.horizontalGap)/ numLanes);
1182 posX = lane * (w + this.horizontalGap);
1183 w = extent == 1 ? w : w * extent + (extent-1) * this.horizontalGap;
1184 w = 100 * w / renderData.colW;
1185 posX = 100 * posX / renderData.colW;
1186 } else {
1187 // an overlap
1188 w = numLanes == 1 ? 100 : (100 / (numLanes - (numLanes - 1) * hOverlap));
1189 posX = lane * (w - hOverlap*w);
1190 w = extent == 1 ? w : w * ( extent - (extent-1) * hOverlap);
1191 }
1192
1193 ir = this._createRenderer(item, "vertical", this.verticalRenderer, "dojoxCalendarVertical");
1194
1195 domStyle.set(ir.container, {
1196 "top": item.start + "px",
1197 "left": posX + "%",
1198 "width": w + "%",
1199 "height": (item.end-item.start+1) + "px"
1200 });
1201
1202 var edited = this.isItemBeingEdited(item);
1203 var selected = this.isItemSelected(item);
1204 var hovered = this.isItemHovered(item);
1205 var focused = this.isItemFocused(item);
1206
1207 var renderer = ir.renderer;
1208
1209 renderer.set("hovered", hovered);
1210 renderer.set("selected", selected);
1211 renderer.set("edited", edited);
1212 renderer.set("focused", this.showFocus ? focused : false);
1213
1214 renderer.set("storeState", this.getItemStoreState(item));
1215
1216 renderer.set("moveEnabled", this.isItemMoveEnabled(item._item, "vertical"));
1217 renderer.set("resizeEnabled", this.isItemResizeEnabled(item._item, "vertical"));
1218
1219 this.applyRendererZIndex(item, ir, hovered, selected, edited, focused);
1220
1221 if(renderer.updateRendering){
1222 renderer.updateRendering(w, item.end-item.start+1);
1223 }
1224
1225 }else{ //itemsType === "decorationItems"
1226
1227 ir = this.decorationRendererManager.createRenderer(item, "vertical", this.verticalDecorationRenderer, "dojoxCalendarDecoration");
1228
1229 domStyle.set(ir.container, {
1230 "top": item.start + "px",
1231 "left": "0",
1232 "width": "100%",
1233 "height": (item.end-item.start+1) + "px"
1234 });
1235 }
1236
1237 domConstruct.place(ir.container, cell);
1238 domStyle.set(ir.container, "display", "block");
1239 }
1240 },
1241
1242 _getCellAt: function(rowIndex, columnIndex, rtl){
1243 // tags:
1244 // private
1245
1246 if((rtl == undefined || rtl == true) && !this.isLeftToRight()){
1247 columnIndex = this.renderData.columnCount -1 - columnIndex;
1248 }
1249 return this.gridTable.childNodes[0].childNodes[rowIndex].childNodes[columnIndex];
1250 },
1251
1252 invalidateLayout: function(){
1253 //make sure to clear hiddens object state
1254 query("td", this.gridTable).forEach(function(td){
1255 domClass.remove(td, "dojoxCalendarHiddenEvents");
1256 });
1257 this.inherited(arguments);
1258 },
1259
1260 _layoutBgItems: function(/*Object*/renderData, /*Integer*/col, /*Date*/startTime, /*Date*/endTime, /*Object[]*/items){
1261 // tags:
1262 // private
1263
1264 var bgItems = {};
1265 for(var i = 0; i < items.length; i++){
1266
1267 var item = items[i];
1268 var overlap = this.computeRangeOverlap(renderData, item.startTime, item.endTime, startTime, endTime);
1269 var start = overlap[0].getDate()-1;
1270 // handle use case where end time is first day of next month.
1271 var end;
1272 if(this.isStartOfDay(overlap[1])){
1273 end = this._waDojoxAddIssue(overlap[1], "day", -1);
1274 end = end.getDate()-1;
1275 }else{
1276 end = overlap[1].getDate()-1;
1277 }
1278
1279 for (var d=start; d<=end; d++){
1280 bgItems[d] = true;
1281 }
1282 }
1283
1284 for(var row in bgItems) {
1285 if(bgItems[row]){
1286 var node = this._getCellAt(row, col, false);
1287 domClass.add(node, "dojoxCalendarHiddenEvents");
1288 }
1289 }
1290 },
1291
1292 _sortItemsFunction: function(a, b){
1293 // tags:
1294 // private
1295
1296 var res = this.dateModule.compare(a.startTime, b.startTime);
1297 if(res == 0){
1298 res = -1 * this.dateModule.compare(a.endTime, b.endTime);
1299 }
1300 return this.isLeftToRight() ? res : -res;
1301 },
1302
1303 ///////////////////////////////////////////////////////////////
1304 //
1305 // View to time projection
1306 //
1307 ///////////////////////////////////////////////////////////////
1308
1309 getTime: function(e, x, y, touchIndex){
1310 // summary:
1311 // Returns the time displayed at the specified point by this component.
1312 // e: Event
1313 // Optional mouse event.
1314 // x: Number
1315 // Position along the x-axis with respect to the sheet container used if event is not defined.
1316 // y: Number
1317 // Position along the y-axis with respect to the sheet container (scroll included) used if event is not defined.
1318 // touchIndex: Integer
1319 // If parameter 'e' is not null and a touch event, the index of the touch to use.
1320 // returns: Date
1321
1322 if (e != null){
1323 var refPos = domGeometry.position(this.itemContainer, true);
1324
1325 if(e.touches){
1326
1327 touchIndex = touchIndex==undefined ? 0 : touchIndex;
1328
1329 x = e.touches[touchIndex].pageX - refPos.x;
1330 y = e.touches[touchIndex].pageY - refPos.y;
1331
1332 }else{
1333
1334 x = e.pageX - refPos.x;
1335 y = e.pageY - refPos.y;
1336 }
1337 }
1338
1339 var r = domGeometry.getContentBox(this.itemContainer);
1340
1341 if(!this.isLeftToRight()){
1342 x = r.w - x;
1343 }
1344
1345 if (x < 0){
1346 x = 0;
1347 }else if(x > r.w){
1348 x = r.w-1;
1349 }
1350
1351 if (y < 0){
1352 y = 0;
1353 }else if(y > r.h){
1354 y = r.h-1;
1355 }
1356
1357 var col = Math.floor(x / (r.w / this.renderData.columnCount));
1358 var row = Math.floor(y / (r.h / this.renderData.maxDayCount));
1359
1360 var date = null;
1361 if(col < this.renderData.dates.length &&
1362 row < this.renderData.dates[col].length){
1363 date = this.newDate(this.renderData.dates[col][row]);
1364 }
1365
1366 return date;
1367 },
1368
1369 ///////////////////////////////////////////////////////////////
1370 //
1371 // Events
1372 //
1373 ///////////////////////////////////////////////////////////////
1374
1375 _onGridMouseUp: function(e){
1376
1377 // tags:
1378 // private
1379
1380
1381 this.inherited(arguments);
1382
1383 if (this._gridMouseDown) {
1384 this._gridMouseDown = false;
1385
1386 this._onGridClick({
1387 date: this.getTime(e),
1388 triggerEvent: e
1389 });
1390 }
1391 },
1392
1393 _onGridTouchStart: function(e){
1394 // tags:
1395 // private
1396
1397
1398 this.inherited(arguments);
1399
1400 var g = this._gridProps;
1401
1402 g.moved= false;
1403 g.start= e.touches[0].screenY;
1404 g.scrollTop= this.scrollContainer.scrollTop;
1405 },
1406
1407 _onGridTouchMove: function(e){
1408 // tags:
1409 // private
1410
1411 this.inherited(arguments);
1412
1413 if (e.touches.length > 1 && !this._isEditing){
1414 event.stop(e);
1415 return;
1416 }
1417
1418 if(this._gridProps && !this._isEditing){
1419
1420 var touch = {x: e.touches[0].screenX, y: e.touches[0].screenY};
1421
1422 var p = this._edProps;
1423
1424 if (!p || p &&
1425 (Math.abs(touch.x - p.start.x) > 25 ||
1426 Math.abs(touch.y - p.start.y) > 25)) {
1427
1428 this._gridProps.moved = true;
1429 var d = e.touches[0].screenY - this._gridProps.start;
1430 var value = this._gridProps.scrollTop - d;
1431 var max = this.itemContainer.offsetHeight - this.scrollContainer.offsetHeight;
1432 if (value < 0){
1433 this._gridProps.start = e.touches[0].screenY;
1434 this._setScrollImpl(0);
1435 this._gridProps.scrollTop = 0;
1436 }else if(value > max){
1437 this._gridProps.start = e.touches[0].screenY;
1438 this._setScrollImpl(max);
1439 this._gridProps.scrollTop = max;
1440 }else{
1441 this._setScrollImpl(value);
1442 }
1443 }
1444 }
1445 },
1446
1447 _onGridTouchEnd: function(e){
1448 // tags:
1449 // private
1450
1451 //event.stop(e);
1452
1453 this.inherited(arguments);
1454
1455 var g = this._gridProps;
1456
1457 if(g){
1458 if(!this._isEditing){
1459 if(!g.moved){
1460
1461 // touched on grid and on touch start editing was ongoing.
1462 if(!g.fromItem && !g.editingOnStart){
1463 this.selectFromEvent(e, null, null, true);
1464 }
1465
1466 if(!g.fromItem){
1467
1468 if(this._pendingDoubleTap && this._pendingDoubleTap.grid){
1469
1470 this._onGridDoubleClick({
1471 date: this.getTime(this._gridProps.event),
1472 triggerEvent: this._gridProps.event
1473 });
1474
1475 clearTimeout(this._pendingDoubleTap.timer);
1476
1477 delete this._pendingDoubleTap;
1478
1479 }else{
1480
1481 this._onGridClick({
1482 date: this.getTime(this._gridProps.event),
1483 triggerEvent: this._gridProps.event
1484 });
1485
1486 this._pendingDoubleTap = {
1487 grid: true,
1488 timer: setTimeout(lang.hitch(this, function(){
1489 delete this._pendingDoubleTap;
1490 }), this.doubleTapDelay)
1491 };
1492 }
1493 }
1494 }
1495 }
1496
1497 this._gridProps = null;
1498 }
1499 },
1500
1501 _onColumnHeaderClick: function(e){
1502 // tags:
1503 // private
1504
1505 this._dispatchCalendarEvt(e, "onColumnHeaderClick");
1506 },
1507
1508 onColumnHeaderClick: function(e){
1509 // summary:
1510 // Event dispatched when a column header cell is dispatched.
1511 // e: __ColumnClickEventArgs
1512 // tags:
1513 // callback
1514
1515 },
1516
1517
1518 ///////////////////////////////////////////////////////////////
1519 //
1520 // View limits
1521 //
1522 ///////////////////////////////////////////////////////////////
1523
1524 _onScrollTimer_tick: function(){
1525 // tags:
1526 // private
1527
1528 this._setScrollImpl(this.scrollContainer.scrollTop + this._scrollProps.scrollStep);
1529 },
1530
1531 ////////////////////////////////////////////
1532 //
1533 // Editing
1534 //
1535 ///////////////////////////////////////////
1536
1537 snapUnit: "day",
1538 snapSteps: 1,
1539 minDurationUnit: "day",
1540 minDurationSteps: 1,
1541 liveLayout: false,
1542 stayInView: true,
1543 allowStartEndSwap: true,
1544 allowResizeLessThan24H: false
1545
1546 });
1547 });