?? model.js
字號:
// paging requestsPending: function(inBoolean){ }, rowToPage: function(inRowIndex){ return (this.rowsPerPage ? Math.floor(inRowIndex / this.rowsPerPage) : inRowIndex); }, pageToRow: function(inPageIndex){ return (this.rowsPerPage ? this.rowsPerPage * inPageIndex : inPageIndex); }, requestRows: function(inRowIndex, inCount){ // summary: // stub. Fill in to perform actual data row fetching logic. The // returning logic must provide the data back to the system via // setRow }, rowsProvided: function(inRowIndex, inCount){ this.requests--; if(this.requests == 0){ this.requestsPending(false); } }, requestPage: function(inPageIndex){ var row = this.pageToRow(inPageIndex); var count = Math.min(this.rowsPerPage, this.count - row); if(count > 0){ this.requests++; this.requestsPending(true); setTimeout(dojo.hitch(this, "requestRows", row, count), 1); //this.requestRows(row, count); } }, needPage: function(inPageIndex){ if(!this.pages[inPageIndex]){ this.pages[inPageIndex] = true; this.requestPage(inPageIndex); } }, preparePage: function(inRowIndex, inColIndex){ if(inRowIndex < this.bop || inRowIndex >= this.eop){ var pageIndex = this.rowToPage(inRowIndex); this.needPage(pageIndex); this.bop = pageIndex * this.rowsPerPage; this.eop = this.bop + (this.rowsPerPage || this.count); } }, isRowLoaded: function(inRowIndex){ return Boolean(this.data[inRowIndex]); }, // removal removePages: function(inRowIndexes){ for(var i=0, r; ((r=inRowIndexes[i]) != undefined); i++){ this.pages[this.rowToPage(r)] = false; } this.bop = this.eop =-1; }, remove: function(inRowIndexes){ this.removePages(inRowIndexes); dojox.grid.data.Table.prototype.remove.apply(this, arguments); }, // access getRow: function(inRowIndex){ var row = this.data[inRowIndex]; if(!row){ this.preparePage(inRowIndex); } return row; }, getDatum: function(inRowIndex, inColIndex){ var row = this.getRow(inRowIndex); return (row ? row[inColIndex] : this.fields.get(inColIndex).na); }, setDatum: function(inDatum, inRowIndex, inColIndex){ var row = this.getRow(inRowIndex); if(row){ row[inColIndex] = inDatum; this.datumChange(inDatum, inRowIndex, inColIndex); }else{ console.debug('[' + this.declaredClass + '] dojox.grid.data.dynamic.set: cannot set data on an non-loaded row'); } }, // sort canSort: function(){ return false; }});// FIXME: deprecated: (included for backward compatibility only)dojox.grid.data.table = dojox.grid.data.Table;dojox.grid.data.dynamic = dojox.grid.data.Dyanamic;// we treat dojo.data stores as dynamic stores because no matter how they got// here, they should always fill that contractdojo.declare("dojox.grid.data.DojoData", dojox.grid.data.Dynamic, { // summary: // A grid data model for dynamic data retreived from a store which // implements the dojo.data API set. Retrieves data automatically when // requested and provides notification when data is received // description: // This store subclasses the Dynamic grid data object in order to // provide paginated data access support, notification and view // updates for stores which support those features, and simple // field/column mapping for all dojo.data stores. constructor: function(inFields, inData, args){ this.count = 1; this._rowIdentities = {}; if(args){ dojo.mixin(this, args); } if(this.store){ // NOTE: we assume Read and Identity APIs for all stores! var f = this.store.getFeatures(); this._canNotify = f['dojo.data.api.Notification']; this._canWrite = f['dojo.data.api.Write']; if(this._canNotify){ dojo.connect(this.store, "onSet", this, "_storeDatumChange"); } } }, markupFactory: function(args, node){ return new dojox.grid.data.DojoData(null, null, args); }, query: { name: "*" }, // default, stupid query store: null, _canNotify: false, _canWrite: false, _rowIdentities: {}, clientSort: false, // data setData: function(inData){ this.store = inData; this.data = []; this.allChange(); }, setRowCount: function(inCount){ //console.debug("inCount:", inCount); this.count = inCount; this.allChange(); }, beginReturn: function(inCount){ if(this.count != inCount){ // this.setRowCount(0); // this.clear(); // console.debug(this.count, inCount); this.setRowCount(inCount); } }, _setupFields: function(dataItem){ // abort if we already have setup fields if(this.fields._nameMaps){ return; } // set up field/index mappings var m = {}; //console.debug("setting up fields", m); var fields = dojo.map(this.store.getAttributes(dataItem), function(item, idx){ m[item] = idx; m[idx+".idx"] = item; // name == display name, key = property name return { name: item, key: item }; }, this ); this.fields._nameMaps = m; // console.debug("new fields:", fields); this.fields.set(fields); this.notify("FieldsChange"); }, _getRowFromItem: function(item){ // gets us the row object (and row index) of an item }, processRows: function(items, store){ // console.debug(arguments); if(!items){ return; } this._setupFields(items[0]); dojo.forEach(items, function(item, idx){ var row = {}; row.__dojo_data_item = item; dojo.forEach(this.fields.values, function(a){ row[a.name] = this.store.getValue(item, a.name)||""; }, this); // FIXME: where else do we need to keep this in sync? this._rowIdentities[this.store.getIdentity(item)] = store.start+idx; this.setRow(row, store.start+idx); }, this); // FIXME: // Q: scott, steve, how the hell do we actually get this to update // the visible UI for these rows? // A: the goal is that Grid automatically updates to reflect changes // in model. In this case, setRow -> rowChanged -> (observed by) Grid -> modelRowChange -> updateRow }, // request data requestRows: function(inRowIndex, inCount){ var row = inRowIndex || 0; var params = { start: row, count: this.rowsPerPage, query: this.query, onBegin: dojo.hitch(this, "beginReturn"), // onItem: dojo.hitch(console, "debug"), onComplete: dojo.hitch(this, "processRows") // add to deferred? } // console.debug("requestRows:", row, this.rowsPerPage); this.store.fetch(params); }, getDatum: function(inRowIndex, inColIndex){ //console.debug("getDatum", inRowIndex, inColIndex); var row = this.getRow(inRowIndex); var field = this.fields.values[inColIndex]; return row && field ? row[field.name] : field ? field.na : '?'; //var idx = row && this.fields._nameMaps[inColIndex+".idx"]; //return (row ? row[idx] : this.fields.get(inColIndex).na); }, setDatum: function(inDatum, inRowIndex, inColIndex){ var n = this.fields._nameMaps[inColIndex+".idx"]; // console.debug("setDatum:", "n:"+n, inDatum, inRowIndex, inColIndex); if(n){ this.data[inRowIndex][n] = inDatum; this.datumChange(inDatum, inRowIndex, inColIndex); } }, // modification, update and store eventing copyRow: function(inRowIndex){ var row = {}; var backstop = {}; var src = this.getRow(inRowIndex); for(var x in src){ if(src[x] != backstop[x]){ row[x] = src[x]; } } return row; }, _attrCompare: function(cache, data){ dojo.forEach(this.fields.values, function(a){ if(cache[a.name] != data[a.name]){ return false; } }, this); return true; }, endModifyRow: function(inRowIndex){ var cache = this.cache[inRowIndex]; if(cache){ var data = this.getRow(inRowIndex); if(!this._attrCompare(cache, data)){ this.update(cache, data, inRowIndex); } delete this.cache[inRowIndex]; } }, cancelModifyRow: function(inRowIndex){ // console.debug("cancelModifyRow", arguments); var cache = this.cache[inRowIndex]; if(cache){ this.setRow(cache, inRowIndex); delete this.cache[inRowIndex]; } }, _storeDatumChange: function(item, attr, oldVal, newVal){ // the store has changed some data under us, need to update the display var rowId = this._rowIdentities[this.store.getIdentity(item)]; var row = this.getRow(rowId); row[attr] = newVal; var colId = this.fields._nameMaps[attr]; this.notify("DatumChange", [ newVal, rowId, colId ]); }, datumChange: function(value, rowIdx, colIdx){ if(this._canWrite){ // we're chaning some data, which means we need to write back var row = this.getRow(rowIdx); var field = this.fields._nameMaps[colIdx+".idx"]; this.store.setValue(row.__dojo_data_item, field, value); // we don't need to call DatumChange, an eventing store will tell // us about the row change events }else{ // we can't write back, so just go ahead and change our local copy // of the data this.notify("DatumChange", arguments); } }, insertion: function(/* index */){ console.debug("Insertion", arguments); this.notify("Insertion", arguments); this.notify("Change", arguments); }, removal: function(/* keys */){ console.debug("Removal", arguments); this.notify("Removal", arguments); this.notify("Change", arguments); }, // sort canSort: function(){ // Q: Return true and re-issue the queries? // A: Return true only. Re-issue the query in 'sort'. return this.clientSort; }});}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -