Lines Matching refs:model
1 YUI.add('model-list', function(Y) {
7 @submodule model-list
16 for events on the model instances they contain. This means, for example, that
18 on the list to be notified whenever any model in the list changes.
36 Fired when a model is added to the list.
38 Listen to the `on` phase of this event to be notified before a model is
40 prevent the model from being added.
42 Listen to the `after` phase of this event to be notified after a model has
46 @param {Model} model The model being added.
47 @param {Number} index The index at which the model will be added.
53 Fired when a model is created or updated via the `create()` method, but
54 before the model is actually saved or added to the list. The `add` event
55 will be fired after the model has been saved and added to the list.
58 @param {Model} model The model being created/updated.
65 duplicate model to the list, or when a sync layer response can't be parsed.
74 * `add`: Error while adding a model (probably because it's already in the
75 list and can't be added again). The model in question will be provided
76 as the `model` property on the event facade.
79 * `remove`: Error while removing a model (probably because it isn't in the
80 list and can't be removed). The model in question will be provided as
81 the `model` property on the event facade.
98 Fired when a model is removed from the list.
100 Listen to the `on` phase of this event to be notified before a model is
102 will prevent the model from being removed.
104 Listen to the `after` phase of this event to be notified after a model has
108 @param {Model} model The model being removed.
109 @param {Number} index The index of the model being removed.
143 The class specified here will be used to create model instances
151 @property model
155 model: Y.Model,
176 var model = this.model = config.model || this.model;
178 if (typeof model === 'string') {
180 this.model = Y.Object.getValue(Y, model.split('.'));
182 if (!this.model) {
183 Y.error('ModelList: Model class not found: ' + model);
203 Adds the specified model or array of models to this list. You may also pass
209 // Add a single model instance.
212 // Add a single model, creating a new instance automatically.
226 models to add. May be existing model instances or hashes of model
227 attributes, in which case new model instances will be created from the
236 @return {Model|Model[]} Added model or array of added models.
242 return YArray.map(isList ? models.toArray() : models, function (model) {
243 return this._add(model, options);
251 Define this method to provide a function that takes a model as a parameter
252 and returns a value by which that model should be sorted relative to other
259 var list = new Y.ModelList({model: Y.Model});
261 list.comparator = function (model) {
262 return model.get('id'); // Sort models by id.
266 @param {Model} model Model being sorted.
267 @return {Number|String} Value by which the model should be sorted relative
274 Creates or updates the specified model on the server, then adds it to this
278 @param {Model|Object} model Model to create. May be an existing model
279 instance or a hash of model attributes, in which case a new model instance
281 @param {Object} [options] Options to be passed to the model's `sync()` and
290 @return {Model} Created model.
292 create: function (model, options, callback) {
303 if (!model._isYUIModel) {
304 model = new this.model(model);
308 model: model
311 return model.save(options, function (err) {
313 self.add(model, options);
321 Executes the supplied function on each model in this list. Returns an array
332 var filtered = list.filter(function (model) {
333 return model.get('enabled');
338 var filteredList = list.filter({asList: true}, function (model) {
339 return model.get('enabled');
347 @param {Function} callback Function to execute on each model.
348 @param {Model} callback.model Model instance.
349 @param {Number} callback.index Index of the current model.
378 list = new Y.ModelList({model: this.model});
389 of the specified attribute from each model in this list.
407 the HTML-escaped values of the specified attribute from each model in this
429 the URL-encoded values of the specified attribute from each model in this
448 Returns the model with the specified _clientId_, or `null` if not found.
459 Returns the model with the specified _id_, or `null` if not found.
474 Calls the named method on every model in the list. Any arguments provided
478 @param {String} name Name of the method to call on each model.
481 the model on which the method was called.
489 Returns the model at the specified _index_.
492 @param {Number} index Index of the model to fetch.
493 @return {Model} The model at the specified index, or `undefined` if there
494 isn't a model there.
518 return an array of model attribute hashes.
566 Executes the specified function on each model in this list and returns an
570 @param {Function} fn Function to execute on each model.
571 @param {Model} fn.model Current model being iterated.
572 @param {Number} fn.index Index of the current model in the list.
584 of model attribute hashes.
590 parse error occurs, an `error` event will be fired and the model will not be
597 @return {Object[]} Array of model attribute hashes.
618 Removes the specified model or array of models from this list. You may also
630 @return {Model|Model[]} Removed model or array of removed models.
636 return YArray.map(isList ? models.toArray() : models, function (model) {
637 return this._remove(model, options);
654 model instances or hashes of model attributes, in which case new model
675 models = YArray.map(models, function (model) {
676 return model._isYUIModel ? model : new this.model(model);
749 Currently, model lists only make use of the `read` action, but other
760 return an array of model attribute hashes.
781 Returns an array containing attribute hashes for each model in this list,
784 Under the hood, this method calls `toJSON()` on each model in the list and
788 @return {Object[]} Array of model attribute hashes.
792 return this.map(function (model) {
793 return model.toJSON();
802 If the model's `clientId` or `id` matches that of a model that's already in
803 the list, an `error` event will be fired and the model will not be added.
806 @param {Model|Object} model Model or object to add.
808 `add` event for the added model.
811 @return {Model} The added model.
814 _add: function (model, options) {
819 if (!model._isYUIModel) {
820 model = new this.model(model);
823 id = model.get('id');
825 if (this._clientIdMap[model.get('clientId')]
830 model: model,
838 index: this._findIndex(model),
839 model: model
844 return model;
848 Adds this list as a bubble target for the specified model's events.
851 @param {Model} model Model to attach to this list.
854 _attachList: function (model) {
855 // Attach this list and make it a bubble target for the model.
856 model.lists.push(this);
857 model.addTarget(this);
877 assumed to be the result of calling a model's `comparator()` method. You can
894 Removes this list as a bubble target for the specified model's events.
897 @param {Model} model Model to detach.
900 _detachList: function (model) {
901 var index = YArray.indexOf(model.lists, this);
904 model.lists.splice(index, 1);
905 model.removeTarget(this);
914 @param {Model} model The model being inserted.
915 @return {Number} Index at which the model should be inserted.
918 _findIndex: function (model) {
928 needle = this.comparator(model);
950 @param {Model} model Model to remove.
952 `remove` event for the removed model.
955 @return {Model} Removed model.
958 _remove: function (model, options) {
959 var index = this.indexOf(model),
967 model: model,
976 model: model
982 return model;
989 @param {Model} a First model to compare.
990 @param {Model} b Second model to compare.
1001 Updates the model maps when a model's `id` attribute changes.
1022 var model = e.model,
1023 id = model.get('id');
1025 this._clientIdMap[model.get('clientId')] = model;
1028 this._idMap[id] = model;
1031 this._attachList(model);
1032 this._items.splice(e.index, 0, model);
1043 var model = e.model,
1044 id = model.get('id');
1046 this._detachList(model);
1047 delete this._clientIdMap[model.get('clientId')];
1084 }, '@VERSION@' ,{requires:['array-extras', 'array-invoke', 'arraylist', 'base-build', 'escape', 'json-parse', 'model']});