if(!dojo._hasResource["dojox.grid.tests.databaseModel"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. dojo._hasResource["dojox.grid.tests.databaseModel"] = true; dojo.provide("dojox.grid.tests.databaseModel"); dojo.require("dojox.grid._data.model"); // Provides a sparse array that is also traversable inorder // with basic Array: // - iterating by index is slow for large sparse arrays // - for...in iteration is in order of element creation // maintains a secondary index for interating // over sparse elements inorder dojo.declare("dojox.grid.Sparse", null, { constructor: function() { this.clear(); }, clear: function() { this.indices = []; this.values = []; }, length: function() { return this.indices.length; }, set: function(inIndex, inValue) { for (var i=0,l=this.indices.length; i= inIndex) break; } if (this.indices[i] != inIndex) this.indices.splice(i, 0, inIndex); this.values[inIndex] = inValue; }, get: function(inIndex) { return this.values[inIndex]; }, remove: function(inIndex) { for (var i=0,l=this.indices.length; i=0) && ((k=inRowIndexes[i])!=undefined); i--) this.setState(k, inState, inValue); }, clearStateForIndexes: function(inRowIndexes, inState) { for (var i=inRowIndexes.length-1, k; (i>=0) && ((k=inRowIndexes[i])!=undefined); i--) this.clearState(k, inState); }, //$ Return boolean stating whether or not an operation is in progress that may change row indexing. isAddRemoving: function() { return Boolean(this.states['inserting'].length() || this.states['removing'].length()); }, isInflight: function() { return Boolean(this.states['inflight'].length()); }, //$ Return boolean stating if the model is currently undergoing any type of edit. isEditing: function() { for (var i=0, r={}, s; (s=this.stateNames[i]); i++) if (this.states[s].length()) return true; }, //$ Return true if ok to modify the given row. Override as needed, using model editing state information. canModify: function(inRowIndex) { return !this.getState(inRowIndex).inflight && !(this.isInflight() && this.isAddRemoving()); }, // server send / receive getSendParams: function(inParams) { var p = { database: this.database || '', table: this.table || '' } return dojo.mixin(p, inParams || {}); }, send: function(inAsync, inParams, inCallbacks) { //console.log('send', inParams.command); var p = this.getSendParams(inParams); var d = dojo.xhrPost({ url: this.server, content: p, handleAs: 'json-comment-filtered', contentType: "application/x-www-form-urlencoded; charset=utf-8", sync: !inAsync }); d.addCallbacks(dojo.hitch(this, "receive", inCallbacks), dojo.hitch(this, "receiveError", inCallbacks)); return d; }, _callback: function(cb, eb, data) { try{ cb && cb(data); } catch(e){ eb && eb(data, e); } }, receive: function(inCallbacks, inData) { inCallbacks && this._callback(inCallbacks.callback, inCallbacks.errback, inData); }, receiveError: function(inCallbacks, inErr) { this._callback(inCallbacks.errback, null, inErr) }, encodeRow: function(inParams, inRow, inPrefix) { for (var i=0, l=inRow.length; i < l; i++) inParams['_' + (inPrefix ? inPrefix : '') + i] = (inRow[i] ? inRow[i] : ''); }, measure: function() { this.send(true, { command: 'info' }, { callback: dojo.hitch(this, this.callbacks.info) }); }, fetchRowCount: function(inCallbacks) { this.send(true, { command: 'count' }, inCallbacks); }, // server commits commitEdit: function(inOldData, inNewData, inRowIndex, inCallbacks) { this.setState(inRowIndex, "inflight", true); var params = {command: 'update'}; this.encodeRow(params, inOldData, 'o'); this.encodeRow(params, inNewData); this.send(true, params, inCallbacks); }, commitInsert: function(inRowIndex, inNewData, inCallbacks) { this.setState(inRowIndex, "inflight", true); var params = {command: 'insert'}; this.encodeRow(params, inNewData); this.send(true, params, inCallbacks); }, // NOTE: supported only in tables with pk commitDelete: function(inRows, inCallbacks) { var params = { command: 'delete', count: inRows.length } var pk = this.getPkIndex(); if (pk < 0) return; for (var i=0; i < inRows.length; i++) { params['_' + i] = inRows[i][pk]; } this.send(true, params, inCallbacks); }, getUpdateCallbacks: function(inRowIndex) { return { callback: dojo.hitch(this, this.callbacks.update, inRowIndex), errback: dojo.hitch(this, this.callbacks.updateError, inRowIndex) }; }, // primary key from fields getPkIndex: function() { for (var i=0, l=this.fields.count(), f; (i