1 | /*! |
---|
2 | * Ext JS Library 3.0.0 |
---|
3 | * Copyright(c) 2006-2009 Ext JS, LLC |
---|
4 | * licensing@extjs.com |
---|
5 | * http://www.extjs.com/license |
---|
6 | */ |
---|
7 | /** |
---|
8 | * @class Ext.StoreMgr |
---|
9 | * @extends Ext.util.MixedCollection |
---|
10 | * The default global group of stores. |
---|
11 | * @singleton |
---|
12 | */ |
---|
13 | Ext.StoreMgr = Ext.apply(new Ext.util.MixedCollection(), { |
---|
14 | /** |
---|
15 | * @cfg {Object} listeners @hide |
---|
16 | */ |
---|
17 | |
---|
18 | /** |
---|
19 | * Registers one or more Stores with the StoreMgr. You do not normally need to register stores |
---|
20 | * manually. Any store initialized with a {@link Ext.data.Store#storeId} will be auto-registered. |
---|
21 | * @param {Ext.data.Store} store1 A Store instance |
---|
22 | * @param {Ext.data.Store} store2 (optional) |
---|
23 | * @param {Ext.data.Store} etc... (optional) |
---|
24 | */ |
---|
25 | register : function(){ |
---|
26 | for(var i = 0, s; (s = arguments[i]); i++){ |
---|
27 | this.add(s); |
---|
28 | } |
---|
29 | }, |
---|
30 | |
---|
31 | /** |
---|
32 | * Unregisters one or more Stores with the StoreMgr |
---|
33 | * @param {String/Object} id1 The id of the Store, or a Store instance |
---|
34 | * @param {String/Object} id2 (optional) |
---|
35 | * @param {String/Object} etc... (optional) |
---|
36 | */ |
---|
37 | unregister : function(){ |
---|
38 | for(var i = 0, s; (s = arguments[i]); i++){ |
---|
39 | this.remove(this.lookup(s)); |
---|
40 | } |
---|
41 | }, |
---|
42 | |
---|
43 | /** |
---|
44 | * Gets a registered Store by id |
---|
45 | * @param {String/Object} id The id of the Store, or a Store instance |
---|
46 | * @return {Ext.data.Store} |
---|
47 | */ |
---|
48 | lookup : function(id){ |
---|
49 | if(Ext.isArray(id)){ |
---|
50 | var fields = ['field1'], expand = !Ext.isArray(id[0]); |
---|
51 | if(!expand){ |
---|
52 | for(var i = 2, len = id[0].length; i <= len; ++i){ |
---|
53 | fields.push('field' + i); |
---|
54 | } |
---|
55 | } |
---|
56 | return new Ext.data.ArrayStore({ |
---|
57 | fields: fields, |
---|
58 | data: id, |
---|
59 | expandData: expand, |
---|
60 | autoDestroy: true, |
---|
61 | autoCreated: true |
---|
62 | |
---|
63 | }); |
---|
64 | } |
---|
65 | return Ext.isObject(id) ? (id.events ? id : Ext.create(id, 'store')) : this.get(id); |
---|
66 | }, |
---|
67 | |
---|
68 | // getKey implementation for MixedCollection |
---|
69 | getKey : function(o){ |
---|
70 | return o.storeId; |
---|
71 | } |
---|
72 | }); |
---|