]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /*\r |
2 | * Internal drop zone implementation for the calendar components. This provides base functionality\r | |
3 | * and is primarily for the month view -- DayViewDD adds day/week view-specific functionality.\r | |
4 | */\r | |
5 | Ext.define('Ext.calendar.dd.DropZone', {\r | |
6 | extend: 'Ext.dd.DropZone',\r | |
7 | \r | |
8 | requires: [\r | |
9 | 'Ext.calendar.util.Date',\r | |
10 | 'Ext.calendar.data.EventMappings'\r | |
11 | ],\r | |
12 | \r | |
13 | ddGroup: 'CalendarDD',\r | |
14 | eventSelector: '.ext-cal-evt',\r | |
15 | \r | |
16 | // private\r | |
17 | shims: [],\r | |
18 | \r | |
19 | getTargetFromEvent: function(e) {\r | |
20 | var dragOffset = this.dragOffset || 0,\r | |
21 | y = e.getY() - dragOffset,\r | |
22 | d = this.view.getDayAt(e.getX(), y);\r | |
23 | \r | |
24 | return d.el ? d: null;\r | |
25 | },\r | |
26 | \r | |
27 | onNodeOver: function(n, dd, e, data) {\r | |
28 | var D = Ext.calendar.util.Date,\r | |
29 | start = data.type == 'eventdrag' ? n.date: D.min(data.start, n.date),\r | |
30 | end = data.type == 'eventdrag' ? D.add(n.date, {days: D.diffDays(data.eventStart, data.eventEnd)}) :\r | |
31 | D.max(data.start, n.date);\r | |
32 | \r | |
33 | if (!this.dragStartDate || !this.dragEndDate || (D.diffDays(start, this.dragStartDate) != 0) || (D.diffDays(end, this.dragEndDate) != 0)) {\r | |
34 | this.dragStartDate = start;\r | |
35 | this.dragEndDate = D.add(end, {days: 1, millis: -1, clearTime: true});\r | |
36 | this.shim(start, end);\r | |
37 | \r | |
38 | var range = Ext.Date.format(start, 'n/j');\r | |
39 | if (D.diffDays(start, end) > 0) {\r | |
40 | range += '-' + Ext.Date.format(end, 'n/j');\r | |
41 | }\r | |
42 | var msg = Ext.util.Format.format(data.type == 'eventdrag' ? this.moveText: this.createText, range);\r | |
43 | data.proxy.updateMsg(msg);\r | |
44 | }\r | |
45 | return this.dropAllowed;\r | |
46 | },\r | |
47 | \r | |
48 | shim: function(start, end) {\r | |
49 | this.currWeek = -1;\r | |
50 | this.DDMInstance.notifyOccluded = true;\r | |
51 | var dt = Ext.Date.clone(start),\r | |
52 | i = 0,\r | |
53 | shim,\r | |
54 | box,\r | |
55 | D = Ext.calendar.util.Date,\r | |
56 | cnt = D.diffDays(dt, end) + 1;\r | |
57 | \r | |
58 | Ext.each(this.shims,\r | |
59 | function(shim) {\r | |
60 | if (shim) {\r | |
61 | shim.isActive = false;\r | |
62 | }\r | |
63 | }\r | |
64 | );\r | |
65 | \r | |
66 | while (i++<cnt) {\r | |
67 | var dayEl = this.view.getDayEl(dt);\r | |
68 | \r | |
69 | // if the date is not in the current view ignore it (this\r | |
70 | // can happen when an event is dragged to the end of the\r | |
71 | // month so that it ends outside the view)\r | |
72 | if (dayEl) {\r | |
73 | var wk = this.view.getWeekIndex(dt);\r | |
74 | shim = this.shims[wk];\r | |
75 | \r | |
76 | if (!shim) {\r | |
77 | shim = this.createShim();\r | |
78 | this.shims[wk] = shim;\r | |
79 | }\r | |
80 | if (wk != this.currWeek) {\r | |
81 | shim.boxInfo = dayEl.getBox();\r | |
82 | this.currWeek = wk;\r | |
83 | }\r | |
84 | else {\r | |
85 | box = dayEl.getBox();\r | |
86 | shim.boxInfo.right = box.right;\r | |
87 | shim.boxInfo.width = box.right - shim.boxInfo.x;\r | |
88 | }\r | |
89 | shim.isActive = true;\r | |
90 | }\r | |
91 | dt = D.add(dt, {days: 1});\r | |
92 | }\r | |
93 | \r | |
94 | Ext.each(this.shims, function(shim) {\r | |
95 | if (shim) {\r | |
96 | if (shim.isActive) {\r | |
97 | shim.show();\r | |
98 | shim.setBox(shim.boxInfo);\r | |
99 | }\r | |
100 | else if (shim.isVisible()) {\r | |
101 | shim.hide();\r | |
102 | }\r | |
103 | }\r | |
104 | });\r | |
105 | },\r | |
106 | \r | |
107 | createShim: function() {\r | |
108 | if (!this.shimCt) {\r | |
109 | this.shimCt = Ext.get('ext-dd-shim-ct');\r | |
110 | if (!this.shimCt) {\r | |
111 | this.shimCt = document.createElement('div');\r | |
112 | this.shimCt.id = 'ext-dd-shim-ct';\r | |
113 | Ext.getBody().appendChild(this.shimCt);\r | |
114 | }\r | |
115 | }\r | |
116 | var el = document.createElement('div');\r | |
117 | el.className = 'ext-dd-shim';\r | |
118 | this.shimCt.appendChild(el);\r | |
119 | \r | |
120 | el = Ext.get(el);\r | |
121 | \r | |
122 | el.setVisibilityMode(2);\r | |
123 | \r | |
124 | return el;\r | |
125 | },\r | |
126 | \r | |
127 | clearShims: function() {\r | |
128 | Ext.each(this.shims,\r | |
129 | function(shim) {\r | |
130 | if (shim) {\r | |
131 | shim.hide();\r | |
132 | }\r | |
133 | });\r | |
134 | this.DDMInstance.notifyOccluded = false;\r | |
135 | },\r | |
136 | \r | |
137 | onContainerOver: function(dd, e, data) {\r | |
138 | return this.dropAllowed;\r | |
139 | },\r | |
140 | \r | |
141 | onCalendarDragComplete: function() {\r | |
142 | delete this.dragStartDate;\r | |
143 | delete this.dragEndDate;\r | |
144 | this.clearShims();\r | |
145 | },\r | |
146 | \r | |
147 | onNodeDrop: function(n, dd, e, data) {\r | |
148 | if (n && data) {\r | |
149 | if (data.type == 'eventdrag') {\r | |
150 | var rec = this.view.getEventRecordFromEl(data.ddel),\r | |
151 | dt = Ext.calendar.util.Date.copyTime(rec.data[Ext.calendar.data.EventMappings.StartDate.name], n.date);\r | |
152 | \r | |
153 | this.view.onEventDrop(rec, dt);\r | |
154 | this.onCalendarDragComplete();\r | |
155 | return true;\r | |
156 | }\r | |
157 | if (data.type == 'caldrag') {\r | |
158 | this.view.onCalendarEndDrag(this.dragStartDate, this.dragEndDate,\r | |
159 | Ext.bind(this.onCalendarDragComplete, this));\r | |
160 | //shims are NOT cleared here -- they stay visible until the handling\r | |
161 | //code calls the onCalendarDragComplete callback which hides them.\r | |
162 | return true;\r | |
163 | }\r | |
164 | }\r | |
165 | this.onCalendarDragComplete();\r | |
166 | return false;\r | |
167 | },\r | |
168 | \r | |
169 | onContainerDrop: function(dd, e, data) {\r | |
170 | this.onCalendarDragComplete();\r | |
171 | return false;\r | |
172 | }\r | |
173 | });\r |