]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * Internal class that manages drag/drop for the `Dashboard`.\r | |
3 | * @private\r | |
4 | */\r | |
5 | Ext.define('Ext.dashboard.DropZone', {\r | |
6 | extend: 'Ext.dd.DropTarget',\r | |
7 | \r | |
8 | ddScrollConfig: {\r | |
9 | vthresh: 75,\r | |
10 | hthresh: -1,\r | |
11 | animate: true,\r | |
12 | increment: 200\r | |
13 | },\r | |
14 | \r | |
15 | containerScroll: true,\r | |
16 | \r | |
17 | // This causes overflow to go hidden during the drag so that we don't cause panels to\r | |
18 | // wrap by triggering overflow.\r | |
19 | overClass: Ext.baseCSSPrefix + 'dashboard-dd-over',\r | |
20 | \r | |
21 | constructor: function (dashboard, cfg) {\r | |
22 | this.dashboard = dashboard;\r | |
23 | dashboard.body.ddScrollConfig = this.ddScrollConfig;\r | |
24 | \r | |
25 | this.callParent([dashboard.body, cfg]);\r | |
26 | },\r | |
27 | \r | |
28 | getOverEvent: function (dd, e, data) {\r | |
29 | var dashboard = this.dashboard,\r | |
30 | dbody = dashboard.body,\r | |
31 | items = dashboard.items.items,\r | |
32 | bodyBox = dbody.getBox(),\r | |
33 | count = items.length,\r | |
34 | xy = e.getXY(),\r | |
35 | x = xy[0] - bodyBox.x + dbody.getScrollLeft(),\r | |
36 | y = xy[1] - bodyBox.y + dbody.getScrollTop(),\r | |
37 | over = {\r | |
38 | columnIndex: 0,\r | |
39 | column: null,\r | |
40 | dashboard: dashboard,\r | |
41 | above: null,\r | |
42 | extensible : false,\r | |
43 | beforeAfter : 0,\r | |
44 | data: data,\r | |
45 | panel: data.panel,\r | |
46 | rawEvent: e,\r | |
47 | source: dd,\r | |
48 | status: this.dropAllowed\r | |
49 | },\r | |
50 | t, ht, i, k, item, w, childCount, childItems, childItem;\r | |
51 | \r | |
52 | for (i = 0; i < count; i += 2) {\r | |
53 | item = items[i];\r | |
54 | w = item.lastBox.width;\r | |
55 | if (items[i+1]) {\r | |
56 | w += items[i+1].lastBox.width;\r | |
57 | }\r | |
58 | \r | |
59 | //if (x < w) {\r | |
60 | if (e.within(item.el)) {\r | |
61 | over.columnIndex = i;\r | |
62 | over.column = item;\r | |
63 | over.extensible = this.isRowExtensible(item.rowIndex);\r | |
64 | \r | |
65 | t = Math.min(80, w * 0.2);\r | |
66 | over.beforeAfter = t = (over.extensible && ((x < t) ? -1 : ((x > w - t) ? 1 : 0)));\r | |
67 | \r | |
68 | if (!t || !over.extensible) {\r | |
69 | childItems = item.items.items;\r | |
70 | // if we are not on an edge OR reached maxColumns (which means "insert the panel in\r | |
71 | // between the columns"), we need to dig one more level down\r | |
72 | //console.log('inside of column ' + i + ': x=' + x + ', y=' + y);\r | |
73 | for (k = 0, childCount = childItems.length; k < childCount; ++k) {\r | |
74 | childItem = childItems[k];\r | |
75 | ht = childItem.el.getHeight();\r | |
76 | //console.log(childItem.id + '.ht = ' + ht);\r | |
77 | if (y < ht / 2) {\r | |
78 | //console.log('above child ' + k);\r | |
79 | // if mouse is above the current child's top, Y coord, it\r | |
80 | // is considered as "above" the previous child\r | |
81 | over.above = childItem;\r | |
82 | break;\r | |
83 | }\r | |
84 | //console.log('below child ' + k);\r | |
85 | y -= ht;\r | |
86 | }\r | |
87 | \r | |
88 | }\r | |
89 | \r | |
90 | break;\r | |
91 | }\r | |
92 | \r | |
93 | x -= w;\r | |
94 | }\r | |
95 | \r | |
96 | return over;\r | |
97 | },\r | |
98 | \r | |
99 | notifyOver: function (dd, e, data) {\r | |
100 | var me = this,\r | |
101 | dashboard = me.dashboard,\r | |
102 | over = me.getOverEvent(dd, e, data),\r | |
103 | colEl = over.column && over.column.el,\r | |
104 | proxy = dd.proxy,\r | |
105 | proxyProxy,\r | |
106 | aboveItem = over.above,\r | |
107 | colWidth, width = 0,\r | |
108 | padding,\r | |
109 | hasListeners = dashboard.hasListeners;\r | |
110 | \r | |
111 | data.lastOver = over;\r | |
112 | \r | |
113 | if ((!hasListeners.validatedrop || dashboard.fireEvent('validatedrop', over) !== false) &&\r | |
114 | (!hasListeners.beforedragover || dashboard.fireEvent('beforedragover', over) !== false ))\r | |
115 | {\r | |
116 | \r | |
117 | proxyProxy = dd.panelProxy.getProxy();\r | |
118 | \r | |
119 | // make sure proxy width is fluid in different width columns\r | |
120 | proxy.getProxy().setWidth('auto');\r | |
121 | \r | |
122 | if ( colEl) {\r | |
123 | \r | |
124 | width = colWidth = colEl.getWidth();\r | |
125 | // A floating column was targeted\r | |
126 | if (over.beforeAfter) {\r | |
127 | \r | |
128 | dd.panelProxy.moveProxy(colEl.dom, colEl.dom.firstChild);\r | |
129 | \r | |
130 | width = colWidth / 2;\r | |
131 | proxyProxy.setWidth(width);\r | |
132 | \r | |
133 | } else {\r | |
134 | if (aboveItem) {\r | |
135 | dd.panelProxy.moveProxy(aboveItem.el.dom.parentNode, aboveItem.el.dom);\r | |
136 | } else {\r | |
137 | dd.panelProxy.moveProxy(colEl.dom, null);\r | |
138 | }\r | |
139 | proxyProxy.setWidth('auto');\r | |
140 | \r | |
141 | }\r | |
142 | if (width) {\r | |
143 | //proxy.getProxy().setWidth(width);\r | |
144 | }\r | |
145 | proxyProxy.setStyle({\r | |
146 | 'float': 'none',\r | |
147 | 'clear' : 'none',\r | |
148 | 'margin-left': (over.beforeAfter > 0) ? (colWidth - width - colEl.getPadding('lr')) + 'px' : '',\r | |
149 | 'margin-top' : '7px'\r | |
150 | });\r | |
151 | \r | |
152 | } else {\r | |
153 | padding = dashboard.body.getPadding('lr');\r | |
154 | proxyProxy.setStyle({\r | |
155 | 'float' : 'left',\r | |
156 | 'clear' : 'left',\r | |
157 | 'margin': '0 7px 0 7px'\r | |
158 | });\r | |
159 | proxyProxy.setWidth(dashboard.body.getWidth() - padding);\r | |
160 | \r | |
161 | // Target the innerCt for the move\r | |
162 | dd.panelProxy.moveProxy(dashboard.body.dom.firstChild.firstChild, null);\r | |
163 | }\r | |
164 | \r | |
165 | this.scrollPos = dashboard.body.getScroll();\r | |
166 | \r | |
167 | if (hasListeners.dragover) {\r | |
168 | dashboard.fireEvent('dragover', over);\r | |
169 | }\r | |
170 | }\r | |
171 | \r | |
172 | return over.status;\r | |
173 | },\r | |
174 | \r | |
175 | isRowExtensible : function(rowIndex) {\r | |
176 | var me = this,\r | |
177 | dashboard = me.dashboard,\r | |
178 | maxColumns = dashboard.getMaxColumns() || 1;\r | |
179 | \r | |
180 | return Ext.Array.from(dashboard.query('>dashboard-column[rowIndex=' + rowIndex + ']')).length < maxColumns;\r | |
181 | },\r | |
182 | \r | |
183 | notifyDrop: function (dd, e, data) {\r | |
184 | this.callParent(arguments);\r | |
185 | \r | |
186 | var dashboard = this.dashboard,\r | |
187 | over = data.lastOver,\r | |
188 | panel = over.panel,\r | |
189 | fromCt = panel.ownerCt,\r | |
190 | toCt = over.column,\r | |
191 | side = toCt ? over.beforeAfter : 1,\r | |
192 | currentIndex = fromCt.items.indexOf(panel),\r | |
193 | newIndex = toCt ? (over.above ? toCt.items.indexOf(over.above) : toCt.items.getCount()) : 0,\r | |
194 | colIndex, newCol,\r | |
195 | hasListeners = dashboard.hasListeners;\r | |
196 | \r | |
197 | // console.log('DROP: ' + panel.id + '@' + currentIndex +\r | |
198 | // // ' from ' + fromCt.id +\r | |
199 | // (side ? ((side < 0) ? ' BEFORE ' : ' AFTER ')\r | |
200 | // : (' AT ' + newIndex + ' IN ')) + toCt.id +\r | |
201 | // (over.above ? ' ABOVE ' + over.above.id : ' AT END'));\r | |
202 | \r | |
203 | //Same column tests\r | |
204 | if (fromCt === toCt) {\r | |
205 | if (fromCt.items.getCount() === 1) {\r | |
206 | //console.log('Null op');\r | |
207 | return;\r | |
208 | }\r | |
209 | if (!side) {\r | |
210 | if (currentIndex < newIndex) {\r | |
211 | --newIndex;\r | |
212 | //console.log('Adjusted newIndex=' + newIndex);\r | |
213 | }\r | |
214 | if (currentIndex === newIndex) {\r | |
215 | //console.log('No change');\r | |
216 | return;\r | |
217 | }\r | |
218 | }\r | |
219 | }\r | |
220 | \r | |
221 | if ((hasListeners.validatedrop && dashboard.fireEvent('validatedrop', over) === false) ||\r | |
222 | (hasListeners.beforedrop && dashboard.fireEvent('beforedrop', over) === false)) {\r | |
223 | return;\r | |
224 | }\r | |
225 | \r | |
226 | Ext.suspendLayouts();\r | |
227 | \r | |
228 | panel.isMoving = true;\r | |
229 | if (side) {\r | |
230 | colIndex = dashboard.items.indexOf(toCt);\r | |
231 | \r | |
232 | // inserting into new Row ?\r | |
233 | if (colIndex < 0) {\r | |
234 | colIndex = dashboard.items.getCount();\r | |
235 | } else if (side > 0) {\r | |
236 | ++colIndex;\r | |
237 | }\r | |
238 | \r | |
239 | newCol = dashboard.createColumn();\r | |
240 | \r | |
241 | if (toCt) {\r | |
242 | newCol.columnWidth = toCt.columnWidth = toCt.columnWidth / 2;\r | |
243 | delete toCt.width;\r | |
244 | } else {\r | |
245 | newCol.columnWidth = 1; //full row\r | |
246 | }\r | |
247 | \r | |
248 | toCt = dashboard.insert(colIndex, newCol);\r | |
249 | newIndex = 0;\r | |
250 | }\r | |
251 | \r | |
252 | // make sure panel is visible prior to inserting so the layout doesn't ignore it\r | |
253 | panel.el.dom.style.display = '';\r | |
254 | \r | |
255 | toCt.insert(newIndex, panel);\r | |
256 | \r | |
257 | panel.isMoving = false;\r | |
258 | \r | |
259 | toCt.updateLayout();\r | |
260 | Ext.resumeLayouts(true);\r | |
261 | \r | |
262 | if (hasListeners.drop) {\r | |
263 | dashboard.fireEvent('drop', over);\r | |
264 | }\r | |
265 | }\r | |
266 | });\r |