-};\r
-\r
-Ext.data.DataReader.prototype = {\r
- /**\r
- * @cfg {String} messageProperty [undefined] Optional name of a property within a server-response that represents a user-feedback message.\r
- */\r
- /**\r
- * Abstract method created in extension's buildExtractors impl.\r
- */\r
- getTotal: Ext.emptyFn,\r
- /**\r
- * Abstract method created in extension's buildExtractors impl.\r
- */\r
- getRoot: Ext.emptyFn,\r
- /**\r
- * Abstract method created in extension's buildExtractors impl.\r
- */\r
- getMessage: Ext.emptyFn,\r
- /**\r
- * Abstract method created in extension's buildExtractors impl.\r
- */\r
- getSuccess: Ext.emptyFn,\r
- /**\r
- * Abstract method created in extension's buildExtractors impl.\r
- */\r
- getId: Ext.emptyFn,\r
- /**\r
- * Abstract method, overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader}\r
- */\r
- buildExtractors : Ext.emptyFn,\r
- /**\r
- * Abstract method overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader}\r
- */\r
- extractData : Ext.emptyFn,\r
- /**\r
- * Abstract method overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader}\r
- */\r
- extractValues : Ext.emptyFn,\r
-\r
- /**\r
- * Used for un-phantoming a record after a successful database insert. Sets the records pk along with new data from server.\r
- * You <b>must</b> return at least the database pk using the idProperty defined in your DataReader configuration. The incoming\r
- * data from server will be merged with the data in the local record.\r
- * In addition, you <b>must</b> return record-data from the server in the same order received.\r
- * Will perform a commit as well, un-marking dirty-fields. Store's "update" event will be suppressed.\r
- * @param {Record/Record[]} record The phantom record to be realized.\r
- * @param {Object/Object[]} data The new record data to apply. Must include the primary-key from database defined in idProperty field.\r
- */\r
- realize: function(rs, data){\r
- if (Ext.isArray(rs)) {\r
- for (var i = rs.length - 1; i >= 0; i--) {\r
- // recurse\r
- if (Ext.isArray(data)) {\r
- this.realize(rs.splice(i,1).shift(), data.splice(i,1).shift());\r
- }\r
- else {\r
- // weird...rs is an array but data isn't?? recurse but just send in the whole invalid data object.\r
- // the else clause below will detect !this.isData and throw exception.\r
- this.realize(rs.splice(i,1).shift(), data);\r
- }\r
- }\r
- }\r
- else {\r
- // If rs is NOT an array but data IS, see if data contains just 1 record. If so extract it and carry on.\r
- if (Ext.isArray(data) && data.length == 1) {\r
- data = data.shift();\r
- }\r
- if (!this.isData(data)) {\r
- // TODO: Let exception-handler choose to commit or not rather than blindly rs.commit() here.\r
- //rs.commit();\r
- throw new Ext.data.DataReader.Error('realize', rs);\r
- }\r
- rs.phantom = false; // <-- That's what it's all about\r
- rs._phid = rs.id; // <-- copy phantom-id -> _phid, so we can remap in Store#onCreateRecords\r
- rs.id = this.getId(data);\r
-\r
- rs.fields.each(function(f) {\r
- if (data[f.name] !== f.defaultValue) {\r
- rs.data[f.name] = data[f.name];\r
- }\r
- });\r
- rs.commit();\r
- }\r
- },\r
-\r
- /**\r
- * Used for updating a non-phantom or "real" record's data with fresh data from server after remote-save.\r
- * If returning data from multiple-records after a batch-update, you <b>must</b> return record-data from the server in\r
- * the same order received. Will perform a commit as well, un-marking dirty-fields. Store's "update" event will be\r
- * suppressed as the record receives fresh new data-hash\r
- * @param {Record/Record[]} rs\r
- * @param {Object/Object[]} data\r
- */\r
- update : function(rs, data) {\r
- if (Ext.isArray(rs)) {\r
- for (var i=rs.length-1; i >= 0; i--) {\r
- if (Ext.isArray(data)) {\r
- this.update(rs.splice(i,1).shift(), data.splice(i,1).shift());\r
- }\r
- else {\r
- // weird...rs is an array but data isn't?? recurse but just send in the whole data object.\r
- // the else clause below will detect !this.isData and throw exception.\r
- this.update(rs.splice(i,1).shift(), data);\r
- }\r
- }\r
- }\r
- else {\r
- // If rs is NOT an array but data IS, see if data contains just 1 record. If so extract it and carry on.\r
- if (Ext.isArray(data) && data.length == 1) {\r
- data = data.shift();\r
- }\r
- if (this.isData(data)) {\r
- rs.fields.each(function(f) {\r
- if (data[f.name] !== f.defaultValue) {\r
- rs.data[f.name] = data[f.name];\r
- }\r
- });\r
- }\r
- rs.commit();\r
- }\r
- },\r
-\r
- /**\r
- * returns extracted, type-cast rows of data. Iterates to call #extractValues for each row\r
- * @param {Object[]/Object} data-root from server response\r
- * @param {Boolean} returnRecords [false] Set true to return instances of Ext.data.Record\r
- * @private\r
- */\r
- extractData : function(root, returnRecords) {\r
- // A bit ugly this, too bad the Record's raw data couldn't be saved in a common property named "raw" or something.\r
- var rawName = (this instanceof Ext.data.JsonReader) ? 'json' : 'node';\r
-\r
- var rs = [];\r
-\r
- // Had to add Check for XmlReader, #isData returns true if root is an Xml-object. Want to check in order to re-factor\r
- // #extractData into DataReader base, since the implementations are almost identical for JsonReader, XmlReader\r
- if (this.isData(root) && !(this instanceof Ext.data.XmlReader)) {\r
- root = [root];\r
- }\r
- var f = this.recordType.prototype.fields,\r
- fi = f.items,\r
- fl = f.length,\r
- rs = [];\r
- if (returnRecords === true) {\r
- var Record = this.recordType;\r
- for (var i = 0; i < root.length; i++) {\r
- var n = root[i];\r
- var record = new Record(this.extractValues(n, fi, fl), this.getId(n));\r
- record[rawName] = n; // <-- There's implementation of ugly bit, setting the raw record-data.\r
- rs.push(record);\r
- }\r
- }\r
- else {\r
- for (var i = 0; i < root.length; i++) {\r
- var data = this.extractValues(root[i], fi, fl);\r
- data[this.meta.idProperty] = this.getId(root[i]);\r
- rs.push(data);\r
- }\r
- }\r
- return rs;\r
- },\r
-\r
- /**\r
- * Returns true if the supplied data-hash <b>looks</b> and quacks like data. Checks to see if it has a key\r
- * corresponding to idProperty defined in your DataReader config containing non-empty pk.\r
- * @param {Object} data\r
- * @return {Boolean}\r
- */\r
- isData : function(data) {\r
- return (data && Ext.isObject(data) && !Ext.isEmpty(this.getId(data))) ? true : false;\r
- },\r
-\r
- // private function a store will createSequence upon\r
- onMetaChange : function(meta){\r
- delete this.ef;\r
- this.meta = meta;\r
- this.recordType = Ext.data.Record.create(meta.fields);\r
- this.buildExtractors();\r
- }\r
-};\r
-\r
-/**\r
- * @class Ext.data.DataReader.Error\r
- * @extends Ext.Error\r
- * General error class for Ext.data.DataReader\r
- */\r
-Ext.data.DataReader.Error = Ext.extend(Ext.Error, {\r
- constructor : function(message, arg) {\r
- this.arg = arg;\r
- Ext.Error.call(this, message);\r
- },\r
- name: 'Ext.data.DataReader'\r
-});\r
-Ext.apply(Ext.data.DataReader.Error.prototype, {\r
- lang : {\r
- 'update': "#update received invalid data from server. Please see docs for DataReader#update and review your DataReader configuration.",\r
- 'realize': "#realize was called with invalid remote-data. Please see the docs for DataReader#realize and review your DataReader configuration.",\r
- 'invalid-response': "#readResponse received an invalid response from the server."\r
- }\r
-});\r