Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / grid / ViewDropZone.js
1 Ext.define('Ext.grid.ViewDropZone', {
2     extend: 'Ext.view.DropZone',
3
4     indicatorHtml: '<div class="x-grid-drop-indicator-left"></div><div class="x-grid-drop-indicator-right"></div>',
5     indicatorCls: 'x-grid-drop-indicator',
6
7     handleNodeDrop : function(data, record, position) {
8         var view = this.view,
9             store = view.getStore(),
10             index, records, i, len;
11
12         // If the copy flag is set, create a copy of the Models with the same IDs
13         if (data.copy) {
14             records = data.records;
15             data.records = [];
16             for (i = 0, len = records.length; i < len; i++) {
17                 data.records.push(records[i].copy(records[i].getId()));
18             }
19         } else {
20             /*
21              * Remove from the source store. We do this regardless of whether the store
22              * is the same bacsue the store currently doesn't handle moving records
23              * within the store. In the future it should be possible to do this.
24              * Here was pass the isMove parameter if we're moving to the same view.
25              */
26             data.view.store.remove(data.records, data.view === view);
27         }
28
29         index = store.indexOf(record);
30         if (position == 'after') {
31             index++;
32         }
33         store.insert(index, data.records);
34         view.getSelectionModel().select(data.records);
35     }
36 });