4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-ModelManager'>/**
19 </span> * @author Ed Spencer
20 * @class Ext.ModelManager
21 * @extends Ext.AbstractManager
23 The ModelManager keeps track of all {@link Ext.data.Model} types defined in your application.
25 __Creating Model Instances__
26 Model instances can be created by using the {@link #create} function. It is also possible to do
27 this by using the Model type directly. The following snippets are equivalent:
30 extend: 'Ext.data.Model',
31 fields: ['first', 'last']
34 // method 1, create through the manager
35 Ext.ModelManager.create({
40 // method 2, create on the type directly
46 __Accessing Model Types__
47 A reference to a Model type can be obtained by using the {@link #getModel} function. Since models types
48 are normal classes, you can access the type directly. The following snippets are equivalent:
51 extend: 'Ext.data.Model',
52 fields: ['first', 'last']
55 // method 1, access model type through the manager
56 var UserType = Ext.ModelManager.getModel('User');
58 // method 2, reference the type directly
64 Ext.define('Ext.ModelManager', {
65 extend: 'Ext.AbstractManager',
66 alternateClassName: 'Ext.ModelMgr',
67 requires: ['Ext.data.Association'],
73 <span id='Ext-ModelManager-property-associationStack'> /**
74 </span> * Private stack of associations that must be created once their associated model has been defined
75 * @property associationStack
80 <span id='Ext-ModelManager-method-registerType'> /**
81 </span> * Registers a model definition. All model plugins marked with isDefault: true are bootstrapped
82 * immediately, as are any addition plugins defined in the model config.
85 registerType: function(name, config) {
86 var proto = config.prototype,
88 if (proto && proto.isModel) {
89 // registering an already defined model
92 // passing in a configuration
94 config.extend = 'Ext.data.Model';
96 model = Ext.define(name, config);
98 this.types[name] = model;
102 <span id='Ext-ModelManager-method-onModelDefined'> /**
104 * Private callback called whenever a model has just been defined. This sets up any associations
105 * that were waiting for the given model to be defined
106 * @param {Function} model The model that was just created
108 onModelDefined: function(model) {
109 var stack = this.associationStack,
110 length = stack.length,
112 association, i, created;
114 for (i = 0; i < length; i++) {
115 association = stack[i];
117 if (association.associatedModel == model.modelName) {
118 create.push(association);
122 for (i = 0, length = create.length; i < length; i++) {
124 this.types[created.ownerModel].prototype.associations.add(Ext.data.Association.create(created));
125 Ext.Array.remove(stack, created);
129 <span id='Ext-ModelManager-method-registerDeferredAssociation'> /**
130 </span> * Registers an association where one of the models defined doesn't exist yet.
131 * The ModelManager will check when new models are registered if it can link them
134 * @param {Ext.data.Association} association The association
136 registerDeferredAssociation: function(association){
137 this.associationStack.push(association);
140 <span id='Ext-ModelManager-method-getModel'> /**
141 </span> * Returns the {@link Ext.data.Model} for a given model name
142 * @param {String/Object} id The id of the model or the model instance.
144 getModel: function(id) {
146 if (typeof model == 'string') {
147 model = this.types[model];
152 <span id='Ext-ModelManager-method-create'> /**
153 </span> * Creates a new instance of a Model using the given data.
154 * @param {Object} data Data to initialize the Model's fields with
155 * @param {String} name The name of the model to create
156 * @param {Number} id Optional unique id of the Model instance (see {@link Ext.data.Model})
158 create: function(config, name, id) {
159 var con = typeof name == 'function' ? name : this.types[name || config.name];
161 return new con(config, id);
165 <span id='Ext-method-regModel'> /**
166 </span> * Creates a new Model class from the specified config object. See {@link Ext.data.Model} for full examples.
168 * @param {Object} config A configuration object for the Model you wish to create.
169 * @return {Ext.data.Model} The newly registered Model
173 Ext.regModel = function() {
175 if (Ext.isDefined(Ext.global.console)) {
176 Ext.global.console.warn('Ext.regModel has been deprecated. Models can now be created by extending Ext.data.Model: Ext.define("MyModel", {extend: "Ext.data.Model", fields: []});.');
179 return this.ModelManager.registerType.apply(this.ModelManager, arguments);