Debian Codegraph @

dojox/grid/EnhancedGrid.js

raw symbols SCIP
1 define([
2 "dojo/_base/kernel",
3 "../main",
4 "dojo/_base/declare",
5 "dojo/_base/lang",
6 "dojo/_base/array",
7 "dojo/_base/sniff",
8 "dojo/dom",
9 "dojo/dom-geometry",
10 "./DataGrid",
11 "./DataSelection",
12 "./enhanced/_PluginManager",
13 "./enhanced/plugins/_SelectionPreserver",//default loaded plugin
14 "dojo/i18n!./enhanced/nls/EnhancedGrid"
15 ], function(dojo, dojox, declare, lang, array, has, dom, domGeometry,
16 DataGrid, DataSelection, _PluginManager, _SelectionPreserver, nls){
17
18 dojo.experimental("dojox.grid.EnhancedGrid");
19
20 var EnhancedGrid = declare("dojox.grid.EnhancedGrid", DataGrid, {
21 // summary:
22 // Provides enhanced features based on DataGrid
23 //
24 // description:
25 // EnhancedGrid features are implemented as plugins that could be loaded on demand.
26 // Explicit dojo.require() is needed to use these feature plugins.
27 //
28 // example:
29 // A quick sample to use EnhancedGrid features:
30 //
31 // Step 1. Load EnhancedGrid and required features
32 // | <script type="text/javascript">
33 // | dojo.require("dojox.grid.EnhancedGrid");
34 // | dojo.require("dojox.grid.enhanced.plugins.DnD");
35 // | dojo.require("dojox.grid.enhanced.plugins.Menu");
36 // | dojo.require("dojox.grid.enhanced.plugins.NestedSorting");
37 // | dojo.require("dojox.grid.enhanced.plugins.IndirectSelection");
38 // | </script>
39 //
40 // Step 2. Use EnhancedGrid
41 //
42 // - Via HTML markup
43 //
44 // | <div dojoType="dojox.grid.EnhancedGrid" ...
45 // | plugins="{nestedSorting: true, dnd: true, indirectSelection: true,
46 // | menus:{headerMenu:"headerMenuId", rowMenu:"rowMenuId", cellMenu:"cellMenuId",
47 // | selectedRegionMenu:"selectedRegionMenuId"}}">
48 // | ...
49 // | </div>
50 //
51 // - Or via JavaScript
52 //
53 // | <script type="text/javascript">
54 // | var grid = new dojox.grid.EnhancedGrid({plugins : {nestedSorting: true, dnd: true, indirectSelection: true,
55 // | menus:{headerMenu:"headerMenuId", rowMenu:"rowMenuId", cellMenu:"cellMenuId",selectedRegionMenu:"selectedRegionMenuId"}},
56 // | ... }, dojo.byId('gridDiv'));
57 // | grid.startup();
58 // | </script>
59 //
60 //
61 // Plugin Support
62 // [Note: Plugin support is still experimental]
63 //
64 // You can either customize the default plugins or add new ones, more details please see
65 //
66 // - dojox.grid.enhanced._PluginManager
67 // - dojox.grid.enhanced._Plugin
68 // - dojox.grid.enhanced.plugins.*
69
70 // plugins: Object
71 // Plugin properties, e.g. {nestedSorting: true, dnd: true, ...}
72 plugins: null,
73
74 // pluginMgr: Object
75 // Singleton plugin manager
76 pluginMgr: null,
77
78 // _pluginMgrClass: Object
79 // Default plugin manager class
80 _pluginMgrClass: _PluginManager,
81
82 postMixInProperties: function(){
83 this._nls = nls;
84 this.inherited(arguments);
85 },
86 postCreate: function(){
87 //create plugin manager
88 this.pluginMgr = new this._pluginMgrClass(this);
89 this.pluginMgr.preInit();
90 this.inherited(arguments);
91 this.pluginMgr.postInit();
92 },
93 plugin: function(/*String*/name){
94 // summary:
95 // An easier way for getting a plugin, e.g. grid.plugin('dnd')
96 return this.pluginMgr.getPlugin(name);
97 },
98 startup: function(){
99 this.inherited(arguments);
100 this.pluginMgr.startup();
101 },
102 createSelection: function(){
103 this.selection = new dojox.grid.enhanced.DataSelection(this);
104 },
105 canSort: function(colIndex, field){
106 // summary:
107 // Overwritten
108 return true;
109 },
110 doKeyEvent: function(e){
111 // summary:
112 // Overwritten, see _Grid.doKeyEvent()
113 try{
114 var view = this.focus.focusView;
115 view.content.decorateEvent(e);
116 if(!e.cell){ view.header.decorateEvent(e); }
117 }catch(e){}
118 this.inherited(arguments);
119 },
120 doApplyCellEdit: function(inValue, inRowIndex, inAttrName){
121 // summary:
122 // Overwritten, see DataGrid.doApplyCellEdit()
123 if(!inAttrName){
124 this.invalidated[inRowIndex] = true;
125 return;
126 }
127 this.inherited(arguments);
128 },
129 mixin: function(target, source){
130 var props = {};
131 for(var p in source){
132 if(p == '_inherited' || p == 'declaredClass' || p == 'constructor' ||
133 source['privates'] && source['privates'][p]){
134 continue;
135 }
136 props[p] = source[p];
137 }
138 lang.mixin(target, props);
139 },
140 _copyAttr: function(idx, attr){
141 // summary:
142 // Overwritten, see DataGrid._copyAttr()
143 // Fix cell TAB navigation for single click editing
144 if(!attr){ return; }
145 return this.inherited(arguments);
146 },
147 _getHeaderHeight: function(){
148 // summary:
149 // Overwritten, see _Grid._getHeaderHeight()
150 // Should include borders/margins of this.viewsHeaderNode
151 this.inherited(arguments);
152 return domGeometry.getMarginBox(this.viewsHeaderNode).h;
153 },
154 _fetch: function(start, isRender){
155 // summary:
156 // Overwritten, see DataGrid._fetch()
157 if(this.items){
158 return this.inherited(arguments);
159 }
160 start = start || 0;
161 if(this.store && !this._pending_requests[start]){
162 if(!this._isLoaded && !this._isLoading){
163 this._isLoading = true;
164 this.showMessage(this.loadingMessage);
165 }
166 this._pending_requests[start] = true;
167 try{
168 var req = {
169 start: start,
170 count: this.rowsPerPage,
171 query: this.query,
172 sort: this.getSortProps(),
173 queryOptions: this.queryOptions,
174 isRender: isRender,
175 onBegin: lang.hitch(this, "_onFetchBegin"),
176 onComplete: lang.hitch(this, "_onFetchComplete"),
177 onError: lang.hitch(this, "_onFetchError")
178 };
179 this._storeLayerFetch(req);
180 }catch(e){
181 this._onFetchError(e, {start: start, count: this.rowsPerPage});
182 }
183 }
184 return 0;
185 },
186 _storeLayerFetch: function(req){
187 // summary:
188 // Extracted fetch specifically for store layer use
189 this.store.fetch(req);
190 },
191 getCellByField: function(field){
192 return array.filter(this.layout.cells, function(cell){
193 return cell.field == field;
194 })[0];
195 },
196 onMouseUp: function(e){ },
197 createView: function(){
198 // summary:
199 // Overwrite: rewrite getCellX of view.header
200 var view = this.inherited(arguments);
201 if(has('mozilla')){
202 var ascendDom = function(inNode, inWhile){
203 for(var n = inNode; n && inWhile(n); n = n.parentNode){}
204 return n;
205 };//copied from dojox.grid._Builder
206 var makeNotTagName = function(inTagName){
207 var name = inTagName.toUpperCase();
208 return function(node){ return node.tagName != name; };
209 };//copied from dojox.grid._Builder
210
211 var func = view.header.getCellX;
212 view.header.getCellX = function(e){
213 var x = func.call(view.header, e);
214 var n = ascendDom(e.target, makeNotTagName("th"));
215 if(n && n !== e.target && dom.isDescendant(e.target, n)){ x += n.firstChild.offsetLeft; }
216 return x;
217 };
218 }
219 return view;
220 },
221 destroy: function(){
222 // summary:
223 // Destroy all resources
224 delete this._nls;
225 this.pluginMgr.destroy();
226 this.inherited(arguments);
227 }
228 });
229
230 declare("dojox.grid.enhanced.DataSelection", DataSelection, {
231 constructor: function(grid){
232 if(grid.keepSelection){
233 if(this.preserver){
234 this.preserver.destroy();
235 }
236 this.preserver = new _SelectionPreserver(this);
237 }
238 },
239 _range: function(inFrom, inTo){
240 this.grid._selectingRange = true;
241 this.inherited(arguments);
242 this.grid._selectingRange = false;
243 this.onChanged();
244 },
245 deselectAll: function(inItemOrIndex){
246 this.grid._selectingRange = true;
247 this.inherited(arguments);
248 this.grid._selectingRange = false;
249 this.onChanged();
250 }
251 });
252
253 EnhancedGrid.markupFactory = function(props, node, ctor, cellFunc){
254 return dojox.grid._Grid.markupFactory(props, node, ctor,
255 lang.partial(DataGrid.cell_markupFactory, cellFunc));
256 };
257
258 EnhancedGrid.registerPlugin = function(clazz, props){
259 _PluginManager.registerPlugin(clazz, props);
260 };
261
262 return EnhancedGrid;
263
264 });