Debian Codegraph @

dojox/grid/enhanced/plugins/GridSource.js

raw symbols SCIP
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 // summary:
21 // A special source that can accept grid contents.
22 // Only for non-grid widgets or domNodes.
23 accept: ["grid/cells", "grid/rows", "grid/cols", "text"],
24
25 // insertNodesForGrid:
26 // If you'd like to insert some sort of nodes into your dnd source, turn this on,
27 // and override getCellContent/getRowContent/getColumnContent
28 // to populate the dnd data in your desired format.
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 // summary:
98 // Fill node innerHTML for dnd grid cells.
99 // example:
100 // | var cells = grid.layout.cells;
101 // | var store = grid.store;
102 // | var cache = grid._by_idx;
103 // | var res = "Grid Cells from " + grid.id + ":<br/>";
104 // | for(var r = leftTopCell.row; r <= rightBottomCell.row; ++r){
105 // | for(var c = leftTopCell.col; c <= rightBottomCell.col; ++c){
106 // | res += store.getValue(cache[r].item, cells[c].field) + ", ";
107 // | }
108 // | res = res.substring(0, res.length - 2) + ";<br/>";
109 // | }
110 // | return res;
111 },
112 getRowContent: function(grid, rowIndexes){
113 // summary:
114 // Fill node innerHTML for dnd grid rows.
115 // example:
116 // | var cells = grid.layout.cells;
117 // | var store = grid.store;
118 // | var cache = grid._by_idx;
119 // | var res = "Grid Rows from " + grid.id + ":<br/>";
120 // | for(var i = 0; i < rowIndexes.length; ++i){
121 // | var r = rowIndexes[i];
122 // | res += "Row " + r + ": ";
123 // | for(var j = 0; j < cells.length; ++j){
124 // | if(!cells[j].hidden){
125 // | res += store.getValue(cache[r].item, cells[j].field) + ", ";
126 // | }
127 // | }
128 // | res = res.substring(0, res.length - 2) + ";<br/>";
129 // | }
130 // | return res;
131 },
132 getColumnContent: function(grid, colIndexes){
133 // summary:
134 // Fill node innerHTML for dnd grid columns.
135 // example:
136 // | var cells = grid.layout.cells;
137 // | var res = "Grid Columns from " + grid.id + ":";
138 // | for(var i = 0; i < colIndexes.length; ++i){
139 // | var c = colIndexes[i];
140 // | res += (cells[c].name || cells[c].field) + ", ";
141 // | }
142 // | return res.substring(0, res.length - 2);
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 });