PageRenderTime 57ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Oro/Bundle/AddressBundle/Resources/public/js/address/collection.js

https://github.com/diimpp/platform
JavaScript | 31 lines | 21 code | 3 blank | 7 comment | 2 complexity | 4882bb8e7926e0496ab28630fb4d6ac6 MD5 | raw file
  1. /*global define*/
  2. define(['underscore', 'backbone', 'oroaddress/js/address/model'
  3. ], function (_, Backbone, AddressModel) {
  4. 'use strict';
  5. /**
  6. * @export oroaddress/js/address/collection
  7. * @class oroaddress.address.Collection
  8. * @extends Backbone.Collection
  9. */
  10. return Backbone.Collection.extend({
  11. model: AddressModel,
  12. initialize: function () {
  13. this.on('change:active', this.onActiveChange, this);
  14. },
  15. onActiveChange: function (item) {
  16. // Only 1 item allowed to be active
  17. if (item.get('active')) {
  18. var activeItems = this.where({active: true});
  19. _.each(activeItems, function (activeItem) {
  20. if (activeItem.get('id') !== item.get('id')) {
  21. activeItem.set('active', false);
  22. }
  23. });
  24. this.trigger('activeChange', item);
  25. }
  26. }
  27. });
  28. });