| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/dnd/Source", |
| 6 |
"./DnD" |
| 7 |
], function(declare, array, lang, Source, DnD){ |
| 8 |
|
| 9 |
var _joinToArray = function(arrays){ |
| 10 |
var a = arrays[0]; |
| 11 |
for(var i = 1; i < arrays.length; ++i){ |
| 12 |
a = a.concat(arrays[i]); |
| 13 |
} |
| 14 |
return a; |
| 15 |
}; |
| 16 |
|
| 17 |
var GridDnDSource = lang.getObject("dojox.grid.enhanced.plugins.GridDnDSource"); |
| 18 |
|
| 19 |
return declare("dojox.grid.enhanced.plugins.GridSource", Source, { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
accept: ["grid/cells", "grid/rows", "grid/cols", "text"], |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
insertNodesForGrid: false, |
| 30 |
|
| 31 |
markupFactory: function(params, node){ |
| 32 |
cls = lang.getObject("dojox.grid.enhanced.plugins.GridSource"); |
| 33 |
return new cls(node, params); |
| 34 |
}, |
| 35 |
checkAcceptance: function(source, nodes){ |
| 36 |
if(source instanceof GridDnDSource){ |
| 37 |
if(nodes[0]){ |
| 38 |
var item = source.getItem(nodes[0].id); |
| 39 |
if(item && (array.indexOf(item.type, "grid/rows") >= 0 || array.indexOf(item.type, "grid/cells") >= 0) && |
| 40 |
!source.dndPlugin._allDnDItemsLoaded()){ |
| 41 |
return false; |
| 42 |
} |
| 43 |
} |
| 44 |
this.sourcePlugin = source.dndPlugin; |
| 45 |
} |
| 46 |
return this.inherited(arguments); |
| 47 |
}, |
| 48 |
onDraggingOver: function(){ |
| 49 |
if(this.sourcePlugin){ |
| 50 |
this.sourcePlugin._isSource = true; |
| 51 |
} |
| 52 |
}, |
| 53 |
onDraggingOut: function(){ |
| 54 |
if(this.sourcePlugin){ |
| 55 |
this.sourcePlugin._isSource = false; |
| 56 |
} |
| 57 |
}, |
| 58 |
onDropExternal: function(source, nodes, copy){ |
| 59 |
if(source instanceof GridDnDSource){ |
| 60 |
var ranges = array.map(nodes, function(node){ |
| 61 |
return source.getItem(node.id).data; |
| 62 |
}); |
| 63 |
var item = source.getItem(nodes[0].id); |
| 64 |
var grid = item.dndPlugin.grid; |
| 65 |
var type = item.type[0]; |
| 66 |
var range; |
| 67 |
try{ |
| 68 |
switch(type){ |
| 69 |
case "grid/cells": |
| 70 |
nodes[0].innerHTML = this.getCellContent(grid, ranges[0].min, ranges[0].max) || ""; |
| 71 |
this.onDropGridCells(grid, ranges[0].min, ranges[0].max); |
| 72 |
break; |
| 73 |
case "grid/rows": |
| 74 |
range = _joinToArray(ranges); |
| 75 |
nodes[0].innerHTML = this.getRowContent(grid, range) || ""; |
| 76 |
this.onDropGridRows(grid, range); |
| 77 |
break; |
| 78 |
case "grid/cols": |
| 79 |
range = _joinToArray(ranges); |
| 80 |
nodes[0].innerHTML = this.getColumnContent(grid, range) || ""; |
| 81 |
this.onDropGridColumns(grid, range); |
| 82 |
break; |
| 83 |
} |
| 84 |
if(this.insertNodesForGrid){ |
| 85 |
this.selectNone(); |
| 86 |
this.insertNodes(true, [nodes[0]], this.before, this.current); |
| 87 |
} |
| 88 |
item.dndPlugin.onDragOut(!copy); |
| 89 |
}catch(e){ |
| 90 |
console.warn("GridSource.onDropExternal() error:",e); |
| 91 |
} |
| 92 |
}else{ |
| 93 |
this.inherited(arguments); |
| 94 |
} |
| 95 |
}, |
| 96 |
getCellContent: function(grid, leftTopCell, rightBottomCell){ |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
}, |
| 112 |
getRowContent: function(grid, rowIndexes){ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
}, |
| 132 |
getColumnContent: function(grid, colIndexes){ |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
}, |
| 144 |
onDropGridCells: function(grid, leftTopCell, rightBottomCell){ |
| 145 |
|
| 146 |
}, |
| 147 |
onDropGridRows: function(grid, rowIndexes){ |
| 148 |
|
| 149 |
}, |
| 150 |
onDropGridColumns: function(grid, colIndexes){ |
| 151 |
|
| 152 |
} |
| 153 |
}); |
| 154 |
}); |