<html>\r
<head>\r
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> \r
<title>The source code</title>\r
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
*/\r
this.recordType = Ext.isArray(recordType) ?\r
Ext.data.Record.create(recordType) : recordType;\r
-\r
- // make sure extraction functions are defined.\r
- this.buildExtractors();\r
+
+ // if recordType defined make sure extraction functions are defined\r
+ if (this.recordType){\r
+ this.buildExtractors();\r
+ }
};\r
\r
Ext.data.DataReader.prototype = {\r
-\r
+ <div id="cfg-Ext.data.DataReader-messageProperty"></div>/**\r
+ * @cfg {String} messageProperty [undefined] Optional name of a property within a server-response that represents a user-feedback message.\r
+ */\r
+ <div id="prop-Ext.data.DataReader-getTotal"></div>/**\r
+ * Abstract method created in extension's buildExtractors impl.\r
+ */\r
+ getTotal: Ext.emptyFn,\r
+ <div id="prop-Ext.data.DataReader-getRoot"></div>/**\r
+ * Abstract method created in extension's buildExtractors impl.\r
+ */\r
+ getRoot: Ext.emptyFn,\r
+ <div id="prop-Ext.data.DataReader-getMessage"></div>/**\r
+ * Abstract method created in extension's buildExtractors impl.\r
+ */\r
+ getMessage: Ext.emptyFn,\r
+ <div id="prop-Ext.data.DataReader-getSuccess"></div>/**\r
+ * Abstract method created in extension's buildExtractors impl.\r
+ */\r
+ getSuccess: Ext.emptyFn,\r
+ <div id="prop-Ext.data.DataReader-getId"></div>/**\r
+ * Abstract method created in extension's buildExtractors impl.\r
+ */\r
+ getId: Ext.emptyFn,\r
<div id="prop-Ext.data.DataReader-buildExtractors"></div>/**\r
- * Abstract method, overridden in {@link Ext.data.JsonReader}\r
+ * Abstract method, overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader}\r
*/\r
buildExtractors : Ext.emptyFn,\r
+ <div id="prop-Ext.data.DataReader-extractData"></div>/**\r
+ * Abstract method overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader}\r
+ */\r
+ extractData : Ext.emptyFn,\r
+ <div id="prop-Ext.data.DataReader-extractValues"></div>/**\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
<div id="method-Ext.data.DataReader-realize"></div>/**\r
* Used for un-phantoming a record after a successful database insert. Sets the records pk along with new data from server.\r
//rs.commit();\r
throw new Ext.data.DataReader.Error('realize', rs);\r
}\r
- var values = this.extractValues(data, rs.fields.items, rs.fields.items.length);\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 = data[this.meta.idProperty];\r
- rs.data = values;\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
data = data.shift();\r
}\r
if (this.isData(data)) {\r
- rs.data = this.extractValues(Ext.apply(rs.data, data), rs.fields.items, rs.fields.items.length);\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
<div id="method-Ext.data.DataReader-isData"></div>/**\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
* @return {Boolean}\r
*/\r
isData : function(data) {\r
- return (data && Ext.isObject(data) && !Ext.isEmpty(data[this.meta.idProperty])) ? true : false;\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
'invalid-response': "#readResponse received an invalid response from the server."\r
}\r
});\r
-\r
-\r
</pre> \r
</body>\r
</html>
\ No newline at end of file