]>
git.proxmox.com Git - extjs.git/blob - extjs/packages/ux/classic/src/DataView/Draggable.js
2 * ## Basic DataView with Draggable mixin.
4 * Ext.Loader.setPath('Ext.ux', '../../../SDK/extjs/examples/ux');
6 * Ext.define('My.cool.View', {
7 * extend: 'Ext.view.View',
10 * draggable: 'Ext.ux.DataView.Draggable'
13 * initComponent: function() {
14 * this.mixins.draggable.init(this, {
16 * ddGroup: 'someGroup'
20 * this.callParent(arguments);
24 * Ext.onReady(function () {
25 * Ext.create('Ext.data.Store', {
26 * storeId: 'baseball',
27 * fields: ['team', 'established'],
29 * { team: 'Atlanta Braves', established: '1871' },
30 * { team: 'Miami Marlins', established: '1993' },
31 * { team: 'New York Mets', established: '1962' },
32 * { team: 'Philadelphia Phillies', established: '1883' },
33 * { team: 'Washington Nationals', established: '1969' }
37 * Ext.create('My.cool.View', {
38 * store: Ext.StoreMgr.get('baseball'),
42 * 'The {team} were founded in {established}.',
46 * itemSelector: 'p.team',
47 * renderTo: Ext.getBody()
51 Ext
.define('Ext.ux.DataView.Draggable', {
52 requires
: 'Ext.dd.DragZone',
55 * @cfg {String} ghostCls The CSS class added to the outermost element of the created ghost proxy
56 * (defaults to 'x-dataview-draggable-ghost')
58 ghostCls
: 'x-dataview-draggable-ghost',
61 * @cfg {Ext.XTemplate/Array} ghostTpl The template used in the ghost DataView
70 * @cfg {Object} ddConfig Config object that is applied to the internally created DragZone
74 * @cfg {String} ghostConfig Config object that is used to configure the internally created DataView
77 init: function(dataview
, config
) {
81 * The Ext.view.View instance that this DragZone is attached to
83 this.dataview
= dataview
;
85 dataview
.on('render', this.onRender
, this);
88 itemSelector
: dataview
.itemSelector
,
92 Ext
.applyIf(this.ghostConfig
, {
101 * Called when the attached DataView is rendered. Sets up the internal DragZone
103 onRender: function() {
104 var config
= Ext
.apply({}, this.ddConfig
|| {}, {
106 dataview
: this.dataview
,
107 getDragData
: this.getDragData
,
108 getTreeNode
: this.getTreeNode
,
109 afterRepair
: this.afterRepair
,
110 getRepairXY
: this.getRepairXY
115 * @type Ext.dd.DragZone
116 * The attached DragZone instane
118 this.dragZone
= Ext
.create('Ext.dd.DragZone', this.dataview
.getEl(), config
);
121 getDragData: function(e
) {
122 var draggable
= this.dvDraggable
,
123 dataview
= this.dataview
,
124 selModel
= dataview
.getSelectionModel(),
125 target
= e
.getTarget(draggable
.itemSelector
),
129 if (!dataview
.isSelected(target
)) {
130 selModel
.select(dataview
.getRecord(target
));
133 selected
= dataview
.getSelectedNodes();
137 records
: selModel
.getSelection(),
141 if (selected
.length
=== 1) {
142 dragData
.single
= true;
143 dragData
.ddel
= target
;
145 dragData
.multi
= true;
146 dragData
.ddel
= draggable
.prepareGhost(selModel
.getSelection());
155 getTreeNode: function() {
156 // console.log('test');
159 afterRepair: function() {
160 this.dragging
= false;
162 var nodes
= this.dragData
.nodes
,
163 length
= nodes
.length
,
166 //FIXME: Ext.fly does not work here for some reason, only frames the last node
167 for (i
= 0; i
< length
; i
++) {
168 Ext
.get(nodes
[i
]).frame('#8db2e3', 1);
174 * Returns the x and y co-ordinates that the dragged item should be animated back to if it was dropped on an
175 * invalid drop target. If we're dragging more than one item we don't animate back and just allow afterRepair
176 * to frame each dropped item.
178 getRepairXY: function(e
) {
179 if (this.dragData
.multi
) {
182 var repairEl
= Ext
.get(this.dragData
.ddel
),
183 repairXY
= repairEl
.getXY();
185 //take the item's margins and padding into account to make the repair animation line up perfectly
186 repairXY
[0] += repairEl
.getPadding('t') + repairEl
.getMargin('t');
187 repairXY
[1] += repairEl
.getPadding('l') + repairEl
.getMargin('l');
194 * Updates the internal ghost DataView by ensuring it is rendered and contains the correct records
195 * @param {Array} records The set of records that is currently selected in the parent DataView
196 * @return {HTMLElement} The Ghost DataView's encapsulating HTMLElement.
198 prepareGhost: function(records
) {
199 return this.createGhost(records
).getEl().dom
;
204 * Creates the 'ghost' DataView that follows the mouse cursor during the drag operation. This div is usually a
205 * lighter-weight representation of just the nodes that are selected in the parent DataView.
207 createGhost: function(records
) {
212 (store
= me
.ghost
.store
).loadRecords(records
);
214 store
= Ext
.create('Ext.data.Store', {
215 model
: records
[0].self
218 store
.loadRecords(records
);
219 me
.ghost
= Ext
.create('Ext.view.View', Ext
.apply({
220 renderTo
: document
.createElement('div'),
223 me
.ghost
.container
.skipGarbageCollection
= me
.ghost
.el
.skipGarbageCollection
= true;
230 destroy: function() {
231 var ghost
= this.ghost
;
234 ghost
.container
.destroy();