| 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", |
| 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 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
plugins: null, |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
pluginMgr: null, |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
_pluginMgrClass: _PluginManager, |
| 81 |
|
| 82 |
postMixInProperties: function(){ |
| 83 |
this._nls = nls; |
| 84 |
this.inherited(arguments); |
| 85 |
}, |
| 86 |
postCreate: function(){ |
| 87 |
|
| 88 |
this.pluginMgr = new this._pluginMgrClass(this); |
| 89 |
this.pluginMgr.preInit(); |
| 90 |
this.inherited(arguments); |
| 91 |
this.pluginMgr.postInit(); |
| 92 |
}, |
| 93 |
plugin: function(name){ |
| 94 |
|
| 95 |
|
| 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 |
|
| 107 |
|
| 108 |
return true; |
| 109 |
}, |
| 110 |
doKeyEvent: function(e){ |
| 111 |
|
| 112 |
|
| 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 |
|
| 122 |
|
| 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 |
|
| 142 |
|
| 143 |
|
| 144 |
if(!attr){ return; } |
| 145 |
return this.inherited(arguments); |
| 146 |
}, |
| 147 |
_getHeaderHeight: function(){ |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
this.inherited(arguments); |
| 152 |
return domGeometry.getMarginBox(this.viewsHeaderNode).h; |
| 153 |
}, |
| 154 |
_fetch: function(start, isRender){ |
| 155 |
|
| 156 |
|
| 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 |
|
| 188 |
|
| 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 |
|
| 199 |
|
| 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 |
}; |
| 206 |
var makeNotTagName = function(inTagName){ |
| 207 |
var name = inTagName.toUpperCase(); |
| 208 |
return function(node){ return node.tagName != name; }; |
| 209 |
}; |
| 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 |
|
| 223 |
|
| 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 |
}); |