Advertisement
Guest User

Untitled

a guest
May 27th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. const _ = require('underscore');
  2. const BaseModel = require('./BaseModel');
  3. const UserConfig = require('./../../../config/model/User');
  4.  
  5. module.exports = BaseModel.extend({
  6. defaults: UserConfig.avatars,
  7.  
  8. idAttribute: 'default',
  9.  
  10. url: 'Avatar',
  11.  
  12. exportStore: function () {
  13. return _.clone(this.attributes);
  14. },
  15.  
  16. /**
  17. * Create avatar urls
  18. *
  19. * m - 23x23
  20. * a - 68x68
  21. * p - 130x130
  22. *
  23. * @param response
  24. * @returns {{default: (*|void|XML|string), small: (*|void|XML|string), big: (*|null|Avatar)}}
  25. */
  26. parse: function (response) {
  27. this.avatarExists = response && response.avatar;
  28.  
  29. return this.avatarExists ? {
  30. 'default': response.avatar.replace(/(\/)[a-z](_[0-9]+)/, '$1m$2'),
  31. small: response.avatar.replace(/(\/)[a-z](_[0-9]+)/, '$1m$2'),
  32. big: response.avatar
  33. } : {};
  34. },
  35.  
  36. destroy: function() {
  37. this.resetToDefaults();
  38. this.avatarExists = false;
  39.  
  40. return this.constructor.__super__.destroy.apply(this, arguments);
  41. }
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement