Roo/data/MemoryProxy.js
[roojs1] / Roo / data / MemoryProxy.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11 /**
12  * @class Roo.data.MemoryProxy
13  * @extends Roo.data.DataProxy
14  * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
15  * to the Reader when its load method is called.
16  * @constructor
17  * @param {Object} config  A config object containing the objects needed for the Store to access data,
18  */
19 Roo.data.MemoryProxy = function(data){
20     if (typeof(data) != 'undefined' && typeof(data.data) != 'undefined') {
21         data = data.data;
22     }
23     Roo.data.MemoryProxy.superclass.constructor.call(this);
24     this.data = data;
25 };
26
27 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
28     
29     /**
30      *  @cfg {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
31      */
32     /**
33      * Load data from the requested source (in this case an in-memory
34      * data object passed to the constructor), read the data object into
35      * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
36      * process that block using the passed callback.
37      * @param {Object} params This parameter is not used by the MemoryProxy class.
38      * @param {Roo.data.DataReader} reader The Reader object which converts the data
39      * object into a block of Roo.data.Records.
40      * @param {Function} callback The function into which to pass the block of Roo.data.records.
41      * The function must be passed <ul>
42      * <li>The Record block object</li>
43      * <li>The "arg" argument from the load function</li>
44      * <li>A boolean success indicator</li>
45      * </ul>
46      * @param {Object} scope The scope in which to call the callback
47      * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
48      */
49     load : function(params, reader, callback, scope, arg){
50         params = params || {};
51         var result;
52         try {
53             result = reader.readRecords(params.data ? params.data :this.data);
54         }catch(e){
55             this.fireEvent("loadexception", this, arg, null, e);
56             callback.call(scope, null, arg, false);
57             return;
58         }
59         callback.call(scope, result, arg, true);
60     },
61     
62     // private
63     update : function(params, records){
64         
65     }
66 });