Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / DataReader.html
index 9d2ada3..523f407 100644 (file)
@@ -1,17 +1,12 @@
-<html>
-<head>
-  <title>The source code</title>
-    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
-    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
-</head>
-<body  onload="prettyPrint();">
-    <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-<div id="cls-Ext.data.DataReader"></div>/**\r
+<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
+</head>\r
+<body  onload="prettyPrint();">\r
+    <pre class="prettyprint lang-js"><div id="cls-Ext.data.DataReader"></div>/**\r
  * @class Ext.data.DataReader\r
  * Abstract base class for reading structured data from a data source and converting\r
  * it into an object containing {@link Ext.data.Record} objects and metadata for use\r
@@ -120,7 +115,12 @@ Ext.data.DataReader.prototype = {
             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
-            rs.data = 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
@@ -152,12 +152,56 @@ Ext.data.DataReader.prototype = {
                 data = data.shift();\r
             }\r
             if (this.isData(data)) {\r
-                rs.data = Ext.apply(rs.data, 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
     <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
@@ -196,42 +240,6 @@ Ext.apply(Ext.data.DataReader.Error.prototype, {
         'invalid-response': "#readResponse received an invalid response from the server."\r
     }\r
 });\r
-\r
-\r
-<div id="method-Ext.data.DataReader.Error-Response"></div>/**\r
- * Ext.data.Response\r
- * A generic response class to normalize response-handling internally to the framework.\r
- * TODO move to own file, add to jsb.\r
- */\r
-Ext.data.Response = function(params) {\r
-    Ext.apply(this, params);\r
-};\r
-Ext.data.Response.prototype = {\r
-    <div id="prop-Ext.data.DataReader.Error-{String}"></div>/**\r
-     * @property {String} action {@link Ext.data.Api#actions}\r
-     */\r
-    action: undefined,\r
-    <div id="prop-Ext.data.DataReader.Error-{Boolean}"></div>/**\r
-     * @property {Boolean} success\r
-     */\r
-    success : undefined,\r
-    <div id="prop-Ext.data.DataReader.Error-{String}"></div>/**\r
-     * @property {String} message\r
-     */\r
-    message : undefined,\r
-    <div id="prop-Ext.data.DataReader.Error-{Array/Object}"></div>/**\r
-     * @property {Array/Object} data\r
-     */\r
-    data: undefined,\r
-    <div id="prop-Ext.data.DataReader.Error-{Object}"></div>/**\r
-     * @property {Object} raw The raw response returned from server-code\r
-     */\r
-    raw: undefined,\r
-    <div id="prop-Ext.data.DataReader.Error-{Ext.data.Record/Ext.data.Record[]}"></div>/**\r
-     * @property {Ext.data.Record/Ext.data.Record[]} record(s) related to the Request action\r
-     */\r
-    records: undefined\r
-}\r
-</pre>
-</body>
+</pre>    \r
+</body>\r
 </html>
\ No newline at end of file