Lines Matching refs:model
5 @submodule model-list
14 for events on the model instances they contain. This means, for example, that
16 on the list to be notified whenever any model in the list changes.
34 Fired when a model is added to the list.
36 Listen to the `on` phase of this event to be notified before a model is
38 prevent the model from being added.
40 Listen to the `after` phase of this event to be notified after a model has
44 @param {Model} model The model being added.
45 @param {Number} index The index at which the model will be added.
51 Fired when a model is created or updated via the `create()` method, but
52 before the model is actually saved or added to the list. The `add` event
53 will be fired after the model has been saved and added to the list.
56 @param {Model} model The model being created/updated.
63 duplicate model to the list, or when a sync layer response can't be parsed.
72 * `add`: Error while adding a model (probably because it's already in the
73 list and can't be added again). The model in question will be provided
74 as the `model` property on the event facade.
77 * `remove`: Error while removing a model (probably because it isn't in the
78 list and can't be removed). The model in question will be provided as
79 the `model` property on the event facade.
96 Fired when a model is removed from the list.
98 Listen to the `on` phase of this event to be notified before a model is
100 will prevent the model from being removed.
102 Listen to the `after` phase of this event to be notified after a model has
106 @param {Model} model The model being removed.
107 @param {Number} index The index of the model being removed.
141 The class specified here will be used to create model instances
149 @property model
153 model: Y.Model,
174 var model = this.model = config.model || this.model;
176 if (typeof model === 'string') {
178 this.model = Y.Object.getValue(Y, model.split('.'));
180 if (!this.model) {
181 Y.error('ModelList: Model class not found: ' + model);
201 Adds the specified model or array of models to this list. You may also pass
207 // Add a single model instance.
210 // Add a single model, creating a new instance automatically.
224 models to add. May be existing model instances or hashes of model
225 attributes, in which case new model instances will be created from the
234 @return {Model|Model[]} Added model or array of added models.
240 return YArray.map(isList ? models.toArray() : models, function (model) {
241 return this._add(model, options);
249 Define this method to provide a function that takes a model as a parameter
250 and returns a value by which that model should be sorted relative to other
257 var list = new Y.ModelList({model: Y.Model});
259 list.comparator = function (model) {
260 return model.get('id'); // Sort models by id.
264 @param {Model} model Model being sorted.
265 @return {Number|String} Value by which the model should be sorted relative
272 Creates or updates the specified model on the server, then adds it to this
276 @param {Model|Object} model Model to create. May be an existing model
277 instance or a hash of model attributes, in which case a new model instance
279 @param {Object} [options] Options to be passed to the model's `sync()` and
288 @return {Model} Created model.
290 create: function (model, options, callback) {
301 if (!model._isYUIModel) {
302 model = new this.model(model);
306 model: model
309 return model.save(options, function (err) {
311 self.add(model, options);
319 Executes the supplied function on each model in this list. Returns an array
330 var filtered = list.filter(function (model) {
331 return model.get('enabled');
336 var filteredList = list.filter({asList: true}, function (model) {
337 return model.get('enabled');
345 @param {Function} callback Function to execute on each model.
346 @param {Model} callback.model Model instance.
347 @param {Number} callback.index Index of the current model.
376 list = new Y.ModelList({model: this.model});
387 of the specified attribute from each model in this list.
405 the HTML-escaped values of the specified attribute from each model in this
427 the URL-encoded values of the specified attribute from each model in this
446 Returns the model with the specified _clientId_, or `null` if not found.
457 Returns the model with the specified _id_, or `null` if not found.
472 Calls the named method on every model in the list. Any arguments provided
476 @param {String} name Name of the method to call on each model.
479 the model on which the method was called.
487 Returns the model at the specified _index_.
490 @param {Number} index Index of the model to fetch.
491 @return {Model} The model at the specified index, or `undefined` if there
492 isn't a model there.
516 return an array of model attribute hashes.
564 Executes the specified function on each model in this list and returns an
568 @param {Function} fn Function to execute on each model.
569 @param {Model} fn.model Current model being iterated.
570 @param {Number} fn.index Index of the current model in the list.
582 of model attribute hashes.
588 parse error occurs, an `error` event will be fired and the model will not be
595 @return {Object[]} Array of model attribute hashes.
616 Removes the specified model or array of models from this list. You may also
628 @return {Model|Model[]} Removed model or array of removed models.
634 return YArray.map(isList ? models.toArray() : models, function (model) {
635 return this._remove(model, options);
652 model instances or hashes of model attributes, in which case new model
673 models = YArray.map(models, function (model) {
674 return model._isYUIModel ? model : new this.model(model);
747 Currently, model lists only make use of the `read` action, but other
758 return an array of model attribute hashes.
779 Returns an array containing attribute hashes for each model in this list,
782 Under the hood, this method calls `toJSON()` on each model in the list and
786 @return {Object[]} Array of model attribute hashes.
790 return this.map(function (model) {
791 return model.toJSON();
800 If the model's `clientId` or `id` matches that of a model that's already in
801 the list, an `error` event will be fired and the model will not be added.
804 @param {Model|Object} model Model or object to add.
806 `add` event for the added model.
809 @return {Model} The added model.
812 _add: function (model, options) {
817 if (!model._isYUIModel) {
818 model = new this.model(model);
821 id = model.get('id');
823 if (this._clientIdMap[model.get('clientId')]
828 model: model,
836 index: this._findIndex(model),
837 model: model
842 return model;
846 Adds this list as a bubble target for the specified model's events.
849 @param {Model} model Model to attach to this list.
852 _attachList: function (model) {
853 // Attach this list and make it a bubble target for the model.
854 model.lists.push(this);
855 model.addTarget(this);
875 assumed to be the result of calling a model's `comparator()` method. You can
892 Removes this list as a bubble target for the specified model's events.
895 @param {Model} model Model to detach.
898 _detachList: function (model) {
899 var index = YArray.indexOf(model.lists, this);
902 model.lists.splice(index, 1);
903 model.removeTarget(this);
912 @param {Model} model The model being inserted.
913 @return {Number} Index at which the model should be inserted.
916 _findIndex: function (model) {
926 needle = this.comparator(model);
948 @param {Model} model Model to remove.
950 `remove` event for the removed model.
953 @return {Model} Removed model.
956 _remove: function (model, options) {
957 var index = this.indexOf(model),
965 model: model,
974 model: model
980 return model;
987 @param {Model} a First model to compare.
988 @param {Model} b Second model to compare.
999 Updates the model maps when a model's `id` attribute changes.
1020 var model = e.model,
1021 id = model.get('id');
1023 this._clientIdMap[model.get('clientId')] = model;
1026 this._idMap[id] = model;
1029 this._attachList(model);
1030 this._items.splice(e.index, 0, model);
1041 var model = e.model,
1042 id = model.get('id');
1044 this._detachList(model);
1045 delete this._clientIdMap[model.get('clientId')];