3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
16 * Internal drag zone implementation for the calendar components. This provides base functionality
17 * and is primarily for the month view -- DayViewDD adds day/week view-specific functionality.
19 Ext.calendar.DragZone = Ext.extend(Ext.dd.DragZone, {
20 ddGroup: 'CalendarDD',
21 eventSelector: '.ext-cal-evt',
23 constructor: function(el, config) {
24 if (!Ext.calendar._statusProxyInstance) {
25 Ext.calendar._statusProxyInstance = new Ext.calendar.StatusProxy();
27 this.proxy = Ext.calendar._statusProxyInstance;
28 Ext.calendar.DragZone.superclass.constructor.call(this, el, config);
31 getDragData: function(e) {
32 // Check whether we are dragging on an event first
33 var t = e.getTarget(this.eventSelector, 3);
35 var rec = this.view.getEventRecordFromEl(t);
39 eventStart: rec.data[Ext.calendar.EventMappings.StartDate.name],
40 eventEnd: rec.data[Ext.calendar.EventMappings.EndDate.name],
45 // If not dragging an event then we are dragging on
46 // the calendar to add a new event
47 t = this.view.getDayAt(e.getPageX(), e.getPageY());
58 onInitDrag: function(x, y) {
59 if (this.dragData.ddel) {
60 var ghost = this.dragData.ddel.cloneNode(true),
61 child = Ext.fly(ghost).child('dl');
63 Ext.fly(ghost).setWidth('auto');
67 child.setHeight('auto');
69 this.proxy.update(ghost);
70 this.onStartDrag(x, y);
72 else if (this.dragData.start) {
73 this.onStartDrag(x, y);
75 this.view.onInitDrag();
79 afterRepair: function() {
80 if (Ext.enableFx && this.dragData.ddel) {
81 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || 'c3daf9');
83 this.dragging = false;
86 getRepairXY: function(e) {
87 if (this.dragData.ddel) {
88 return Ext.Element.fly(this.dragData.ddel).getXY();
92 afterInvalidDrop: function(e, id) {
93 Ext.select('.ext-dd-shim').hide();
98 * Internal drop zone implementation for the calendar components. This provides base functionality
99 * and is primarily for the month view -- DayViewDD adds day/week view-specific functionality.
101 Ext.calendar.DropZone = Ext.extend(Ext.dd.DropZone, {
102 ddGroup: 'CalendarDD',
103 eventSelector: '.ext-cal-evt',
108 getTargetFromEvent: function(e) {
109 var dragOffset = this.dragOffset || 0,
110 y = e.getPageY() - dragOffset,
111 d = this.view.getDayAt(e.getPageX(), y);
113 return d.el ? d: null;
116 onNodeOver: function(n, dd, e, data) {
117 var D = Ext.calendar.Date,
118 start = data.type == 'eventdrag' ? n.date: D.min(data.start, n.date),
119 end = data.type == 'eventdrag' ? n.date.add(Date.DAY, D.diffDays(data.eventStart, data.eventEnd)) :
120 D.max(data.start, n.date);
122 if (!this.dragStartDate || !this.dragEndDate || (D.diffDays(start, this.dragStartDate) != 0) || (D.diffDays(end, this.dragEndDate) != 0)) {
123 this.dragStartDate = start;
124 this.dragEndDate = end.clearTime().add(Date.DAY, 1).add(Date.MILLI, -1);
125 this.shim(start, end);
127 var range = start.format('n/j');
128 if (D.diffDays(start, end) > 0) {
129 range += '-' + end.format('n/j');
131 var msg = String.format(data.type == 'eventdrag' ? this.moveText: this.createText, range);
132 data.proxy.updateMsg(msg);
134 return this.dropAllowed;
137 shim: function(start, end) {
139 var dt = start.clone(),
143 cnt = Ext.calendar.Date.diffDays(dt, end) + 1;
148 shim.isActive = false;
154 var dayEl = this.view.getDayEl(dt);
156 // if the date is not in the current view ignore it (this
157 // can happen when an event is dragged to the end of the
158 // month so that it ends outside the view)
160 var wk = this.view.getWeekIndex(dt);
161 shim = this.shims[wk];
164 shim = this.createShim();
165 this.shims[wk] = shim;
167 if (wk != this.currWeek) {
168 shim.boxInfo = dayEl.getBox();
172 box = dayEl.getBox();
173 shim.boxInfo.right = box.right;
174 shim.boxInfo.width = box.right - shim.boxInfo.x;
176 shim.isActive = true;
178 dt = dt.add(Date.DAY, 1);
186 shim.setBox(shim.boxInfo);
188 else if (shim.isVisible()) {
195 createShim: function() {
197 this.shimCt = Ext.get('ext-dd-shim-ct');
199 this.shimCt = document.createElement('div');
200 this.shimCt.id = 'ext-dd-shim-ct';
201 Ext.getBody().appendChild(this.shimCt);
204 var el = document.createElement('div');
205 el.className = 'ext-dd-shim';
206 this.shimCt.appendChild(el);
208 return new Ext.Layer({
216 clearShims: function() {
225 onContainerOver: function(dd, e, data) {
226 return this.dropAllowed;
229 onCalendarDragComplete: function() {
230 delete this.dragStartDate;
231 delete this.dragEndDate;
235 onNodeDrop: function(n, dd, e, data) {
237 if (data.type == 'eventdrag') {
238 var rec = this.view.getEventRecordFromEl(data.ddel),
239 dt = Ext.calendar.Date.copyTime(rec.data[Ext.calendar.EventMappings.StartDate.name], n.date);
241 this.view.onEventDrop(rec, dt);
242 this.onCalendarDragComplete();
245 if (data.type == 'caldrag') {
246 this.view.onCalendarEndDrag(this.dragStartDate, this.dragEndDate,
247 this.onCalendarDragComplete.createDelegate(this));
248 //shims are NOT cleared here -- they stay visible until the handling
249 //code calls the onCalendarDragComplete callback which hides them.
253 this.onCalendarDragComplete();
257 onContainerDrop: function(dd, e, data) {
258 this.onCalendarDragComplete();
262 destroy: function() {
263 Ext.calendar.DropZone.superclass.destroy.call(this);
264 Ext.destroy(this.shimCt);