/src/Oro/Bundle/FormBundle/Resources/public/js/multiple-entity/collection.js
JavaScript | 31 lines | 21 code | 3 blank | 7 comment | 2 complexity | fdb0138bfe6707f0631395b5733e0963 MD5 | raw file
- /*global define*/
- define(['backbone', './model'
- ], function (Backbone, EntityModel) {
- 'use strict';
- /**
- * @export oroform/js/multiple-entity/collection
- * @class oroform.MultipleEntity.Collection
- * @extends Backbone.Collection
- */
- return Backbone.Collection.extend({
- model: EntityModel,
- initialize: function () {
- this.on('change:isDefault', this.onIsDefaultChange, this);
- },
- onIsDefaultChange: function (item) {
- // Only 1 item allowed to be default
- if (item.get('isDefault')) {
- var defaultItems = this.where({isDefault: true});
- _.each(defaultItems, function (defaultItem) {
- if (defaultItem.get('id') !== item.get('id')) {
- defaultItem.set('isDefault', false);
- }
- });
- this.trigger('defaultChange', item);
- }
- }
- });
- });