Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / grid / ViewDropZone.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.define('Ext.grid.ViewDropZone', {
16     extend: 'Ext.view.DropZone',
17
18     indicatorHtml: '<div class="x-grid-drop-indicator-left"></div><div class="x-grid-drop-indicator-right"></div>',
19     indicatorCls: 'x-grid-drop-indicator',
20
21     handleNodeDrop : function(data, record, position) {
22         var view = this.view,
23             store = view.getStore(),
24             index, records, i, len;
25
26         // If the copy flag is set, create a copy of the Models with the same IDs
27         if (data.copy) {
28             records = data.records;
29             data.records = [];
30             for (i = 0, len = records.length; i < len; i++) {
31                 data.records.push(records[i].copy(records[i].getId()));
32             }
33         } else {
34             /*
35              * Remove from the source store. We do this regardless of whether the store
36              * is the same bacsue the store currently doesn't handle moving records
37              * within the store. In the future it should be possible to do this.
38              * Here was pass the isMove parameter if we're moving to the same view.
39              */
40             data.view.store.remove(data.records, data.view === view);
41         }
42
43         index = store.indexOf(record);
44
45         // 'after', or undefined (meaning a drop at index -1 on an empty View)...
46         if (position !== 'before') {
47             index++;
48         }
49         store.insert(index, data.records);
50         view.getSelectionModel().select(data.records);
51     }
52 });