X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/ee06f37b0f6f6d94cd05a6ffae556660f7c4a2bc..c930e9176a5a85509c5b0230e2bff5c22a591432:/src/data/StoreMgr.js diff --git a/src/data/StoreMgr.js b/src/data/StoreMgr.js new file mode 100644 index 00000000..1de43d4b --- /dev/null +++ b/src/data/StoreMgr.js @@ -0,0 +1,72 @@ +/*! + * Ext JS Library 3.0.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +/** + * @class Ext.StoreMgr + * @extends Ext.util.MixedCollection + * The default global group of stores. + * @singleton + */ +Ext.StoreMgr = Ext.apply(new Ext.util.MixedCollection(), { + /** + * @cfg {Object} listeners @hide + */ + + /** + * Registers one or more Stores with the StoreMgr. You do not normally need to register stores + * manually. Any store initialized with a {@link Ext.data.Store#storeId} will be auto-registered. + * @param {Ext.data.Store} store1 A Store instance + * @param {Ext.data.Store} store2 (optional) + * @param {Ext.data.Store} etc... (optional) + */ + register : function(){ + for(var i = 0, s; (s = arguments[i]); i++){ + this.add(s); + } + }, + + /** + * Unregisters one or more Stores with the StoreMgr + * @param {String/Object} id1 The id of the Store, or a Store instance + * @param {String/Object} id2 (optional) + * @param {String/Object} etc... (optional) + */ + unregister : function(){ + for(var i = 0, s; (s = arguments[i]); i++){ + this.remove(this.lookup(s)); + } + }, + + /** + * Gets a registered Store by id + * @param {String/Object} id The id of the Store, or a Store instance + * @return {Ext.data.Store} + */ + lookup : function(id){ + if(Ext.isArray(id)){ + var fields = ['field1'], expand = !Ext.isArray(id[0]); + if(!expand){ + for(var i = 2, len = id[0].length; i <= len; ++i){ + fields.push('field' + i); + } + } + return new Ext.data.ArrayStore({ + fields: fields, + data: id, + expandData: expand, + autoDestroy: true, + autoCreated: true + + }); + } + return Ext.isObject(id) ? (id.events ? id : Ext.create(id, 'store')) : this.get(id); + }, + + // getKey implementation for MixedCollection + getKey : function(o){ + return o.storeId; + } +}); \ No newline at end of file