Re: BaseUser.js

From disqus.com, 2 Months ago, written in JavaScript, viewed 3 times. This paste is a reply to Re: BaseUser.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/dc0c078f Embed
Download Paste or View Raw
  1. define('core/models/BaseUser',[
  2.     'backbone',
  3.  
  4.     'core/config',
  5. ], function (
  6.     Backbone,
  7.  
  8.     config
  9. ) {
  10.     'use strict';
  11.  
  12.     var BaseUser = Backbone.Model.extend({
  13.         defaults: {
  14.             about: null,
  15.             avatar: {
  16.                 // NOTE: the avatar URLs may not be defined at declaration-time, and
  17.                 //       might be modified by the host application later
  18.                 cache: config.urls.avatar.generic,
  19.                 permalink: config.urls.avatar.generic,
  20.             },
  21.             connections: {},
  22.             email: null,  // Should not be passed unless request is by moderator
  23.             isAnonymous: true,  // Anonymous by default
  24.             isFollowedBy: null,
  25.             isFollowing: null,
  26.             joinedAt: null,  // Date time in string. Format: YYYY-MM-DDTHH:mm:ss
  27.             name: null,
  28.             profileUrl: null,
  29.             url: null,
  30.             username: null,
  31.  
  32.             numPosts: null,
  33.             numFollowing: null,
  34.             numForumsFollowing: null,
  35.             numFollowers: null,
  36.             numLikesReceived: null,
  37.  
  38.             // optional, attached parameters, passed on request-by-request basis
  39.             isFlagged: null,
  40.         },
  41.  
  42.         hasValidAvatar: function (attrs) {
  43.             var avatar = attrs ? attrs.avatar : this.get('avatar');
  44.             return avatar && avatar.cache;
  45.         },
  46.  
  47.         isAnonymous: function () {
  48.             return !this.get('id');
  49.         },
  50.  
  51.         isRegistered: function () {
  52.             return !this.isAnonymous();
  53.         },
  54.  
  55.         validate: function (attrs) {
  56.             if (!this.hasValidAvatar(attrs))
  57.                 return 'None of the avatar related properties can be null, undefined or empty on User models.';
  58.         },
  59.  
  60.         toJSON: function () {
  61.             var data = Backbone.Model.prototype.toJSON.apply(this, arguments);
  62.             data.thread = {};
  63.  
  64.             // Validation does not have any effect if silent flag is set, like
  65.             // in the first initialization so we fix the value on toJSON for
  66.             // templates etc.
  67.             if (!this.hasValidAvatar())
  68.                 data.avatar = this.defaults.avatar;
  69.  
  70.             // Tell us if this user is a user w/ a registered account.
  71.             data.isRegistered = this.isRegistered();
  72.  
  73.             return data;
  74.         },
  75.     });
  76.  
  77.     return BaseUser;
  78. });
  79.  
  80. // https://c.disquscdn.com/next/next-core/core/models/BaseUser.js

Replies to Re: BaseUser.js rss

Title Name Language When
Re: Re: Session.js disqus.com javascript 2 Months ago.

Reply to "Re: BaseUser.js"

Here you can reply to the paste above