Debian Codegraph @

dojox/calendar/ViewBase.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare",
3 "dojo/_base/lang",
4 "dojo/_base/array",
5 "dojo/_base/window",
6 "dojo/_base/event",
7 "dojo/_base/html",
8 "dojo/sniff",
9 "dojo/query",
10 "dojo/dom",
11 "dojo/dom-style",
12 "dojo/dom-class",
13 "dojo/dom-construct",
14 "dojo/dom-geometry",
15 "dojo/on",
16 "dojo/date",
17 "dojo/date/locale",
18 "dojo/when",
19 "dijit/_WidgetBase",
20 "dojox/widget/_Invalidating",
21 "dojox/widget/Selection",
22 "./time",
23 "./StoreMixin",
24 "./StoreManager",
25 "./RendererManager"],
26
27 function(
28 declare,
29 lang,
30 arr,
31 win,
32 event,
33 html,
34 has,
35 query,
36 dom,
37 domStyle,
38 domClass,
39 domConstruct,
40 domGeometry,
41 on,
42 date,
43 locale,
44 when,
45 _WidgetBase,
46 _Invalidating,
47 Selection,
48 timeUtil,
49 StoreMixin,
50 StoreManager,
51 RendererManager){
52
53 /*=====
54 var __GridClickEventArgs = {
55 // summary:
56 // The event dispatched when the grid is clicked or double-clicked.
57 // date: Date
58 // The start of the previously displayed time interval, if any.
59 // triggerEvent: Event
60 // The event at the origin of this event.
61 };
62 =====*/
63
64 /*=====
65 var __ItemMouseEventArgs = {
66 // summary:
67 // The event dispatched when an item is clicked, double-clicked or context-clicked.
68 // item: Object
69 // The item clicked.
70 // renderer: dojox/calendar/_RendererMixin
71 // The item renderer clicked.
72 // triggerEvent: Event
73 // The event at the origin of this event.
74 };
75 =====*/
76
77 /*=====
78 var __itemEditingEventArgs = {
79 // summary:
80 // An item editing event.
81 // item: Object
82 // The render item that is being edited. Set/get the startTime and/or endTime properties to customize editing behavior.
83 // storeItem: Object
84 // The real data from the store. DO NOT change properties, but you may use properties of this item in the editing behavior logic.
85 // editKind: String
86 // Kind of edit: "resizeBoth", "resizeStart", "resizeEnd" or "move".
87 // dates: Date[]
88 // The computed date/time of the during the event editing. One entry per edited date (touch use case).
89 // startTime: Date?
90 // The start time of data item.
91 // endTime: Date?
92 // The end time of data item.
93 // sheet: String
94 // For views with several sheets (columns view for example), the sheet when the event occurred.
95 // source: dojox/calendar/ViewBase
96 // The view where the event occurred.
97 // eventSource: String
98 // The device that triggered the event. This property can take the following values:
99 //
100 // - "mouse",
101 // - "keyboard",
102 // - "touch"
103 // triggerEvent: Event
104 // The event at the origin of this event.
105 };
106 =====*/
107
108 /*=====
109 var __rendererLifecycleEventArgs = {
110 // summary:
111 // An renderer lifecycle event.
112 // renderer: Object
113 // The renderer.
114 // source: dojox/calendar/ViewBase
115 // The view where the event occurred.
116 // item:Object?
117 // The item that will be displayed by the renderer for the "rendererCreated" and "rendererReused" events.
118 };
119 =====*/
120
121 return declare("dojox.calendar.ViewBase", [_WidgetBase, StoreMixin, _Invalidating, Selection], {
122
123 // summary:
124 // The dojox.calendar.ViewBase widget is the base of calendar view widgets
125
126 // datePackage: Object
127 // JavaScript namespace to find Calendar routines. Uses Gregorian Calendar routines at dojo.date by default.
128 datePackage: date,
129
130 _calendar: "gregorian",
131
132 // viewKind: String
133 // Kind of the view. Used by the calendar widget to determine how to configure the view.
134 viewKind: null,
135
136 // _layoutStep: [protected] Integer
137 // The number of units displayed by a visual layout unit (i.e. a column or a row)
138 _layoutStep: 1,
139
140 // _layoutStep: [protected] Integer
141 // The unit displayed by a visual layout unit (i.e. a column or a row)
142 _layoutUnit: "day",
143
144 // resizeCursor: String
145 // CSS value to apply to the cursor while resizing an item renderer.
146 resizeCursor: "n-resize",
147
148 // formatItemTimeFunc: Function
149 // Optional function to format the time of day of the item renderers.
150 // The function takes the date, the render data object, the view and the data item as arguments and returns a String.
151 formatItemTimeFunc: null,
152
153 _cssDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
154
155 _getFormatItemTimeFuncAttr: function(){
156 if(this.formatItemTimeFunc){
157 return this.formatItemTimeFunc;
158 }
159 if(this.owner != null){
160 return this.owner.get("formatItemTimeFunc");
161 }
162 },
163
164 // The listeners added by the view itself.
165 _viewHandles: null,
166
167 // doubleTapDelay: Integer
168 // The maximum time amount in milliseconds between to touchstart events that trigger a double-tap event.
169 doubleTapDelay: 300,
170
171 constructor: function(/*Object*/ args){
172 args = args || {};
173
174 this._calendar = args.datePackage ? args.datePackage.substr(args.datePackage.lastIndexOf(".")+1) : this._calendar;
175 this.dateModule = args.datePackage ? lang.getObject(args.datePackage, false) : date;
176 this.dateClassObj = this.dateModule.Date || Date;
177 this.dateLocaleModule = args.datePackage ? lang.getObject(args.datePackage+".locale", false) : locale;
178
179 this._viewHandles = [];
180
181 this.storeManager = new StoreManager({owner: this, _ownerItemsProperty: "items"});
182 this.storeManager.on("layoutInvalidated", lang.hitch(this, this._refreshItemsRendering));
183 this.storeManager.on("dataLoaded", lang.hitch(this, function(items){
184 this.set("items", items);
185 }));
186 this.storeManager.on("renderersInvalidated", lang.hitch(this, function(item){
187 this.updateRenderers(item);
188 }));
189
190 this.rendererManager = new RendererManager({owner: this});
191 this.rendererManager.on("rendererCreated", lang.hitch(this, this._onRendererCreated));
192 this.rendererManager.on("rendererReused", lang.hitch(this, this._onRendererReused));
193 this.rendererManager.on("rendererRecycled", lang.hitch(this, this._onRendererRecycled));
194 this.rendererManager.on("rendererDestroyed", lang.hitch(this, this._onRendererDestroyed));
195
196 this.decorationStoreManager = new StoreManager({owner: this, _ownerItemsProperty: "decorationItems"});
197 this.decorationStoreManager.on("layoutInvalidated", lang.hitch(this, this._refreshDecorationItemsRendering));
198 this.decorationStoreManager.on("dataLoaded", lang.hitch(this, function(items){
199 this.set("decorationItems", items);
200 }));
201 this.decorationRendererManager = new RendererManager({owner: this});
202
203 this._setupDayRefresh();
204 },
205
206 destroy: function(preserveDom){
207
208 this.rendererManager.destroy();
209 this.decorationRendererManager.destroy();
210
211 while(this._viewHandles.length > 0){
212 this._viewHandles.pop().remove();
213 }
214
215 this.inherited(arguments);
216 },
217
218 _setupDayRefresh: function(){
219 // Refresh the view when the current day changes.
220 var now = this.newDate(new Date());
221 var d = timeUtil.floor(now, "day", 1, this.dateClassObj);
222 var d = this.dateModule.add(d, "day", 1);
223 // manages DST at 24h
224 if(d.getHours() == 23){
225 d = this.dateModule.add(d, "hour", 2); // go to 1am
226 }else{
227 d = timeUtil.floorToDay(d, true, this.dateClassObj);
228 }
229 setTimeout(lang.hitch(this, function(){
230 if(!this._isEditing){
231 this.refreshRendering(true); // recursive refresh
232 }
233 this._setupDayRefresh();
234 }), d.getTime()-now.getTime() + 5000);
235 // add 5 seconds to be sure to be tomorrow
236 },
237
238 resize: function(changeSize){
239 // summary:
240 // Function to call when the view is resized.
241 // If the view is in a Dijit container or in a Dojo mobile container, it will be automatically called.
242 // On other use cases, this method must called when the window is resized and/or when the orientation has changed.
243 if(changeSize){
244 domGeometry.setMarginBox(this.domNode, changeSize);
245 }
246 },
247
248 // view lifecycle methods
249 beforeActivate: function(){
250 // summary:
251 // Function invoked just before the view is displayed by the calendar.
252 // tags:
253 // protected
254 },
255
256 afterActivate: function(){
257 // summary:
258 // Function invoked just after the view is displayed by the calendar.
259 // tags:
260 // protected
261 },
262
263 beforeDeactivate: function(){
264 // summary:
265 // Function invoked just before the view is hidden or removed by the calendar.
266 // tags:
267 // protected
268 },
269
270 afterDeactivate: function(){
271 // summary:
272 // Function invoked just after the view is the view is hidden or removed by the calendar.
273 // tags:
274 // protected
275 },
276
277 _getTopOwner: function(){
278 // summary:
279 // Returns the top owner: the calendar or the parent view.
280 var p = this;
281 while(p.owner != undefined){
282 p = p.owner;
283 }
284 return p;
285 },
286
287 _createRenderData: function(){
288 // summary:
289 // Creates the object that contains all the data needed to render this widget.
290 // tags:
291 // protected
292 },
293
294 _validateProperties: function(){
295 // summary:
296 // Validates the widget properties before the rendering pass.
297 // tags:
298 // protected
299 },
300
301 _setText: function(node, text, allowHTML){
302 // summary:
303 // Creates a text node under the parent node after having removed children nodes if any.
304 // node: Node
305 // The node that will contain the text node.
306 // text: String
307 // The text to set to the text node.
308 if(text != null){
309 if(!allowHTML && node.hasChildNodes()){
310 // span > textNode
311 node.childNodes[0].childNodes[0].nodeValue = text;
312 }else{
313
314 while(node.hasChildNodes()){
315 node.removeChild(node.lastChild);
316 }
317
318 var tNode = win.doc.createElement("span");
319 if(has("dojo-bidi")){
320 this.applyTextDir(tNode, text);
321 }
322
323 if(allowHTML){
324 tNode.innerHTML = text;
325 }else{
326 tNode.appendChild(win.doc.createTextNode(text));
327 }
328 node.appendChild(tNode);
329 }
330 }
331 },
332
333 isAscendantHasClass: function(node, ancestor, className){
334 // summary:
335 // Determines if a node has an ascendant node that has the css class specified.
336 // node: Node
337 // The DOM node.
338 // ancestor: Node
339 // The ancestor node used to limit the search in hierarchy.
340 // className: String
341 // The css class name.
342 // returns: Boolean
343
344 while(node != ancestor && node != document){
345
346 if(domClass.contains(node, className)){
347 return true;
348 }
349
350 node = node.parentNode;
351 }
352 return false;
353 },
354
355 isWeekEnd: function(date){
356 // summary:
357 // Determines whether the specified date is a week-end.
358 // This method is using dojo.date.locale.isWeekend() method as
359 // dojox.date.XXXX calendars are not supporting this method.
360 // date: Date
361 // The date to test.
362 return locale.isWeekend(date);
363 },
364
365 getWeekNumberLabel: function(date){
366 // summary:
367 // Returns the week number string from dojo.date.locale.format() method as
368 // dojox.date.XXXX calendar are not supporting the "w" pattern.
369 // date: Date
370 // The date to format.
371 if(date.toGregorian){
372 date = date.toGregorian();
373 }
374 return locale.format(date, {
375 selector: "date",
376 datePattern: "w"});
377 },
378
379 addAndFloor: function(date, unit, steps){
380 // date must be floored!!
381 // unit >= day
382 var d = this.dateModule.add(date, unit, steps);
383 if(d.getHours() == 23){
384 d = this.dateModule.add(d, "hour", 2); // go to 1am
385 }else{
386 d = timeUtil.floorToDay(d, true, this.dateClassObj);
387 }
388 return d;
389 },
390
391 floorToDay: function(date, reuse){
392 // summary:
393 // Floors the specified date to the start of day.
394 // date: Date
395 // The date to floor.
396 // reuse: Boolean
397 // Whether use the specified instance or create a new one. Default is false.
398 // returns: Date
399 return timeUtil.floorToDay(date, reuse, this.dateClassObj);
400 },
401
402 floorToMonth: function(date, reuse){
403 // summary:
404 // Floors the specified date to the start of the date's month.
405 // date: Date
406 // The date to floor.
407 // reuse: Boolean
408 // Whether use the specified instance or create a new one. Default is false.
409 // returns: Date
410 return timeUtil.floorToMonth(date, reuse, this.dateClassObj);
411 },
412
413
414 floorDate: function(date, unit, steps, reuse){
415 // summary:
416 // floors the date to the unit.
417 // date: Date
418 // The date/time to floor.
419 // unit: String
420 // The unit. Valid values are "minute", "hour", "day".
421 // steps: Integer
422 // For "day" only 1 is valid.
423 // reuse: Boolean
424 // Whether use the specified instance or create a new one. Default is false.
425 // returns: Date
426 return timeUtil.floor(date, unit, steps, reuse, this.dateClassObj);
427 },
428
429 isToday: function(date){
430 // summary:
431 // Returns whether the specified date is in the current day.
432 // date: Date
433 // The date to test.
434 // renderData: Object
435 // The current renderData
436 // returns: Boolean
437 return timeUtil.isToday(date, this.dateClassObj);
438 },
439
440 isStartOfDay: function(d){
441 // summary:
442 // Tests if the specified date represents the starts of day.
443 // d:Date
444 // The date to test.
445 // returns: Boolean
446 return timeUtil.isStartOfDay(d, this.dateClassObj, this.dateModule);
447 },
448
449 isOverlapping: function(renderData, start1, end1, start2, end2, includeLimits){
450 // summary:
451 // Computes if the first time range defined by the start1 and end1 parameters
452 // is overlapping the second time range defined by the start2 and end2 parameters.
453 // renderData: Object
454 // The render data.
455 // start1: Date
456 // The start time of the first time range.
457 // end1: Date
458 // The end time of the first time range.
459 // start2: Date
460 // The start time of the second time range.
461 // end2: Date
462 // The end time of the second time range.
463 // includeLimits: Boolean
464 // Whether include the end time or not.
465 // returns: Boolean
466 return timeUtil.isOverlapping(renderData, start1, end1, start2, end2, includeLimits);
467 },
468
469 computeRangeOverlap: function(renderData, start1, end1, start2, end2, includeLimits){
470 // summary:
471 // Computes the overlap time range of the time ranges.
472 // Returns a vector of Date with at index 0 the start time and at index 1 the end time.
473 // renderData: Object.
474 // The render data.
475 // start1: Date
476 // The start time of the first time range.
477 // end1: Date
478 // The end time of the first time range.
479 // start2: Date
480 // The start time of the second time range.
481 // end2: Date
482 // The end time of the second time range.
483 // includeLimits: Boolean
484 // Whether include the end time or not.
485 // returns: Date[]
486 var cal = renderData.dateModule;
487
488 if(start1 == null || start2 == null || end1 == null || end2 == null){
489 return null;
490 }
491
492 var comp1 = cal.compare(start1, end2);
493 var comp2 = cal.compare(start2, end1);
494
495 if(includeLimits){
496
497 if(comp1 == 0 || comp1 == 1 || comp2 == 0 || comp2 == 1){
498 return null;
499 }
500 } else if(comp1 == 1 || comp2 == 1){
501 return null;
502 }
503
504 return [
505 this.newDate(cal.compare(start1, start2)>0 ? start1: start2, renderData),
506 this.newDate(cal.compare(end1, end2)>0 ? end2: end1, renderData)
507 ];
508 },
509
510 isSameDay : function(date1, date2){
511 // summary:
512 // Tests if the specified dates are in the same day.
513 // date1: Date
514 // The first date.
515 // date2: Date
516 // The second date.
517 // returns: Boolean
518 if(date1 == null || date2 == null){
519 return false;
520 }
521
522 return date1.getFullYear() == date2.getFullYear() &&
523 date1.getMonth() == date2.getMonth() &&
524 date1.getDate() == date2.getDate();
525
526 },
527
528 computeProjectionOnDate: function(renderData, refDate, date, max){
529 // summary:
530 // Computes the time to pixel projection in a day.
531 // renderData: Object
532 // The render data.
533 // refDate: Date
534 // The reference date that defines the destination date.
535 // date: Date
536 // The date to project.
537 // max: Integer
538 // The size in pixels of the representation of a day.
539 // tags:
540 // protected
541 // returns: Number
542
543
544 var cal = renderData.dateModule;
545 var minH = renderData.minHours;
546 var maxH = renderData.maxHours;
547
548 if(max <= 0 || cal.compare(date, refDate) == -1){
549 return 0;
550 }
551
552 var gt = function(d){
553 return d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds();
554 };
555
556 var referenceDate = this.floorToDay(refDate, false, renderData);
557
558 if(date.getDate() != referenceDate.getDate()){
559 if(date.getMonth() == referenceDate.getMonth()){
560 if(date.getDate() < referenceDate.getDate()){
561 return 0;
562 } else if(date.getDate() > referenceDate.getDate() && maxH < 24){
563 return max;
564 }
565 }else{
566 if(date.getFullYear() == referenceDate.getFullYear()){
567 if(date.getMonth() < referenceDate.getMonth()){
568 return 0;
569 } else if(date.getMonth() > referenceDate.getMonth()){
570 return max;
571 }
572 }else{
573 if(date.getFullYear() < referenceDate.getFullYear()){
574 return 0;
575 } else if(date.getFullYear() > referenceDate.getFullYear()){
576 return max;
577 }
578 }
579 }
580 }
581
582 var res;
583 var ONE_DAY = 86400; // 24h x 60m x 60s
584
585 if(this.isSameDay(refDate, date) || maxH > 24){
586
587 var d = lang.clone(refDate);
588 var minTime = 0;
589
590 if(minH != null && minH != 0){
591 d.setHours(minH);
592 minTime = gt(d);
593 }
594
595 d = lang.clone(refDate);
596 d.setHours(maxH);
597
598 var maxTime;
599 if(maxH == null || maxH == 24){
600 maxTime = ONE_DAY;
601 }else if(maxH > 24){
602 maxTime = ONE_DAY + gt(d);
603 }else{
604 maxTime = gt(d);
605 }
606
607 //precision is the second
608 //use this API for daylight time issues.
609
610 var delta = 0;
611
612 if(maxH > 24 && refDate.getDate() != date.getDate()){
613 delta = ONE_DAY + gt(date);
614 }else{
615 delta = gt(date);
616 }
617
618 if(delta < minTime){
619 return 0;
620 }
621 if(delta > maxTime){
622 return max;
623 }
624
625 delta -= minTime;
626
627 res = (max * delta)/(maxTime - minTime);
628
629 }else{
630
631 if(date.getDate() < refDate.getDate() &&
632 date.getMonth() == refDate.getMonth()){
633 return 0;
634 }
635
636 var d2 = this.floorToDay(date);
637 var dp1 = renderData.dateModule.add(refDate, "day", 1);
638 dp1 = this.floorToDay(dp1, false, renderData);
639
640 if(cal.compare(d2, refDate) == 1 && cal.compare(d2, dp1) == 0 || cal.compare(d2, dp1) == 1){
641 res = max;
642 }else{
643 res = 0;
644 }
645 }
646
647 return res;
648 },
649
650 getTime: function(e, x, y, touchIndex){
651 // summary:
652 // Returns the time displayed at the specified point by this component.
653 // e: Event
654 // Optional mouse event.
655 // x: Number
656 // Position along the x-axis with respect to the sheet container used if event is not defined.
657 // y: Number
658 // Position along the y-axis with respect to the sheet container (scroll included) used if event is not defined.
659 // touchIndex: Integer
660 // If parameter 'e' is not null and a touch event, the index of the touch to use.
661 // returns: Date
662 return null;
663 },
664
665 getSubColumn: function(e, x, y, touchIndex){
666 // summary:
667 // Returns the sub column at the specified point by this component.
668 // e: Event
669 // Optional mouse event.
670 // x: Number
671 // Position along the x-axis with respect to the sheet container used if event is not defined.
672 // y: Number
673 // Position along the y-axis with respect to the sheet container (scroll included) used if event is not defined.
674 // touchIndex: Integer
675 // If parameter 'e' is not null and a touch event, the index of the touch to use.
676 // returns: Object
677
678 return null;
679 },
680
681 getSubColumnIndex: function(value){
682 // summary:
683 // Returns the sub column index that has the specified value, if any. -1 otherwise.
684 // value: String
685 // The sub column index.
686 if(this.subColumns){
687 for(var i=0; i<this.subColumns.length; i++){
688 if(this.subColumns[i] == value){
689 return i;
690 }
691 }
692 }
693 return -1;
694 },
695
696 newDate: function(obj){
697 // summary:
698 // Creates a new Date object.
699 // obj: Object
700 // This object can have several values:
701 //
702 // - the time in milliseconds since gregorian epoch.
703 // - a Date instance
704 // returns: Date
705 return timeUtil.newDate(obj, this.dateClassObj);
706 },
707
708 _isItemInView: function(item){
709 // summary:
710 // Computes whether the specified item is entirely in the view or not.
711 // item: Object
712 // The item to test
713 // returns: Boolean
714 var rd = this.renderData;
715 var cal = rd.dateModule;
716
717 if(cal.compare(item.startTime, rd.startTime) == -1){
718 return false;
719 }
720
721 return cal.compare(item.endTime, rd.endTime) != 1;
722 },
723
724 _ensureItemInView: function(item){
725 // summary:
726 // If needed, moves the item to be entirely in view.
727 // item: Object
728 // The item to test
729 // returns: Boolean
730 // Whether the item has been moved to be in view or not.
731 // tags:
732 // protected
733
734 var rd = this.renderData;
735 var cal = rd.dateModule;
736
737 var duration = Math.abs(cal.difference(item.startTime, item.endTime, "millisecond"));
738 var fixed = false;
739
740 if(cal.compare(item.startTime, rd.startTime) == -1){
741 item.startTime = rd.startTime;
742 item.endTime = cal.add(item.startTime, "millisecond", duration);
743 fixed = true;
744 }else if(cal.compare(item.endTime, rd.endTime) == 1){
745 item.endTime = rd.endTime;
746 item.startTime = cal.add(item.endTime, "millisecond", -duration);
747 fixed = true;
748 }
749 return fixed;
750 },
751
752 /////////////////////////////////////////////////////////
753 //
754 // Scrollable
755 //
756 /////////////////////////////////////////////////////////
757
758 // scrollable: Boolean
759 // Indicates whether the view can be scrolled or not.
760 scrollable: true,
761
762 // autoScroll: Boolean
763 // Indicates whether the view can be scrolled automatically.
764 // Auto scrolling is used when moving focus to a non visible renderer using keyboard
765 // and while editing an item.
766 autoScroll: true,
767
768 _autoScroll: function(gx, gy, orientation){
769 // summary:
770 // Starts or stops the auto scroll according to the mouse cursor position during an item editing.
771 // gx: Integer
772 // The position of the mouse cursor along the x-axis.
773 // gy: Integer
774 // The position of the mouse cursor along the y-axis.
775 // tags:
776 // extension
777
778 return false;
779 },
780
781 // scrollMethod: String
782 // Method used to scroll the view, for example the scroll of column view.
783 // Valid value are:
784 //
785 // - "auto": let the view decide (default),
786 // - "css": use css 3d transform,
787 // - "dom": use the scrollTop property.
788 scrollMethod: "auto",
789
790 _setScrollMethodAttr: function(value){
791 if(this.scrollMethod != value){
792 this.scrollMethod = value;
793
794 // reset
795 if(this._domScroll !== undefined){
796 if(this._domScroll){
797 domStyle.set(this.sheetContainer, this._cssPrefix+"transform", "translateY(0px)");
798 }else{
799 this.scrollContainer.scrollTop = 0;
800 }
801 }
802
803 delete this._domScroll;
804 var pos = this._getScrollPosition();
805 delete this._scrollPos;
806
807 this._setScrollPosition(pos);
808 }
809
810 },
811
812 _startAutoScroll: function(step){
813 // summary:
814 // Starts the auto scroll of the view (if it's scrollable). Used only during editing.
815 // tags:
816 // protected
817 var sp = this._scrollProps;
818 if(!sp){
819 sp = this._scrollProps = {};
820 }
821
822 sp.scrollStep = step;
823
824 if (!sp.isScrolling){
825 sp.isScrolling = true;
826 sp.scrollTimer = setInterval(lang.hitch(this, this._onScrollTimer_tick), 10);
827 }
828 },
829
830 _stopAutoScroll: function(){
831 // summary:
832 // Stops the auto scroll of the view (if it's scrollable). Used only during editing.
833 // tags:
834 // protected
835 var sp = this._scrollProps;
836
837 if (sp && sp.isScrolling) {
838 clearInterval(sp.scrollTimer);
839 sp.scrollTimer = null;
840 }
841 this._scrollProps = null;
842 },
843
844 _onScrollTimer_tick: function(pos){
845 },
846
847 _scrollPos: 0,
848 _hscrollPos: 0,
849
850 getCSSPrefix: function(){
851 // summary:
852 // Utility method that return the specific CSS prefix
853 // for non standard CSS properties. Ex: -moz-border-radius.
854 if(has("ie")){
855 return "-ms-";
856 }
857 if(has("webkit")){
858 return "-webkit-";
859 }
860 if(has("mozilla")){
861 return "-moz-";
862 }
863 if(has("opera")){
864 return "-o-";
865 }
866 return "";
867 },
868
869 // _hScrollNodes: DOMNodes[]
870 // Array of nodes that will be scrolled horizontally.
871 // Must be set by sub class on buildRendering.
872
873 _hScrollNodes: null,
874
875 _setScrollPositionBase: function(pos, vertical){
876 // summary:
877 // Sets the scroll position (if the view is scrollable), using the scroll method defined.
878 // tags:
879 // protected
880
881 if(vertical && this._scrollPos == pos ||
882 !vertical && this._hScrollPos == pos){
883 return;
884 }
885
886 // determine scroll method once.
887 if(this._domScroll === undefined){
888
889 var sm = this.get("scrollMethod");
890 if(sm === "auto"){
891 this._domScroll = !has("ios") && !has("android") && !has("webkit");
892 }else{
893 this._domScroll = sm === "dom";
894 }
895 }
896
897 var max = 0;
898 if(vertical){
899 var containerSize = domGeometry.getMarginBox(this.scrollContainer);
900 var sheetSize = domGeometry.getMarginBox(this.sheetContainer);
901 max = sheetSize.h - containerSize.h;
902 }else{
903 var gridSize = domGeometry.getMarginBox(this.grid);
904 var gridTableSize = domGeometry.getMarginBox(this.gridTable);
905 max = gridTableSize.w - gridSize.w;
906 }
907
908 if(pos < 0){
909 pos = 0;
910 }else if(pos > max){
911 pos = max;
912 }
913
914 if(vertical){
915 this._scrollPos = pos;
916 }else{
917 this._hScrollPos = pos;
918 }
919
920 var rtl = !this.isLeftToRight();
921
922 if(this._domScroll){
923 if(vertical){
924 this.scrollContainer.scrollTop = pos;
925 }else{
926 arr.forEach(this._hScrollNodes, function(elt){
927 domStyle.set(elt, "left", ((rtl?1:-1) * pos) + "px");
928 }, this);
929 }
930
931 }else{
932 if(!this._cssPrefix){
933 this._cssPrefix = this.getCSSPrefix();
934 }
935
936 var cssProp = this._cssPrefix+"transform";
937
938 if(vertical){
939 domStyle.set(this.sheetContainer, cssProp, "translateY(-"+pos+"px)");
940 }else{
941 var css = "translateX("+(rtl?"":"-")+pos+"px)";
942 arr.forEach(this._hScrollNodes, function(elt){
943 domStyle.set(elt, cssProp, css);
944 }, this);
945 }
946 }
947 },
948
949 _setScrollPosition: function(pos){
950 // summary:
951 // Sets the verical scroll position (if the view is scrollable), using the scroll method defined.
952 // tags:
953 // protected
954 this._setScrollPositionBase(pos, true);
955 },
956
957 _getScrollPosition: function(){
958 // summary:
959 // Returns the vertical scroll position (if the view is scrollable), using the scroll method defined.
960 // tags:
961 // protected
962
963 return this._scrollPos;
964 },
965
966 _setHScrollPosition: function(pos){
967 // summary:
968 // Sets the horizontal scroll position (if the view is scrollable), using the scroll method defined.
969 // tags:
970 // protected
971
972 this._setScrollPositionBase(pos, false);
973 },
974
975 _setHScrollPositionImpl: function(pos, useDom, cssProperty){
976 // summary:
977 // Sets the horizontal scroll position on sub elements (if the view is scrollable), using the scroll method defined.
978 // Important: must be implemented by sub classes and not called directly. Use _setHScrollPosition() method instead.
979 // tags:
980 // private
981
982 var css = useDom ? null : "translateX(-"+pos+"px)";
983 arr.forEach(this._hScrollNodes, function(elt){
984 if(useDom){
985 elt.scrollLeft = pos;
986 domStyle.set(elt, "left", (-pos) + "px");
987 }else{
988 domStyle.set(elt, cssProp, css);
989 }
990 }, this);
991 },
992
993 _hScrollPos: 0,
994
995 _getHScrollPosition: function(){
996 // summary:
997 // Returns the horizontal scroll position (if the view is scrollable), using the scroll method defined.
998 // tags:
999 // protected
1000
1001 return this._hScrollPos;
1002 },
1003
1004 scrollView: function(dir){
1005 // summary:
1006 // If the view is scrollable, scrolls it vertically to the specified direction.
1007 // dir: Integer
1008 // Direction of the scroll. Valid values are -1 and 1.
1009 // tags:
1010 // extension
1011 },
1012
1013 ensureVisibility: function(start, end, margin, visibilityTarget, duration){
1014 // summary:
1015 // Scrolls the view if the [start, end] time range is not visible or only partially visible.
1016 // start: Date
1017 // Start time of the range of interest.
1018 // end: Date
1019 // End time of the range of interest.
1020 // margin: int
1021 // Margin in minutes around the time range.
1022 // visibilityTarget: String
1023 // The end(s) of the time range to make visible.
1024 // Valid values are: "start", "end", "both".
1025 // duration: Number
1026 // Optional, the maximum duration of the scroll animation.
1027 // tags:
1028 // extension
1029
1030 },
1031
1032 ////////////////////////////////////////////////////////
1033 //
1034 // Store & Items
1035 //
1036 ////////////////////////////////////////////////////////
1037
1038 _getStoreAttr: function(){
1039 if(this.owner){
1040 return this.owner.get("store");
1041 }
1042 return this.store;
1043 },
1044
1045 _setItemsAttr: function(value){
1046 this._set("items", value);
1047 this.displayedItemsInvalidated = true;
1048 },
1049
1050 _refreshItemsRendering: function(){
1051 var rd = this.renderData;
1052 this._computeVisibleItems(rd);
1053 this._layoutRenderers(rd);
1054 },
1055
1056 _refreshDecorationItemsRendering: function(){
1057 var rd = this.renderData;
1058 this._computeVisibleItems(rd);
1059 this._layoutDecorationRenderers(rd);
1060 },
1061
1062 invalidateLayout: function(){
1063 // summary:
1064 // Triggers a re-layout of the renderers.
1065 this._layoutRenderers(this.renderData);
1066 this._layoutDecorationRenderers(this.renderData);
1067 },
1068
1069 _setDecorationItemsAttr: function(value){
1070 this._set("decorationItems", value);
1071 this.displayedDecorationItemsInvalidated = true;
1072 },
1073
1074 _getDecorationStoreAttr: function(){
1075 if(this.owner){
1076 return this.owner.get("decorationStore");
1077 }
1078 return this.decorationStore;
1079 },
1080
1081 _setDecorationStoreAttr: function(value){
1082 this.decorationStore = value;
1083 this.decorationStoreManager.set("store", value);
1084 },
1085
1086 ////////////////////////////////////////////////////////
1087 //
1088 // Layout
1089 //
1090 ////////////////////////////////////////////////////////
1091
1092 computeOverlapping: function(layoutItems, func){
1093 // summary:
1094 // Computes the overlap layout of a list of items. A lane and extent properties are added to each layout item.
1095 // layoutItems: Object[]
1096 // List of layout items, each item must have a start and end properties.
1097 // addedPass: Function
1098 // Whether computes the extent of each item renderer on free sibling lanes.
1099 // returns: Object
1100 // tags:
1101 // protected
1102
1103
1104 if(layoutItems.length == 0){
1105 return {
1106 numLanes: 0,
1107 addedPassRes: [1]
1108 };
1109 }
1110
1111 var lanes = [];
1112
1113 for(var i=0; i<layoutItems.length; i++){
1114 var layoutItem = layoutItems[i];
1115 this._layoutPass1(layoutItem, lanes);
1116 }
1117
1118 var addedPassRes = null;
1119 if(func){
1120 addedPassRes = lang.hitch(this, func)(lanes);
1121 }
1122
1123 return {
1124 numLanes: lanes.length,
1125 addedPassRes: addedPassRes
1126 };
1127 },
1128
1129 _layoutPass1: function (layoutItem, lanes){
1130 // summary:
1131 // First pass of the overlap layout. Find a lane where the item can be placed or create a new one.
1132 // layoutItem: Object
1133 // An object that contains a start and end properties at least.
1134 // lanes:
1135 // The array of lanes.
1136 // tags:
1137 // protected
1138 var stop = true;
1139
1140 for(var i=0; i<lanes.length; i++){
1141 var lane = lanes[i];
1142 stop = false;
1143 for(var j=0; j<lane.length && !stop; j++){
1144 if(lane[j].start < layoutItem.end && layoutItem.start < lane[j].end){
1145 // one already placed item is overlapping
1146 stop = true;
1147 lane[j].extent = 1;
1148 }
1149 }
1150 if(!stop){
1151 //we have found a place
1152 layoutItem.lane = i;
1153 layoutItem.extent = -1;
1154 lane.push(layoutItem);
1155 return;
1156 }
1157 }
1158
1159 //no place found -> add a lane
1160 lanes.push([layoutItem]);
1161 layoutItem.lane = lanes.length-1;
1162 layoutItem.extent = -1;
1163 },
1164
1165
1166
1167 _layoutInterval: function(renderData, index, start, end, items){
1168 // summary:
1169 // For each item in the items list: retrieve a renderer, compute its location and size and add it to the DOM.
1170 // renderData: Object
1171 // The render data.
1172 // index: Integer
1173 // The index of the interval.
1174 // start: Date
1175 // The start time of the displayed date interval.
1176 // end: Date
1177 // The end time of the displayed date interval.
1178 // items: Object[]
1179 // The list of the items to represent.
1180 // tags:
1181 // extension
1182 },
1183
1184 // layoutPriorityFunction: Function
1185 // An optional comparison function use to determine the order the item will be laid out
1186 // The function is used to sort an array and must, as any sorting function, take two items
1187 // as argument and must return an integer whose sign define order between arguments.
1188 // By default, a comparison by start time then end time is used.
1189 layoutPriorityFunction: null,
1190
1191 _sortItemsFunction: function(a, b){
1192 var res = this.dateModule.compare(a.startTime, b.startTime);
1193 if(res == 0){
1194 res = -1 * this.dateModule.compare(a.endTime, b.endTime);
1195 }
1196 return res;
1197 },
1198
1199
1200 _layoutRenderers: function(renderData){
1201 this._layoutRenderersImpl(renderData, this.rendererManager, renderData.items, "dataItems");
1202 },
1203
1204 _layoutDecorationRenderers: function(renderData){
1205 this._layoutRenderersImpl(renderData, this.decorationRendererManager, renderData.decorationItems, "decorationItems");
1206 },
1207
1208 _layoutRenderersImpl: function(renderData, rendererManager, items, itemType){
1209 // summary:
1210 // Renders the data items. This method will call the _layoutInterval() method.
1211 // renderData: Object
1212 // The render data.
1213 // tags:
1214 // protected
1215 if(!items){
1216 return;
1217 }
1218
1219 // recycle renderers first
1220 rendererManager.recycleItemRenderers();
1221
1222 var cal = renderData.dateModule;
1223
1224 // Date
1225 var startDate = this.newDate(renderData.startTime);
1226
1227 // Date and time
1228 var startTime = lang.clone(startDate);
1229
1230 var endDate;
1231
1232 var items = items.concat();
1233
1234 var itemsTemp = [], events;
1235 var processing = {};
1236
1237 var index = 0;
1238
1239 while(cal.compare(startDate, renderData.endTime) == -1 && items.length > 0){
1240
1241 endDate = this.addAndFloor(startDate, this._layoutUnit, this._layoutStep);
1242
1243 var endTime = lang.clone(endDate);
1244
1245 if(renderData.minHours){
1246 startTime.setHours(renderData.minHours);
1247 }
1248
1249 if(renderData.maxHours != undefined && renderData.maxHours != 24){
1250 if(renderData.maxHours < 24){
1251 endTime = cal.add(endDate, "day", -1);
1252 } // else > 24
1253 endTime = this.floorToDay(endTime, true, renderData);
1254 endTime.setHours(renderData.maxHours - (renderData.maxHours < 24 ? 0 : 24));
1255 }
1256
1257 // look for events that overlap the current sub interval
1258 events = arr.filter(items, function(item){
1259 var r = this.isOverlapping(renderData, item.startTime, item.endTime, startTime, endTime);
1260 if(r){
1261 processing[item.id] = true;
1262 itemsTemp.push(item);
1263 }else{
1264 if(processing[item.id]){
1265 delete processing[item.id];
1266 }else{
1267 itemsTemp.push(item);
1268 }
1269 }
1270 return r;
1271 }, this);
1272
1273 items = itemsTemp;
1274 itemsTemp = [];
1275
1276 // if event are in the current sub interval, layout them
1277 if(events.length > 0){
1278 // Sort the item according a sorting function, by default start time then end time comparison are used.
1279 events.sort(lang.hitch(this, this.layoutPriorityFunction ? this.layoutPriorityFunction : this._sortItemsFunction));
1280 this._layoutInterval(renderData, index, startTime, endTime, events, itemType);
1281 }
1282
1283 startDate = endDate;
1284 startTime = lang.clone(startDate);
1285
1286 index++;
1287 }
1288
1289 this._onRenderersLayoutDone(this);
1290 },
1291
1292 /////////////////////////////////////////////////////////////////
1293 //
1294 // Renderers management
1295 //
1296 ////////////////////////////////////////////////////////////////
1297
1298 _recycleItemRenderers: function(remove){
1299 this.rendererManager.recycleItemRenderers(remove);
1300 },
1301
1302 getRenderers: function(item){
1303 // summary:
1304 // Returns the renderers that are currently used to displayed the speficied item.
1305 // Returns an array of objects that contains two properties:
1306 // - container: The DOM node that contains the renderer.
1307 // - renderer: The dojox.calendar._RendererMixin instance.
1308 // Do not keep references on the renderers are they are recycled and reused for other items.
1309 // item: Object
1310 // The data or render item.
1311 // returns: Object[]
1312
1313 return this.rendererManager.getRenderers(item);
1314 },
1315
1316 // itemToRendererKindFunc: Function
1317 // An optional function to associate a kind of renderer ("horizontal", "label" or null) with the specified item.
1318 // By default, if an item is lasting more that 24 hours an horizontal item is used, otherwise a label is used.
1319 itemToRendererKindFunc: null,
1320
1321 _itemToRendererKind: function(item){
1322 // summary:
1323 // Associates a kind of renderer with a data item.
1324 // item: Object
1325 // The data item.
1326 // returns: String
1327 // tags:
1328 // protected
1329 if(this.itemToRendererKindFunc){
1330 return this.itemToRendererKindFunc(item);
1331 }
1332 return this._defaultItemToRendererKindFunc(item); // String
1333 },
1334
1335 _defaultItemToRendererKindFunc:function(item){
1336 // tags:
1337 // private
1338 return null;
1339 },
1340
1341 _createRenderer: function(item, kind, rendererClass, cssClass){
1342 // summary:
1343 // Creates an item renderer of the specified kind. A renderer is an object with the "container" and "instance" properties.
1344 // item: Object
1345 // The data item.
1346 // kind: String
1347 // The kind of renderer.
1348 // rendererClass: Object
1349 // The class to instantiate to create the renderer.
1350 // returns: Object
1351 // tags:
1352 // protected
1353
1354 return this.rendererManager.createRenderer(item, kind, rendererClass, cssClass);
1355 },
1356
1357 _onRendererCreated: function(e){
1358 if(e.source == this){
1359 this.onRendererCreated(e);
1360 }
1361 if(this.owner != null){
1362 this.owner._onRendererCreated(e);
1363 }
1364 },
1365
1366 onRendererCreated: function(e){
1367 // summary:
1368 // Event dispatched when an item renderer has been created.
1369 // e: __rendererLifecycleEventArgs
1370 // The renderer lifecycle event.
1371 // tags:
1372 // callback
1373 },
1374
1375 _onRendererRecycled: function(e){
1376 if(e.source == this){
1377 this.onRendererRecycled(e);
1378 }
1379 if(this.owner != null){
1380 this.owner._onRendererRecycled(e);
1381 }
1382 },
1383
1384 onRendererRecycled: function(e){
1385 // summary:
1386 // Event dispatched when an item renderer has been recycled.
1387 // e: __rendererLifecycleEventArgs
1388 // The renderer lifecycle event.
1389 // tags:
1390 // callback
1391
1392 },
1393
1394 _onRendererReused: function(e){
1395 if(e.source == this){
1396 this.onRendererReused(e);
1397 }
1398 if(this.owner != null){
1399 this.owner._onRendererReused(e);
1400 }
1401 },
1402
1403 onRendererReused: function(e){
1404 // summary:
1405 // Event dispatched when an item renderer that was recycled is reused.
1406 // e: __rendererLifecycleEventArgs
1407 // The renderer lifecycle event.
1408 // tags:
1409 // callback
1410 },
1411
1412 _onRendererDestroyed: function(e){
1413 if(e.source == this){
1414 this.onRendererDestroyed(e);
1415 }
1416 if(this.owner != null){
1417 this.owner._onRendererDestroyed(e);
1418 }
1419 },
1420
1421 onRendererDestroyed: function(e){
1422 // summary:
1423 // Event dispatched when an item renderer is destroyed.
1424 // e: __rendererLifecycleEventArgs
1425 // The renderer lifecycle event.
1426 // tags:
1427 // callback
1428 },
1429
1430 _onRenderersLayoutDone: function(view){
1431 // tags:
1432 // private
1433
1434 this.onRenderersLayoutDone(view);
1435 if(this.owner != null){
1436 this.owner._onRenderersLayoutDone(view);
1437 }
1438 },
1439
1440 onRenderersLayoutDone: function(view){
1441 // summary:
1442 // Event triggered when item renderers layout has been done.
1443 // tags:
1444 // callback
1445 },
1446
1447 _recycleRenderer: function(renderer, remove){
1448 // summary:
1449 // Recycles the item renderer to be reused in the future.
1450 // renderer: dojox/calendar/_RendererMixin
1451 // The item renderer to recycle.
1452 // tags:
1453 // protected
1454
1455 this.rendererManager.recycleRenderer(renderer, remove);
1456 },
1457
1458 _destroyRenderer: function(renderer){
1459 // summary:
1460 // Destroys the item renderer.
1461 // renderer: dojox/calendar/_RendererMixin
1462 // The item renderer to destroy.
1463 // tags:
1464 // protected
1465
1466 this.rendererManager.destroyRenderer(renderer);
1467 },
1468
1469 _destroyRenderersByKind: function(kind){
1470 // tags:
1471 // private
1472
1473 this.rendererManager.destroyRenderersByKind(kind);
1474 },
1475
1476
1477 _updateEditingCapabilities: function(item, renderer){
1478 // summary:
1479 // Update the moveEnabled and resizeEnabled properties of a renderer according to its event current editing state.
1480 // item: Object
1481 // The store data item.
1482 // renderer: dojox/calendar/_RendererMixin
1483 // The item renderer.
1484 // tags:
1485 // protected
1486
1487 var moveEnabled = this.isItemMoveEnabled(item, renderer.rendererKind);
1488 var resizeEnabled = this.isItemResizeEnabled(item, renderer.rendererKind);
1489 var changed = false;
1490
1491 if(moveEnabled != renderer.get("moveEnabled")){
1492 renderer.set("moveEnabled", moveEnabled);
1493 changed = true;
1494 }
1495 if(resizeEnabled != renderer.get("resizeEnabled")){
1496 renderer.set("resizeEnabled", resizeEnabled);
1497 changed = true;
1498 }
1499
1500 if(changed){
1501 renderer.updateRendering();
1502 }
1503 },
1504
1505 updateRenderers: function(obj, stateOnly){
1506 // summary:
1507 // Updates all the renderers that represents the specified item(s).
1508 // obj: Object
1509 // A render item or an array of render items.
1510 // stateOnly: Boolean
1511 // Whether only the state of the item has changed (selected, edited, edited, focused) or a more global change has occured.
1512 // tags:
1513 // protected
1514
1515 if(obj == null){
1516 return;
1517 }
1518
1519 var items = lang.isArray(obj) ? obj : [obj];
1520
1521 for(var i=0; i<items.length; i++){
1522
1523 var item = items[i];
1524
1525 if(item == null || item.id == null){
1526 continue;
1527 }
1528
1529 var list = this.rendererManager.itemToRenderer[item.id];
1530
1531 if(list == null){
1532 continue;
1533 }
1534
1535 var selected = this.isItemSelected(item);
1536 var hovered = this.isItemHovered(item);
1537 var edited = this.isItemBeingEdited(item);
1538 var focused = this.showFocus ? this.isItemFocused(item) : false;
1539
1540 for(var j = 0; j < list.length; j++){
1541
1542 var renderer = list[j].renderer;
1543 renderer.set("hovered", hovered);
1544 renderer.set("selected", selected);
1545 renderer.set("edited", edited);
1546 renderer.set("focused", focused);
1547 renderer.set("storeState", this.getItemStoreState(item));
1548
1549 this.applyRendererZIndex(item, list[j], hovered, selected, edited, focused);
1550
1551 if(!stateOnly){
1552 renderer.set("item", item); // force content refresh
1553 if(renderer.updateRendering){
1554 renderer.updateRendering(); // reuse previously set dimensions
1555 }
1556 }
1557 }
1558
1559 }
1560 },
1561
1562 applyRendererZIndex: function(item, renderer, hovered, selected, edited, focused){
1563 // summary:
1564 // Applies the z-index to the renderer based on the state of the item.
1565 // This methods is setting a z-index of 20 is the item is selected or edited
1566 // and the current lane value computed by the overlap layout (i.e. the renderers
1567 // are stacked according to their lane).
1568 // item: Object
1569 // The render item.
1570 // renderer: Object
1571 // A renderer associated with the render item.
1572 // hovered: Boolean
1573 // Whether the item is hovered or not.
1574 // selected: Boolean
1575 // Whether the item is selected or not.
1576 // edited: Boolean
1577 // Whether the item is being edited not not.
1578 // focused: Boolean
1579 // Whether the item is focused not not.
1580 // tags:
1581 // protected
1582
1583 domStyle.set(renderer.container, {"zIndex": edited || selected ? 20: item.lane == undefined ? 0 : item.lane});
1584 },
1585
1586 getIdentity: function(item){
1587 return this.owner ? this.owner.getIdentity(item) : item.id;
1588 },
1589
1590 /////////////////////////////////////////////////////
1591 //
1592 // Hovered item
1593 //
1594 ////////////////////////////////////////////////////
1595
1596 _setHoveredItem: function(item, renderer){
1597 // summary:
1598 // Sets the current hovered item.
1599 // item: Object
1600 // The data item.
1601 // renderer: dojox/calendar/_RendererMixin
1602 // The item renderer.
1603 // tags:
1604 // protected
1605
1606 if(this.owner){
1607 this.owner._setHoveredItem(item, renderer);
1608 return;
1609 }
1610
1611 if(this.hoveredItem && item && this.hoveredItem.id != item.id ||
1612 item == null || this.hoveredItem == null){
1613 var old = this.hoveredItem;
1614 this.hoveredItem = item;
1615
1616 this.updateRenderers([old, this.hoveredItem], true);
1617
1618 if(item && renderer){
1619 this._updateEditingCapabilities(item._item ? item._item : item, renderer);
1620 }
1621 }
1622 },
1623
1624 // hoveredItem: Object
1625 // The currently hovered data item.
1626 hoveredItem: null,
1627
1628 isItemHovered: function(item){
1629 // summary:
1630 // Returns whether the specified item is hovered or not.
1631 // item: Object
1632 // The item.
1633 // returns: Boolean
1634 if (this._isEditing && this._edProps){
1635 return item.id == this._edProps.editedItem.id;
1636 }
1637 return this.owner ?
1638 this.owner.isItemHovered(item) :
1639 this.hoveredItem != null && this.hoveredItem.id == item.id;
1640
1641 },
1642
1643 isItemFocused: function(item){
1644 // summary:
1645 // Returns whether the specified item is focused or not.
1646 // item: Object
1647 // The item.
1648 // returns: Boolean
1649 return this._isItemFocused ? this._isItemFocused(item) : false;
1650 },
1651
1652 ////////////////////////////////////////////////////////////////////
1653 //
1654 // Selection delegation
1655 //
1656 ///////////////////////////////////////////////////////////////////
1657
1658 _setSelectionModeAttr: function(value){
1659 if(this.owner){
1660 this.owner.set("selectionMode", value);
1661 }else{
1662 this.inherited(arguments);
1663 }
1664 },
1665
1666 _getSelectionModeAttr: function(value){
1667 if(this.owner){
1668 return this.owner.get("selectionMode");
1669 }
1670 return this.inherited(arguments);
1671 },
1672
1673 _setSelectedItemAttr: function(value){
1674 if(this.owner){
1675 this.owner.set("selectedItem", value);
1676 }else{
1677 this.inherited(arguments);
1678 }
1679 },
1680
1681 _getSelectedItemAttr: function(value){
1682 if(this.owner){
1683 return this.owner.get("selectedItem");
1684 }
1685 return this.selectedItem; // no getter on super class (dojox.widget.Selection)
1686 },
1687
1688 _setSelectedItemsAttr: function(value){
1689 if(this.owner){
1690 this.owner.set("selectedItems", value);
1691 }else{
1692 this.inherited(arguments);
1693 }
1694 },
1695
1696 _getSelectedItemsAttr: function(){
1697 if(this.owner){
1698 return this.owner.get("selectedItems");
1699 }
1700 return this.inherited(arguments);
1701 },
1702
1703 isItemSelected: function(item){
1704 if(this.owner){
1705 return this.owner.isItemSelected(item);
1706 }
1707 return this.inherited(arguments);
1708 },
1709
1710 selectFromEvent: function(e, item, renderer, dispatch){
1711 if(this.owner){
1712 this.owner.selectFromEvent(e, item, renderer, dispatch);
1713 }else{
1714 this.inherited(arguments);
1715 }
1716 },
1717
1718 setItemSelected: function(item, value){
1719 if(this.owner){
1720 this.owner.setItemSelected(item, value);
1721 }else{
1722 this.inherited(arguments);
1723 }
1724 },
1725
1726 ////////////////////////////////////////////////////////////////////
1727 //
1728 // Event creation
1729 //
1730 ///////////////////////////////////////////////////////////////////
1731
1732 createItemFunc: null,
1733 /*=====
1734 createItemFunc: function(view, d, e){
1735 // summary:
1736 // A user supplied function that creates a new event.
1737 // view: ViewBase
1738 // the current view,
1739 // d: Date
1740 // the date at the clicked location.
1741 // e: MouseEvemt
1742 // the mouse event (can be used to return null for example)
1743 // subColumn: Object
1744 // the subcolumn at clicked location (can return null)
1745 },
1746 =====*/
1747
1748
1749 _getCreateItemFuncAttr: function(){
1750 if(this.owner){
1751 return this.owner.get("createItemFunc");
1752 }
1753 return this.createItemFunc;
1754 },
1755
1756 // createOnGridClick: Boolean
1757 // Indicates whether the user can create new event by clicking and dragging the grid.
1758 // A createItem function must be defined on the view or the calendar object.
1759 createOnGridClick: false,
1760
1761 _getCreateOnGridClickAttr: function(){
1762 if(this.owner){
1763 return this.owner.get("createOnGridClick");
1764 }
1765 return this.createOnGridClick;
1766 },
1767
1768 ////////////////////////////////////////////////////////////////////
1769 //
1770 // Event creation
1771 //
1772 ///////////////////////////////////////////////////////////////////
1773
1774 _gridMouseDown: false,
1775
1776 _tempIdCount: 0,
1777 _tempItemsMap: null,
1778
1779 _onGridMouseDown: function(e){
1780 // tags:
1781 // private
1782 this._gridMouseDown = true;
1783
1784 this.showFocus = false;
1785
1786 if(this._isEditing){
1787 this._endItemEditing("mouse", false);
1788 }
1789
1790 this._doEndItemEditing(this.owner, "mouse");
1791
1792 this.set("focusedItem", null);
1793 this.selectFromEvent(e, null, null, true);
1794
1795 if(this._setTabIndexAttr){
1796 this[this._setTabIndexAttr].focus();
1797 }
1798
1799 if(this._onRendererHandleMouseDown){
1800
1801 var f = this.get("createItemFunc");
1802
1803 if(!f){
1804 return;
1805 }
1806
1807 var newItem = this._createdEvent = f(this, this.getTime(e), e, this.getSubColumn(e));
1808
1809 var store = this.get("store");
1810
1811 if(!newItem || store == null){
1812 return;
1813 }
1814
1815 // calendar needs an ID to work with
1816 if(store.getIdentity(newItem) == undefined){
1817 var id = "_tempId_" + (this._tempIdCount++);
1818 newItem[store.idProperty] = id;
1819 if(this._tempItemsMap == null){
1820 this._tempItemsMap = {};
1821 }
1822 this._tempItemsMap[id] = true;
1823 }
1824
1825 var newRenderItem = this.itemToRenderItem(newItem, store);
1826 newRenderItem._item = newItem;
1827 this._setItemStoreState(newItem, "unstored");
1828
1829 // add the new temporary item to the displayed list and force view refresh
1830 var owner = this._getTopOwner();
1831 var items = owner.get("items");
1832
1833 owner.set("items", items ? items.concat([newRenderItem]) : [newRenderItem]);
1834
1835 this._refreshItemsRendering();
1836
1837 // renderer created in _refreshItemsRenderering()
1838 var renderers = this.getRenderers(newItem);
1839 if(renderers && renderers.length>0){
1840 var renderer = renderers[0];
1841 if(renderer){
1842 // trigger editing
1843 this._onRendererHandleMouseDown(e, renderer.renderer, "resizeEnd");
1844 this._startItemEditing(newRenderItem, "mouse");
1845 }
1846 }
1847 }
1848 },
1849
1850 _onGridMouseMove: function(e){
1851 // tags:
1852 // private
1853 },
1854
1855 _onGridMouseUp: function(e){
1856 // tags:
1857 // private
1858 },
1859
1860 _onGridTouchStart: function(e){
1861 // tags:
1862 // private
1863
1864 var p = this._edProps;
1865
1866 this._gridProps = {
1867 event: e,
1868 fromItem: this.isAscendantHasClass(e.target, this.eventContainer, "dojoxCalendarEvent")
1869 };
1870
1871 if(this._isEditing){
1872
1873 if(this._gridProps){
1874 this._gridProps.editingOnStart = true;
1875 }
1876
1877 lang.mixin(p, this._getTouchesOnRenderers(e, p.editedItem));
1878
1879 if(p.touchesLen == 0){
1880
1881 if(p && p.endEditingTimer){
1882 clearTimeout(p.endEditingTimer);
1883 p.endEditingTimer = null;
1884 }
1885 this._endItemEditing("touch", false);
1886 }
1887 }
1888
1889 this._doEndItemEditing(this.owner, "touch");
1890
1891 event.stop(e);
1892
1893 },
1894
1895 _doEndItemEditing: function(obj, eventSource){
1896 // tags:
1897 // private
1898
1899 if(obj && obj._isEditing){
1900 var p = obj._edProps;
1901 if(p && p.endEditingTimer){
1902 clearTimeout(p.endEditingTimer);
1903 p.endEditingTimer = null;
1904 }
1905 obj._endItemEditing(eventSource, false);
1906 }
1907 },
1908
1909 _onGridTouchEnd: function(e){
1910 // tags:
1911 // private
1912 },
1913
1914 _onGridTouchMove: function(e){
1915 // tags:
1916 // private
1917 },
1918
1919 __fixEvt: function(e){
1920 // summary:
1921 // Extension point for a view to add some event properties to a calendar event.
1922 // tags:
1923 // callback
1924 return e;
1925 },
1926
1927 _dispatchCalendarEvt: function(e, name){
1928 // summary:
1929 // Adds view properties to event and enable bubbling at owner level.
1930 // e: Event
1931 // The dispatched event.
1932 // name: String
1933 // The event name.
1934 // tags:
1935 // protected
1936
1937 e = this.__fixEvt(e);
1938 this[name](e);
1939 if(this.owner){
1940 this.owner[name](e);
1941 }
1942 return e;
1943 },
1944
1945 _onGridClick: function(e){
1946 // tags:
1947 // private
1948 if(!e.triggerEvent){
1949 e = {
1950 date: this.getTime(e),
1951 triggerEvent: e
1952 };
1953 }
1954
1955 this._dispatchCalendarEvt(e, "onGridClick");
1956 },
1957
1958 onGridClick: function(e){
1959 // summary:
1960 // Event dispatched when the grid has been clicked.
1961 // e: __GridClickEventArgs
1962 // The event dispatched when the grid is clicked.
1963 // tags:
1964 // callback
1965 },
1966
1967 _onGridDoubleClick: function(e){
1968 // tags:
1969 // private
1970
1971 if(!e.triggerEvent){
1972 e = {
1973 date: this.getTime(e),
1974 triggerEvent: e
1975 };
1976 }
1977
1978 this._dispatchCalendarEvt(e, "onGridDoubleClick");
1979 },
1980
1981 onGridDoubleClick: function(e){
1982 // summary:
1983 // Event dispatched when the grid has been double-clicked.
1984 // e: __GridClickEventArgs
1985 // The event dispatched when the grid is double-clicked.
1986 // tags:
1987 // protected
1988
1989 },
1990
1991 _onItemClick: function(e){
1992 // tags:
1993 // private
1994
1995 this._dispatchCalendarEvt(e, "onItemClick");
1996 },
1997
1998 onItemClick: function(e){
1999 // summary:
2000 // Event dispatched when an item renderer has been clicked.
2001 // e: __ItemMouseEventArgs
2002 // The event dispatched when an item is clicked.
2003 // tags:
2004 // callback
2005
2006 },
2007
2008 _onItemDoubleClick: function(e){
2009 // tags:
2010 // private
2011
2012 this._dispatchCalendarEvt(e, "onItemDoubleClick");
2013 },
2014
2015 onItemDoubleClick: function(e){
2016 // summary:
2017 // Event dispatched when an item renderer has been double-clicked.
2018 // e: __ItemMouseEventArgs
2019 // The event dispatched when an item is double-clicked.
2020 // tags:
2021 // callback
2022
2023 },
2024
2025 _onItemContextMenu: function(e){
2026 this._dispatchCalendarEvt(e, "onItemContextMenu");
2027 // tags:
2028 // private
2029
2030 },
2031
2032 onItemContextMenu: function(e){
2033 // summary:
2034 // Event dispatched when an item renderer has been context-clicked.
2035 // e: __ItemMouseEventArgs
2036 // The event dispatched when an item is context-clicked.
2037 // tags:
2038 // callback
2039
2040 },
2041
2042 //////////////////////////////////////////////////////////
2043 //
2044 // Editing
2045 //
2046 //////////////////////////////////////////////////////////
2047
2048 _getStartEndRenderers: function(item){
2049 // summary:
2050 // Returns an array that contains the first and last renderers of an item
2051 // that are currently displayed. They could be the same renderer if only one renderer is used.
2052 // item: Object
2053 // The render item.
2054 // returns: Object[]
2055 // tags:
2056 // protected
2057
2058
2059 var list = this.rendererManager.itemToRenderer[item.id];
2060
2061 if(list == null){
2062 return null;
2063 }
2064
2065 // trivial and most common use case.
2066 if(list.length == 1){
2067 var node = list[0].renderer;
2068 return [node, node];
2069 }
2070
2071 var rd = this.renderData;
2072 var resizeStartFound = false;
2073 var resizeEndFound = false;
2074
2075 var res = [];
2076
2077 for(var i=0; i<list.length; i++){
2078
2079 var ir = list[i].renderer;
2080
2081 if (!resizeStartFound){
2082 resizeStartFound = rd.dateModule.compare(ir.item.range[0], ir.item.startTime) == 0;
2083 res[0] = ir;
2084 }
2085
2086 if (!resizeEndFound){
2087 resizeEndFound = rd.dateModule.compare(ir.item.range[1], ir.item.endTime) == 0;
2088 res[1] = ir;
2089 }
2090
2091 if (resizeStartFound && resizeEndFound){
2092 break;
2093 }
2094 }
2095
2096 return res;
2097 },
2098
2099 // editable: Boolean
2100 // A flag that indicates whether or not the user can edit
2101 // items in the data provider.
2102 // If <code>true</code>, the item renderers in the control are editable.
2103 // The user can click on an item renderer, or use the keyboard or touch devices, to move or resize the associated event.
2104 editable: true,
2105
2106 // moveEnabled: Boolean
2107 // A flag that indicates whether the user can move items displayed.
2108 // If <code>true</code>, the user can move the items.
2109 moveEnabled: true,
2110
2111 // resizeEnabled: Boolean
2112 // A flag that indicates whether the items can be resized.
2113 // If `true`, the control supports resizing of items.
2114 resizeEnabled: true,
2115
2116 isItemEditable: function(item, rendererKind){
2117 // summary:
2118 // Computes whether particular item renderer can be edited or not.
2119 // By default it is using the editable property value.
2120 // item: Object
2121 // The item represented by the renderer.
2122 // rendererKind: String
2123 // The kind of renderer.
2124 // returns: Boolean
2125 return this.getItemStoreState(item) != "storing" && this.editable && (this.owner ? this.owner.isItemEditable(item, rendererKind) : true);
2126 },
2127
2128 isItemMoveEnabled: function(item, rendererKind){
2129 // summary:
2130 // Computes whether particular item renderer can be moved.
2131 // By default it is using the moveEnabled property value.
2132 // item: Object
2133 // The item represented by the renderer.
2134 // rendererKind: String
2135 // The kind of renderer.
2136 // returns: Boolean
2137 return this.isItemEditable(item, rendererKind) && this.moveEnabled &&
2138 (this.owner ? this.owner.isItemMoveEnabled(item, rendererKind): true);
2139 },
2140
2141 isItemResizeEnabled: function(item, rendererKind){
2142 // summary:
2143 // Computes whether particular item renderer can be resized.
2144 // By default it is using the resizedEnabled property value.
2145 // item: Object
2146 // The item represented by the renderer.
2147 // rendererKind: String
2148 // The kind of renderer.
2149 // returns: Boolean
2150
2151 return this.isItemEditable(item, rendererKind) && this.resizeEnabled &&
2152 (this.owner ? this.owner.isItemResizeEnabled(item, rendererKind): true);
2153 },
2154
2155 // _isEditing: Boolean
2156 // Whether an item is being edited or not.
2157 _isEditing: false,
2158
2159 isItemBeingEdited: function(item){
2160 // summary:
2161 // Returns whether an item is being edited or not.
2162 // item: Object
2163 // The item to test.
2164 // returns: Boolean
2165 return this._isEditing && this._edProps && this._edProps.editedItem && this._edProps.editedItem.id == item.id;
2166 },
2167
2168 _setEditingProperties: function(props){
2169 // summary:
2170 // Registers the editing properties used by the editing functions.
2171 // This method should only be called by editing interaction mixins like Mouse, Keyboard and Touch.
2172 // tags:
2173 // protected
2174
2175 this._edProps = props;
2176 },
2177
2178 _startItemEditing: function(item, eventSource){
2179 // summary:
2180 // Configures the component, renderers to start one (mouse) of several (touch, keyboard) editing gestures.
2181 // item: Object
2182 // The item that will be edited.
2183 // eventSource: String
2184 // "mouse", "keyboard", "touch"
2185 // tags:
2186 // protected
2187
2188 this._isEditing = true;
2189 this._getTopOwner()._isEditing = true;
2190 var p = this._edProps;
2191
2192 p.editedItem = item;
2193 p.storeItem = item._item;
2194 p.eventSource = eventSource;
2195
2196 p.secItem = this._secondarySheet ? this._findRenderItem(item.id, this._secondarySheet.renderData.items) : null;
2197 p.ownerItem = this.owner ? this._findRenderItem(item.id, this.items) : null;
2198
2199 if (!p.liveLayout){
2200 p.editSaveStartTime = item.startTime;
2201 p.editSaveEndTime = item.endTime;
2202
2203 p.editItemToRenderer = this.rendererManager.itemToRenderer;
2204 p.editItems = this.renderData.items;
2205 p.editRendererList = this.rendererManager.rendererList;
2206
2207 this.renderData.items = [p.editedItem];
2208 var id = p.editedItem.id;
2209
2210 this.rendererManager.itemToRenderer = {};
2211 this.rendererManager.rendererList = [];
2212 var list = p.editItemToRenderer[id];
2213
2214 p.editRendererIndices = [];
2215
2216 arr.forEach(list, lang.hitch(this, function(ir, i){
2217 if(this.rendererManager.itemToRenderer[id] == null){
2218 this.rendererManager.itemToRenderer[id] = [ir];
2219 }else{
2220 this.rendererManager.itemToRenderer[id].push(ir);
2221 }
2222 this.rendererManager.rendererList.push(ir);
2223 }));
2224
2225 // remove in old map & list the occurrence used by the edited item
2226 p.editRendererList = arr.filter(p.editRendererList, function(ir){
2227 return ir != null && ir.renderer.item.id != id;
2228 });
2229 delete p.editItemToRenderer[id];
2230 }
2231
2232 // graphic feedback refresh
2233 this._layoutRenderers(this.renderData);
2234
2235 this._onItemEditBegin({
2236 item: item,
2237 storeItem: p.storeItem,
2238 eventSource: eventSource
2239 });
2240 },
2241
2242 _onItemEditBegin: function(e){
2243 // tags:
2244 // private
2245
2246 this._editStartTimeSave = this.newDate(e.item.startTime);
2247 this._editEndTimeSave = this.newDate(e.item.endTime);
2248
2249 this._dispatchCalendarEvt(e, "onItemEditBegin");
2250 },
2251
2252 onItemEditBegin: function(e){
2253 // summary:
2254 // Event dispatched when the item is entering the editing mode.
2255 // tags:
2256 // callback
2257
2258 },
2259
2260 _endItemEditing: function(/*String*/eventSource, /*Boolean*/canceled){
2261 // summary:
2262 // Leaves the item editing mode.
2263 // item: Object
2264 // The item that was edited.
2265 // eventSource: String
2266 // "mouse", "keyboard", "touch"
2267 // tags:
2268 // protected
2269
2270 if(this._editingGesture){
2271 // make sure to stop the current gesture if any
2272 this._endItemEditingGesture(eventSource);
2273 }
2274
2275 this._isEditing = false;
2276 this._getTopOwner()._isEditing = false;
2277
2278 var p = this._edProps;
2279
2280 arr.forEach(p.handles, function(handle){
2281 handle.remove();
2282 });
2283
2284 if (!p.liveLayout){
2285 this.renderData.items = p.editItems;
2286 this.rendererManager.rendererList = p.editRendererList.concat(this.rendererManager.rendererList);
2287 lang.mixin(this.rendererManager.itemToRenderer, p.editItemToRenderer);
2288 }
2289
2290 this._onItemEditEnd(lang.mixin(this._createItemEditEvent(), {
2291 item: p.editedItem,
2292 storeItem: p.storeItem,
2293 eventSource: eventSource,
2294 completed: !canceled
2295 }));
2296
2297 this._layoutRenderers(this.renderData);
2298
2299 this._edProps = null;
2300 },
2301
2302 _onItemEditEnd: function(e){
2303 // tags:
2304 // private
2305
2306 this._dispatchCalendarEvt(e, "onItemEditEnd");
2307
2308 if(!e.isDefaultPrevented()){
2309
2310 var store = this.get("store");
2311
2312 // updated store item
2313 var storeItem = this.renderItemToItem(e.item, store);
2314
2315 var s = this._getItemStoreStateObj(e.item);
2316
2317 if(s != null && s.state == "unstored"){
2318
2319 if(e.completed){
2320 // renderItemToItem cannot find the original data item
2321 // (as it does not exist in the store yet) to mixin with.
2322 // so we must do it here.
2323 storeItem = lang.mixin(s.item, storeItem);
2324 this._setItemStoreState(storeItem, "storing");
2325 var oldID = store.getIdentity(storeItem);
2326 var options = null;
2327
2328 if(this._tempItemsMap && this._tempItemsMap[oldID]){
2329 options = {temporaryId: oldID};
2330 delete this._tempItemsMap[oldID];
2331 delete storeItem[store.idProperty];
2332 }
2333
2334 // add to the store.
2335 when(store.add(storeItem, options), lang.hitch(this, function(res){
2336 var id;
2337 if(lang.isObject(res)){
2338 id = store.getIdentity(res);
2339 }else{
2340 id = res;
2341 }
2342
2343 if(id != oldID){
2344 this._removeRenderItem(oldID);
2345 }
2346 }));
2347
2348 }else{ // creation canceled
2349 // cleanup items list
2350
2351 this._removeRenderItem(s.id);
2352 }
2353
2354 } else if(e.completed){
2355 // Inject new properties in data store item
2356 // and apply data changes
2357 this._setItemStoreState(storeItem, "storing");
2358 store.put(storeItem);
2359 }else{
2360 e.item.startTime = this._editStartTimeSave;
2361 e.item.endTime = this._editEndTimeSave;
2362 }
2363 }
2364 },
2365
2366 _removeRenderItem: function(id){
2367
2368 var owner = this._getTopOwner();
2369 var items = owner.get("items");
2370 var l = items.length;
2371 var found = false;
2372 for(var i=l-1; i>=0; i--){
2373 if(items[i].id == id){
2374 items.splice(i, 1);
2375 found = true;
2376 break;
2377 }
2378 }
2379 this._cleanItemStoreState(id);
2380 if(found){
2381 owner.set("items", items); //force a complete relayout
2382 this.invalidateLayout();
2383 }
2384 },
2385
2386 onItemEditEnd: function(e){
2387 // summary:
2388 // Event dispatched when the item is leaving the editing mode.
2389 // tags:
2390 // protected
2391
2392 },
2393
2394 _createItemEditEvent: function(){
2395 // tags:
2396 // private
2397
2398 var e = {
2399 cancelable: true,
2400 bubbles: false,
2401 __defaultPrevent: false
2402 };
2403
2404 e.preventDefault = function(){
2405 this.__defaultPrevented = true;
2406 };
2407
2408 e.isDefaultPrevented = function(){
2409 return this.__defaultPrevented;
2410 };
2411
2412 return e;
2413 },
2414
2415
2416 _startItemEditingGesture: function(dates, editKind, eventSource, e){
2417 // summary:
2418 // Starts the editing gesture.
2419 // date: Date[]
2420 // The reference dates (at least one).
2421 // editKind: String
2422 // Kind of edit: "resizeBoth", "resizeStart", "resizeEnd" or "move".
2423 // eventSource: String
2424 // "mouse", "keyboard", "touch"
2425 // e: Event
2426 // The event at the origin of the editing gesture.
2427 // tags:
2428 // protected
2429
2430 var p = this._edProps;
2431
2432 if(!p || p.editedItem == null){
2433 return;
2434 }
2435
2436 this._editingGesture = true;
2437
2438 var item = p.editedItem;
2439
2440 p.editKind = editKind;
2441
2442 this._onItemEditBeginGesture(this.__fixEvt(lang.mixin(this._createItemEditEvent(), {
2443 item: item,
2444 storeItem: p.storeItem,
2445 startTime: item.startTime,
2446 endTime: item.endTime,
2447 editKind: editKind,
2448 rendererKind: p.rendererKind,
2449 triggerEvent: e,
2450 dates: dates,
2451 eventSource: eventSource
2452 })));
2453
2454 p.itemBeginDispatched = true;
2455
2456 },
2457
2458
2459 _onItemEditBeginGesture: function(e){
2460 // tags:
2461 // private
2462 var p = this._edProps;
2463
2464 var item = p.editedItem;
2465 var dates = e.dates;
2466
2467 p.editingTimeFrom = [];
2468 p.editingTimeFrom[0] = dates[0];
2469
2470 p.editingItemRefTime = [];
2471 p.editingItemRefTime[0] = this.newDate(p.editKind == "resizeEnd" ? item.endTime : item.startTime);
2472
2473 if (p.editKind == "resizeBoth"){
2474 p.editingTimeFrom[1] = dates[1];
2475 p.editingItemRefTime[1] = this.newDate(item.endTime);
2476 }
2477
2478 var cal = this.renderData.dateModule;
2479
2480 p.inViewOnce = this._isItemInView(item);
2481
2482 if(p.rendererKind == "label" || this.roundToDay){
2483 p._itemEditBeginSave = this.newDate(item.startTime);
2484 p._itemEditEndSave = this.newDate(item.endTime);
2485 }
2486
2487 p._initDuration = cal.difference(item.startTime, item.endTime, item.allDay?"day":"millisecond");
2488
2489 this._dispatchCalendarEvt(e, "onItemEditBeginGesture");
2490
2491 if (!e.isDefaultPrevented()){
2492
2493 if (e.eventSource == "mouse"){
2494 var cursor = e.editKind=="move"?"move":this.resizeCursor;
2495 p.editLayer = domConstruct.create("div", {
2496 style: "position: absolute; left:0; right:0; bottom:0; top:0; z-index:30; tabIndex:-1; background-image:url('"+this._blankGif+"'); cursor: "+cursor,
2497 onresizestart: function(e){return false;},
2498 onselectstart: function(e){return false;}
2499 }, this.domNode);
2500 p.editLayer.focus();
2501 }
2502 }
2503 },
2504
2505 onItemEditBeginGesture: function(e){
2506 // summary:
2507 // Event dispatched when an editing gesture is beginning.
2508 // e: __itemEditingEventArgs
2509 // The editing event.
2510 // tags:
2511 // callback
2512
2513 },
2514
2515 _waDojoxAddIssue: function(d, unit, steps){
2516 // summary:
2517 // Workaround an issue of dojox.date.XXXXX.date.add() function
2518 // that does not support the subtraction of time correctly (normalization issues).
2519 // d: Date
2520 // Reference date.
2521 // unit: String
2522 // Unit to add.
2523 // steps: Integer
2524 // Number of units to add.
2525 // tags:
2526 // protected
2527
2528 var cal = this.renderData.dateModule;
2529 if(this._calendar != "gregorian" && steps < 0){
2530 var gd = d.toGregorian();
2531 gd = date.add(gd, unit, steps);
2532 return new this.renderData.dateClassObj(gd);
2533 }else{
2534 return cal.add(d, unit, steps);
2535 }
2536 },
2537
2538 _computeItemEditingTimes: function(item, editKind, rendererKind, times, eventSource){
2539 // tags:
2540 // private
2541
2542 var cal = this.renderData.dateModule;
2543 var p = this._edProps;
2544 if(editKind == "move"){
2545 var diff = cal.difference(p.editingTimeFrom[0], times[0], "millisecond");
2546 times[0] = this._waDojoxAddIssue(p.editingItemRefTime[0], "millisecond", diff);
2547 }
2548 return times;
2549 },
2550
2551 _moveOrResizeItemGesture: function(dates, eventSource, e, subColumn){
2552 // summary:
2553 // Moves or resizes an item.
2554 // dates: Date[]
2555 // The reference dates.
2556 // editKind: String
2557 // Kind of edit: "resizeStart", "resizeEnd", "resizeBoth" or "move".
2558 // eventSource: String
2559 // "mouse", "keyboard", "touch"
2560 // e: Event
2561 // The event at the origin of the editing gesture.
2562 // subColumn: String
2563 // The sub column value, if any, or null.
2564 // tags:
2565 // private
2566
2567 if(!this._isEditing || dates[0] == null){
2568 return;
2569 }
2570
2571 var p = this._edProps;
2572 var item = p.editedItem;
2573 var rd = this.renderData;
2574 var cal = rd.dateModule;
2575 var editKind = p.editKind;
2576
2577 var newTimes = [dates[0]];
2578
2579 if(editKind == "resizeBoth"){
2580 newTimes[1] = dates[1];
2581 }
2582
2583 newTimes = this._computeItemEditingTimes(item, p.editKind, p.rendererKind, newTimes, eventSource);
2584
2585 var newTime = newTimes[0]; // usual use case
2586
2587 var moveOrResizeDone = false;
2588
2589 var oldStart = lang.clone(item.startTime);
2590 var oldEnd = lang.clone(item.endTime);
2591 var oldSubColumn = item.subColumn;
2592
2593 // swap cannot used using keyboard as a gesture is made of one single change (loss of start/end context).
2594 var allowSwap = p.eventSource == "keyboard" ? false : this.allowStartEndSwap;
2595
2596 // Update the Calendar with the edited value.
2597 if(editKind == "move"){
2598 if(subColumn != null && item.subColumn != subColumn && this.allowSubColumnMove){
2599 // TODO abstract change?
2600 item.subColumn = subColumn;
2601 // refresh the other properties that depends on this one (especially cssClass)
2602 var store = this.get("store");
2603 var storeItem = this.renderItemToItem(item, store);
2604 lang.mixin(item, this.itemToRenderItem(storeItem, store));
2605 moveOrResizeDone = true;
2606 }
2607 if(cal.compare(item.startTime, newTime) != 0){
2608 var duration = cal.difference(item.startTime, item.endTime, "millisecond");
2609 item.startTime = this.newDate(newTime);
2610 item.endTime = cal.add(item.startTime, "millisecond", duration);
2611 moveOrResizeDone = true;
2612 }
2613
2614 }else if(editKind == "resizeStart"){
2615
2616 if(cal.compare(item.startTime, newTime) != 0){
2617 if(cal.compare(item.endTime, newTime) != -1){
2618 item.startTime = this.newDate(newTime);
2619 }else{ // swap detected
2620 if(allowSwap){
2621 item.startTime = this.newDate(item.endTime);
2622 item.endTime = this.newDate(newTime);
2623 p.editKind = editKind = "resizeEnd";
2624 if(eventSource == "touch"){ // invert touches as well!
2625 p.resizeEndTouchIndex = p.resizeStartTouchIndex;
2626 p.resizeStartTouchIndex = -1;
2627 }
2628 }else{ // block the swap but keep the time of day
2629 item.startTime = this.newDate(item.endTime);
2630 item.startTime.setHours(newTime.getHours());
2631 item.startTime.setMinutes(newTime.getMinutes());
2632 item.startTime.setSeconds(newTime.getSeconds());
2633 }
2634 }
2635 moveOrResizeDone = true;
2636 }
2637
2638 }else if(editKind == "resizeEnd"){
2639
2640 if(cal.compare(item.endTime, newTime) != 0){
2641 if(cal.compare(item.startTime, newTime) != 1){
2642 item.endTime = this.newDate(newTime);
2643 }else{ // swap detected
2644
2645 if(allowSwap){
2646 item.endTime = this.newDate(item.startTime);
2647 item.startTime = this.newDate(newTime);
2648 p.editKind = editKind = "resizeStart";
2649 if(eventSource == "touch"){ // invert touches as well!
2650 p.resizeStartTouchIndex = p.resizeEndTouchIndex;
2651 p.resizeEndTouchIndex = -1;
2652 }
2653 }else{ // block the swap but keep the time of day
2654 item.endTime = this.newDate(item.startTime);
2655 item.endTime.setHours(newTime.getHours());
2656 item.endTime.setMinutes(newTime.getMinutes());
2657 item.endTime.setSeconds(newTime.getSeconds());
2658 }
2659 }
2660
2661 moveOrResizeDone = true;
2662 }
2663 }else if(editKind == "resizeBoth"){
2664
2665 moveOrResizeDone = true;
2666
2667 var start = this.newDate(newTime);
2668 var end = this.newDate(newTimes[1]);
2669
2670 if(cal.compare(start, end) != -1){ // swap detected
2671 if(allowSwap){
2672 var t = start;
2673 start = end;
2674 end = t;
2675 }else{ // as both ends are moved, the simple way is to forbid the move gesture.
2676 moveOrResizeDone = false;
2677 }
2678 }
2679
2680 if(moveOrResizeDone){
2681 item.startTime = start;
2682 item.endTime = end;
2683 }
2684
2685 }else{
2686 return false;
2687 }
2688
2689 if(!moveOrResizeDone){
2690 return false;
2691 }
2692
2693 var evt = lang.mixin(this._createItemEditEvent(), {
2694 item: item,
2695 storeItem: p.storeItem,
2696 startTime: item.startTime,
2697 endTime: item.endTime,
2698 editKind: editKind,
2699 rendererKind: p.rendererKind,
2700 triggerEvent: e,
2701 eventSource: eventSource
2702 });
2703
2704 // trigger snapping, rounding, minimal duration, boundaries checks etc.
2705 if(editKind == "move"){
2706 this._onItemEditMoveGesture(evt);
2707 }else{
2708 this._onItemEditResizeGesture(evt);
2709 }
2710
2711 // prevent invalid range
2712 if(cal.compare(item.startTime, item.endTime) == 1){
2713 var tmp = item.startTime;
2714 item.startTime = item.endTime;
2715 item.endTime = tmp;
2716 }
2717
2718 moveOrResizeDone =
2719 oldSubColumn != item.subColumn ||
2720 cal.compare(oldStart, item.startTime) != 0 ||
2721 cal.compare(oldEnd, item.endTime) != 0;
2722
2723 if(!moveOrResizeDone){
2724 return false;
2725 }
2726
2727 this._layoutRenderers(this.renderData);
2728
2729 if(p.liveLayout && p.secItem != null){
2730 p.secItem.startTime = item.startTime;
2731 p.secItem.endTime = item.endTime;
2732 this._secondarySheet._layoutRenderers(this._secondarySheet.renderData);
2733 }else if(p.ownerItem != null && this.owner.liveLayout){
2734 p.ownerItem.startTime = item.startTime;
2735 p.ownerItem.endTime = item.endTime;
2736 this.owner._layoutRenderers(this.owner.renderData);
2737 }
2738
2739 return true;
2740 },
2741
2742 _findRenderItem: function(id, list){
2743 // tags:
2744 // private
2745
2746 list = list || this.renderData.items;
2747 for(var i=0; i<list.length; i++){
2748 if(list[i].id == id){
2749 return list[i];
2750 }
2751 }
2752 return null;
2753 },
2754
2755 _onItemEditMoveGesture: function(e){
2756 // tags:
2757 // private
2758
2759 this._dispatchCalendarEvt(e, "onItemEditMoveGesture");
2760
2761 if(!e.isDefaultPrevented()){
2762
2763 var p = e.source._edProps;
2764 var rd = this.renderData;
2765 var cal = rd.dateModule;
2766 var newStartTime, newEndTime;
2767
2768 if(p.rendererKind == "label" || (this.roundToDay && !e.item.allDay)){
2769
2770 newStartTime = this.floorToDay(e.item.startTime, false, rd);
2771 newStartTime.setHours(p._itemEditBeginSave.getHours());
2772 newStartTime.setMinutes(p._itemEditBeginSave.getMinutes());
2773
2774 newEndTime = cal.add(newStartTime, "millisecond", p._initDuration);
2775
2776 }else if(e.item.allDay){
2777 newStartTime = this.floorToDay(e.item.startTime, true);
2778 newEndTime = cal.add(newStartTime, "day", p._initDuration);
2779 }else{
2780 newStartTime = this.floorDate(e.item.startTime, this.snapUnit, this.snapSteps);
2781 newEndTime = cal.add(newStartTime, "millisecond", p._initDuration);
2782 }
2783
2784 e.item.startTime = newStartTime;
2785 e.item.endTime = newEndTime;
2786
2787 if(!p.inViewOnce){
2788 p.inViewOnce = this._isItemInView(e.item);
2789 }
2790
2791 // to prevent strange behaviors use constraint in items already fully in view.
2792 if(p.inViewOnce && this.stayInView){
2793 this._ensureItemInView(e.item);
2794 }
2795 }
2796 },
2797
2798 _DAY_IN_MILLISECONDS: 24 * 60 * 60 * 1000,
2799
2800 onItemEditMoveGesture: function(e){
2801 // summary:
2802 // Event dispatched during a move editing gesture.
2803 // e: __itemEditingEventArgs
2804 // The editing event.
2805 // tags:
2806 // callback
2807
2808 },
2809
2810 _onItemEditResizeGesture: function(e){
2811 // tags:
2812 // private
2813
2814 this._dispatchCalendarEvt(e, "onItemEditResizeGesture");
2815
2816 if(!e.isDefaultPrevented()){
2817
2818 var p = e.source._edProps;
2819 var rd = this.renderData;
2820 var cal = rd.dateModule;
2821
2822 var newStartTime = e.item.startTime;
2823 var newEndTime = e.item.endTime;
2824
2825 if(e.editKind == "resizeStart"){
2826 if(e.item.allDay){
2827 newStartTime = this.floorToDay(e.item.startTime, false, this.renderData);
2828 }else if(this.roundToDay){
2829 newStartTime = this.floorToDay(e.item.startTime, false, rd);
2830 newStartTime.setHours(p._itemEditBeginSave.getHours());
2831 newStartTime.setMinutes(p._itemEditBeginSave.getMinutes());
2832 }else{
2833 newStartTime = this.floorDate(e.item.startTime, this.snapUnit, this.snapSteps);
2834 }
2835 }else if(e.editKind == "resizeEnd"){
2836 if(e.item.allDay){
2837 if(!this.isStartOfDay(e.item.endTime)){
2838 newEndTime = this.floorToDay(e.item.endTime, false, this.renderData);
2839 newEndTime = cal.add(newEndTime, "day", 1);
2840 }
2841 }else if(this.roundToDay){
2842 newEndTime = this.floorToDay(e.item.endTime, false, rd);
2843 newEndTime.setHours(p._itemEditEndSave.getHours());
2844 newEndTime.setMinutes(p._itemEditEndSave.getMinutes());
2845 }else{
2846 newEndTime = this.floorDate(e.item.endTime, this.snapUnit, this.snapSteps);
2847
2848 if(e.eventSource == "mouse"){
2849 newEndTime = cal.add(newEndTime, this.snapUnit, this.snapSteps);
2850 }
2851 }
2852 }else{ // Resize both
2853 newStartTime = this.floorDate(e.item.startTime, this.snapUnit, this.snapSteps);
2854 newEndTime = this.floorDate(e.item.endTime, this.snapUnit, this.snapSteps);
2855 newEndTime = cal.add(newEndTime, this.snapUnit, this.snapSteps);
2856 }
2857
2858 e.item.startTime = newStartTime;
2859 e.item.endTime = newEndTime;
2860
2861 var minimalDay = e.item.allDay || p._initDuration >= this._DAY_IN_MILLISECONDS && !this.allowResizeLessThan24H;
2862
2863 this.ensureMinimalDuration(this.renderData, e.item,
2864 minimalDay ? "day" : this.minDurationUnit,
2865 minimalDay ? 1 : this.minDurationSteps,
2866 e.editKind);
2867
2868 if(!p.inViewOnce){
2869 p.inViewOnce = this._isItemInView(e.item);
2870 }
2871
2872 // to prevent strange behaviors use constraint in items already fully in view.
2873 if(p.inViewOnce && this.stayInView){
2874 this._ensureItemInView(e.item);
2875 }
2876 }
2877 },
2878
2879 onItemEditResizeGesture: function(e){
2880 // summary:
2881 // Event dispatched during a resize editing gesture.
2882 // e: __itemEditingEventArgs
2883 // The editing event.
2884 // tags:
2885 // callback
2886
2887 },
2888
2889 _endItemEditingGesture: function(/*String*/eventSource, /*Event*/e){
2890 // tags:
2891 // protected
2892
2893 if(!this._isEditing){
2894 return;
2895 }
2896
2897 this._editingGesture = false;
2898
2899 var p = this._edProps;
2900 var item = p.editedItem;
2901
2902 p.itemBeginDispatched = false;
2903
2904 this._onItemEditEndGesture(lang.mixin(this._createItemEditEvent(), {
2905 item: item,
2906 storeItem: p.storeItem,
2907 startTime: item.startTime,
2908 endTime: item.endTime,
2909 editKind: p.editKind,
2910 rendererKind: p.rendererKind,
2911 triggerEvent: e,
2912 eventSource: eventSource
2913 }));
2914
2915 },
2916
2917 _onItemEditEndGesture: function(e){
2918 // tags:
2919 // private
2920
2921 var p = this._edProps;
2922
2923 delete p._itemEditBeginSave;
2924 delete p._itemEditEndSave;
2925
2926 this._dispatchCalendarEvt(e, "onItemEditEndGesture");
2927
2928 if (!e.isDefaultPrevented()){
2929 if(p.editLayer){
2930 if(has("ie")){
2931 p.editLayer.style.cursor = "default";
2932 }
2933 setTimeout(lang.hitch(this, function(){
2934 if(this.domNode){ // for unit tests
2935 this.domNode.focus();
2936 p.editLayer.parentNode.removeChild(p.editLayer);
2937 p.editLayer = null;
2938 }
2939 }), 10);
2940
2941 }
2942 }
2943 },
2944
2945 onItemEditEndGesture: function(e){
2946 // summary:
2947 // Event dispatched at the end of an editing gesture.
2948 // e: __itemEditingEventArgs
2949 // The editing event.
2950 // tags:
2951 // callback
2952
2953 },
2954
2955 ensureMinimalDuration: function(renderData, item, unit, steps, editKind){
2956 // summary:
2957 // During the resize editing gesture, ensures that the item has the specified minimal duration.
2958 // renderData: Object
2959 // The render data.
2960 // item: Object
2961 // The edited item.
2962 // unit: String
2963 // The unit used to define the minimal duration.
2964 // steps: Integer
2965 // The number of time units.
2966 // editKind: String
2967 // The edit kind: "resizeStart" or "resizeEnd".
2968 var minTime;
2969 var cal = renderData.dateModule;
2970
2971 if(editKind == "resizeStart"){
2972 minTime = cal.add(item.endTime, unit, -steps);
2973 if(cal.compare(item.startTime, minTime) == 1){
2974 item.startTime = minTime;
2975 }
2976 } else {
2977 minTime = cal.add(item.startTime, unit, steps);
2978 if(cal.compare(item.endTime, minTime) == -1){
2979 item.endTime = minTime;
2980 }
2981 }
2982 },
2983
2984 // doubleTapDelay: Integer
2985 // The maximum delay between two taps needed to trigger an "itemDoubleClick" event, in touch context.
2986 doubleTapDelay: 300,
2987
2988 // snapUnit: String
2989 // The unit of the snapping to apply during the editing of an event.
2990 // "day", "hour" and "minute" are valid values.
2991 snapUnit: "minute",
2992
2993 // snapSteps: Integer
2994 // The number of units used to compute the snapping of the edited item.
2995 snapSteps: 15,
2996
2997 // minDurationUnit: "String"
2998 // The unit used to define the minimal duration of the edited item.
2999 // "day", "hour" and "minute" are valid values.
3000 minDurationUnit: "hour",
3001
3002 // minDurationSteps: Integer
3003 // The number of units used to define the minimal duration of the edited item.
3004 minDurationSteps: 1,
3005
3006 // liveLayout: Boolean
3007 // If true, all the events are laid out during the editing gesture. If false, only the edited event is laid out.
3008 liveLayout: false,
3009
3010 // stayInView: Boolean
3011 // Specifies during editing, if the item is already in view, if the item must stay in the time range defined by the view or not.
3012 stayInView: true,
3013
3014 // allowStartEndSwap: Boolean
3015 // Specifies if the start and end time of an item can be swapped during an editing gesture. Note that using the keyboard this property is ignored.
3016 allowStartEndSwap: true,
3017
3018 // allowResizeLessThan24H: Boolean
3019 // If an event has a duration greater than 24 hours, indicates if using a resize gesture, it can be resized to last less than 24 hours.
3020 // This flag is usually used when two different kind of renderers are used (MatrixView) to prevent changing the kind of renderer during an editing gesture.
3021 allowResizeLessThan24H: false,
3022
3023 // allowSubColumnMove: Boolean
3024 // If several sub columns are displayed, indicated if the data item can be reassigned to another sub column by an editing gesture.
3025 allowSubColumnMove: true
3026
3027 });
3028 });