Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / src / data / MemoryProxy.js
diff --git a/src/data/MemoryProxy.js b/src/data/MemoryProxy.js
new file mode 100644 (file)
index 0000000..f03f9e3
--- /dev/null
@@ -0,0 +1,69 @@
+/*!
+ * Ext JS Library 3.0.0
+ * Copyright(c) 2006-2009 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+/**\r
+ * @class Ext.data.MemoryProxy\r
+ * @extends Ext.data.DataProxy\r
+ * An implementation of Ext.data.DataProxy that simply passes the data specified in its constructor\r
+ * to the Reader when its load method is called.\r
+ * @constructor\r
+ * @param {Object} data The data object which the Reader uses to construct a block of Ext.data.Records.\r
+ */\r
+Ext.data.MemoryProxy = function(data){\r
+    // Must define a dummy api with "read" action to satisfy DataProxy#doRequest and Ext.data.Api#prepare *before* calling super\r
+    var api = {};\r
+    api[Ext.data.Api.actions.read] = true;\r
+    Ext.data.MemoryProxy.superclass.constructor.call(this, {\r
+        api: api\r
+    });\r
+    this.data = data;\r
+};\r
+\r
+Ext.extend(Ext.data.MemoryProxy, Ext.data.DataProxy, {\r
+    /**\r
+     * @event loadexception\r
+     * Fires if an exception occurs in the Proxy during data loading. Note that this event is also relayed\r
+     * through {@link Ext.data.Store}, so you can listen for it directly on any Store instance.\r
+     * @param {Object} this\r
+     * @param {Object} arg The callback's arg object passed to the {@link #load} function\r
+     * @param {Object} null This parameter does not apply and will always be null for MemoryProxy\r
+     * @param {Error} e The JavaScript Error object caught if the configured Reader could not read the data\r
+     */\r
+\r
+       /**\r
+     * MemoryProxy implementation of DataProxy#doRequest\r
+     * @param {String} action\r
+     * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null\r
+     * @param {Object} params An object containing properties which are to be used as HTTP parameters\r
+     * for the request to the remote server.\r
+     * @param {Ext.data.DataReader} reader The Reader object which converts the data\r
+     * object into a block of Ext.data.Records.\r
+     * @param {Function} callback The function into which to pass the block of Ext.data.Records.\r
+     * The function must be passed <ul>\r
+     * <li>The Record block object</li>\r
+     * <li>The "arg" argument from the load function</li>\r
+     * <li>A boolean success indicator</li>\r
+     * </ul>\r
+     * @param {Object} scope The scope in which to call the callback\r
+     * @param {Object} arg An optional argument which is passed to the callback as its second parameter.\r
+     */\r
+    doRequest : function(action, rs, params, reader, callback, scope, arg) {\r
+        // No implementation for CRUD in MemoryProxy.  Assumes all actions are 'load'\r
+        params = params || {};\r
+        var result;\r
+        try {\r
+            result = reader.readRecords(this.data);\r
+        }catch(e){\r
+            // @deprecated loadexception\r
+            this.fireEvent("loadexception", this, null, arg, e);\r
+\r
+            this.fireEvent('exception', this, 'response', action, arg, null, e);\r
+            callback.call(scope, null, arg, false);\r
+            return;\r
+        }\r
+        callback.call(scope, result, arg, true);\r
+    }\r
+});
\ No newline at end of file