3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * Internal drag zone implementation for the calendar components. This provides base functionality
9 * and is primarily for the month view -- DayViewDD adds day/week view-specific functionality.
11 Ext.calendar.DragZone = Ext.extend(Ext.dd.DragZone, {
12 ddGroup: 'CalendarDD',
13 eventSelector: '.ext-cal-evt',
15 constructor: function(el, config) {
16 if (!Ext.calendar._statusProxyInstance) {
17 Ext.calendar._statusProxyInstance = new Ext.calendar.StatusProxy();
19 this.proxy = Ext.calendar._statusProxyInstance;
20 Ext.calendar.DragZone.superclass.constructor.call(this, el, config);
23 getDragData: function(e) {
24 // Check whether we are dragging on an event first
25 var t = e.getTarget(this.eventSelector, 3);
27 var rec = this.view.getEventRecordFromEl(t);
31 eventStart: rec.data[Ext.calendar.EventMappings.StartDate.name],
32 eventEnd: rec.data[Ext.calendar.EventMappings.EndDate.name],
37 // If not dragging an event then we are dragging on
38 // the calendar to add a new event
39 t = this.view.getDayAt(e.getPageX(), e.getPageY());
50 onInitDrag: function(x, y) {
51 if (this.dragData.ddel) {
52 var ghost = this.dragData.ddel.cloneNode(true),
53 child = Ext.fly(ghost).child('dl');
55 Ext.fly(ghost).setWidth('auto');
59 child.setHeight('auto');
61 this.proxy.update(ghost);
62 this.onStartDrag(x, y);
64 else if (this.dragData.start) {
65 this.onStartDrag(x, y);
67 this.view.onInitDrag();
71 afterRepair: function() {
72 if (Ext.enableFx && this.dragData.ddel) {
73 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || 'c3daf9');
75 this.dragging = false;
78 getRepairXY: function(e) {
79 if (this.dragData.ddel) {
80 return Ext.Element.fly(this.dragData.ddel).getXY();
84 afterInvalidDrop: function(e, id) {
85 Ext.select('.ext-dd-shim').hide();
90 * Internal drop zone implementation for the calendar components. This provides base functionality
91 * and is primarily for the month view -- DayViewDD adds day/week view-specific functionality.
93 Ext.calendar.DropZone = Ext.extend(Ext.dd.DropZone, {
94 ddGroup: 'CalendarDD',
95 eventSelector: '.ext-cal-evt',
100 getTargetFromEvent: function(e) {
101 var dragOffset = this.dragOffset || 0,
102 y = e.getPageY() - dragOffset,
103 d = this.view.getDayAt(e.getPageX(), y);
105 return d.el ? d: null;
108 onNodeOver: function(n, dd, e, data) {
109 var D = Ext.calendar.Date,
110 start = data.type == 'eventdrag' ? n.date: D.min(data.start, n.date),
111 end = data.type == 'eventdrag' ? n.date.add(Date.DAY, D.diffDays(data.eventStart, data.eventEnd)) :
112 D.max(data.start, n.date);
114 if (!this.dragStartDate || !this.dragEndDate || (D.diffDays(start, this.dragStartDate) != 0) || (D.diffDays(end, this.dragEndDate) != 0)) {
115 this.dragStartDate = start;
116 this.dragEndDate = end.clearTime().add(Date.DAY, 1).add(Date.MILLI, -1);
117 this.shim(start, end);
119 var range = start.format('n/j');
120 if (D.diffDays(start, end) > 0) {
121 range += '-' + end.format('n/j');
123 var msg = String.format(data.type == 'eventdrag' ? this.moveText: this.createText, range);
124 data.proxy.updateMsg(msg);
126 return this.dropAllowed;
129 shim: function(start, end) {
131 var dt = start.clone(),
135 cnt = Ext.calendar.Date.diffDays(dt, end) + 1;
140 shim.isActive = false;
146 var dayEl = this.view.getDayEl(dt);
148 // if the date is not in the current view ignore it (this
149 // can happen when an event is dragged to the end of the
150 // month so that it ends outside the view)
152 var wk = this.view.getWeekIndex(dt);
153 shim = this.shims[wk];
156 shim = this.createShim();
157 this.shims[wk] = shim;
159 if (wk != this.currWeek) {
160 shim.boxInfo = dayEl.getBox();
164 box = dayEl.getBox();
165 shim.boxInfo.right = box.right;
166 shim.boxInfo.width = box.right - shim.boxInfo.x;
168 shim.isActive = true;
170 dt = dt.add(Date.DAY, 1);
178 shim.setBox(shim.boxInfo);
180 else if (shim.isVisible()) {
187 createShim: function() {
189 this.shimCt = Ext.get('ext-dd-shim-ct');
191 this.shimCt = document.createElement('div');
192 this.shimCt.id = 'ext-dd-shim-ct';
193 Ext.getBody().appendChild(this.shimCt);
196 var el = document.createElement('div');
197 el.className = 'ext-dd-shim';
198 this.shimCt.appendChild(el);
200 return new Ext.Layer({
208 clearShims: function() {
217 onContainerOver: function(dd, e, data) {
218 return this.dropAllowed;
221 onCalendarDragComplete: function() {
222 delete this.dragStartDate;
223 delete this.dragEndDate;
227 onNodeDrop: function(n, dd, e, data) {
229 if (data.type == 'eventdrag') {
230 var rec = this.view.getEventRecordFromEl(data.ddel),
231 dt = Ext.calendar.Date.copyTime(rec.data[Ext.calendar.EventMappings.StartDate.name], n.date);
233 this.view.onEventDrop(rec, dt);
234 this.onCalendarDragComplete();
237 if (data.type == 'caldrag') {
238 this.view.onCalendarEndDrag(this.dragStartDate, this.dragEndDate,
239 this.onCalendarDragComplete.createDelegate(this));
240 //shims are NOT cleared here -- they stay visible until the handling
241 //code calls the onCalendarDragComplete callback which hides them.
245 this.onCalendarDragComplete();
249 onContainerDrop: function(dd, e, data) {
250 this.onCalendarDragComplete();
254 destroy: function() {
255 Ext.calendar.DropZone.superclass.destroy.call(this);
256 Ext.destroy(this.shimCt);