commit extjs-2.2.1
[extjs.git] / examples / grid / CallBroker.js
1 /*\r
2  * Ext JS Library 2.2.1\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 Ext.CallBroker = function(config){\r
10     if(!config.reader){\r
11         this.reader = new Ext.data.JsonReader({}, [\r
12             'id', 'type', 'call', 'args'\r
13         ]);\r
14     }\r
15     Ext.CallBroker.superclass.constructor.call(this, config);\r
16 };\r
17 \r
18 Ext.extend(Ext.CallBroker, Ext.data.Store, {\r
19     loadRecords : function(o, options, success){\r
20         Ext.CallBroker.superclass.loadRecords.apply(this, arguments);\r
21         if(o && success){\r
22             this.data.each(this.delegateCall, this);\r
23         }\r
24     },\r
25 \r
26     delegateCall : function(c){\r
27         var o = this[c.type](c.data);\r
28         o[c.call][c.args instanceof Array ? 'apply' : 'call'](o, c.args);\r
29     },\r
30 \r
31     store : function(c){\r
32         return Ext.StoreMgr.lookup(c.id);\r
33     },\r
34 \r
35     component : function(c){\r
36         return Ext.getCmp(c.id);\r
37     },\r
38 \r
39     element : function(c){\r
40         return Ext.get(c.id);\r
41     },\r
42 \r
43     object : function(c){\r
44         return new Function('return '+c.id)();\r
45     }\r
46 });