2 * @class Ext.ux.DataView.Draggable
7 Ext.create('Ext.view.View', {
9 draggable: 'Ext.ux.DataView.Draggable'
12 initComponent: function() {
13 this.mixins.draggable.init(this, {
19 this.callParent(arguments);
25 Ext.define('Ext.ux.DataView.Draggable', {
26 requires: 'Ext.dd.DragZone',
29 * @cfg {String} ghostCls The CSS class added to the outermost element of the created ghost proxy
30 * (defaults to 'x-dataview-draggable-ghost')
32 ghostCls: 'x-dataview-draggable-ghost',
35 * @cfg {Ext.XTemplate/Array} ghostTpl The template used in the ghost DataView
44 * @cfg {Object} ddConfig Config object that is applied to the internally created DragZone
48 * @cfg {String} ghostConfig Config object that is used to configure the internally created DataView
51 init: function(dataview, config) {
55 * The Ext.view.View instance that this DragZone is attached to
57 this.dataview = dataview;
59 dataview.on('render', this.onRender, this);
62 itemSelector: dataview.itemSelector,
66 Ext.applyIf(this.ghostConfig, {
75 * Called when the attached DataView is rendered. Sets up the internal DragZone
77 onRender: function() {
78 var config = Ext.apply({}, this.ddConfig || {}, {
80 dataview : this.dataview,
81 getDragData: this.getDragData,
82 getTreeNode: this.getTreeNode,
83 afterRepair: this.afterRepair,
84 getRepairXY: this.getRepairXY
89 * @type Ext.dd.DragZone
90 * The attached DragZone instane
92 this.dragZone = Ext.create('Ext.dd.DragZone', this.dataview.getEl(), config);
95 getDragData: function(e) {
96 var draggable = this.dvDraggable,
97 dataview = this.dataview,
98 selModel = dataview.getSelectionModel(),
99 target = e.getTarget(draggable.itemSelector),
103 if (!dataview.isSelected(target)) {
104 selModel.select(dataview.getRecord(target));
107 selected = dataview.getSelectedNodes();
111 records: selModel.getSelection(),
115 if (selected.length == 1) {
116 dragData.single = true;
117 dragData.ddel = target;
119 dragData.multi = true;
120 dragData.ddel = draggable.prepareGhost(selModel.getSelection()).dom;
129 getTreeNode: function() {
133 afterRepair: function() {
134 this.dragging = false;
136 var nodes = this.dragData.nodes,
137 length = nodes.length,
140 //FIXME: Ext.fly does not work here for some reason, only frames the last node
141 for (i = 0; i < length; i++) {
142 Ext.get(nodes[i]).frame('#8db2e3', 1);
148 * Returns the x and y co-ordinates that the dragged item should be animated back to if it was dropped on an
149 * invalid drop target. If we're dragging more than one item we don't animate back and just allow afterRepair
150 * to frame each dropped item.
152 getRepairXY: function(e) {
153 if (this.dragData.multi) {
156 var repairEl = Ext.get(this.dragData.ddel),
157 repairXY = repairEl.getXY();
159 //take the item's margins and padding into account to make the repair animation line up perfectly
160 repairXY[0] += repairEl.getPadding('t') + repairEl.getMargin('t');
161 repairXY[1] += repairEl.getPadding('l') + repairEl.getMargin('l');
168 * Updates the internal ghost DataView by ensuring it is rendered and contains the correct records
169 * @param {Array} records The set of records that is currently selected in the parent DataView
170 * @return {Ext.view.View} The Ghost DataView
172 prepareGhost: function(records) {
173 var ghost = this.createGhost(records),
179 return ghost.getEl();
184 * Creates the 'ghost' DataView that follows the mouse cursor during the drag operation. This div is usually a
185 * lighter-weight representation of just the nodes that are selected in the parent DataView. Delegates the creation
186 * of each selected item's element to {@link createGhostElement}
188 createGhost: function(records) {
190 var ghostConfig = Ext.apply({}, this.ghostConfig, {
191 store: Ext.create('Ext.data.Store', {
192 model: records[0].modelName
196 this.ghost = Ext.create('Ext.view.View', ghostConfig);
198 this.ghost.render(document.createElement('div'));