2014-11-28 20:49:41 -05:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/common/user'
|
2014-07-06 14:45:27 -04:00
|
|
|
User = require 'models/User'
|
|
|
|
|
|
|
|
module.exports = class UserView extends RootView
|
|
|
|
template: template
|
|
|
|
className: 'user-view'
|
2014-07-15 10:15:21 -04:00
|
|
|
viewName: null # Used for the breadcrumbs
|
2014-07-06 14:45:27 -04:00
|
|
|
|
2014-07-21 13:49:16 -04:00
|
|
|
constructor: (@userID, options) ->
|
2014-07-06 15:10:28 -04:00
|
|
|
super options
|
2014-07-09 12:12:31 -04:00
|
|
|
@listenTo @, 'userNotFound', @ifUserNotFound
|
2014-07-14 06:14:43 -04:00
|
|
|
@fetchUser @userID
|
|
|
|
|
2014-08-14 11:25:41 -04:00
|
|
|
fetchUser: ->
|
2014-08-07 16:03:00 -04:00
|
|
|
if @isMe()
|
|
|
|
@user = me
|
|
|
|
@onLoaded()
|
2014-08-14 11:25:41 -04:00
|
|
|
@user = new User _id: @userID
|
2015-02-11 16:12:42 -05:00
|
|
|
@supermodel.loadModel @user, 'user', cache: false
|
2014-07-06 15:10:28 -04:00
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
2014-07-15 10:15:21 -04:00
|
|
|
context.viewName = @viewName
|
2014-07-09 12:12:31 -04:00
|
|
|
context.user = @user unless @user?.isAnonymous()
|
2014-07-06 15:10:28 -04:00
|
|
|
context
|
|
|
|
|
2014-09-30 13:53:01 -04:00
|
|
|
isMe: -> @userID in [me.id, me.get('slug')]
|
2014-07-06 16:48:33 -04:00
|
|
|
|
2014-08-07 16:03:00 -04:00
|
|
|
onLoaded: ->
|
2014-08-14 11:25:41 -04:00
|
|
|
@onUserLoaded @user if @user.loaded and not @userLoaded
|
2014-08-07 16:03:00 -04:00
|
|
|
super()
|
2014-07-09 12:12:31 -04:00
|
|
|
|
2014-08-14 11:25:41 -04:00
|
|
|
onUserLoaded: ->
|
2014-09-30 13:53:01 -04:00
|
|
|
@userID = @user.id
|
2014-08-14 11:25:41 -04:00
|
|
|
@userLoaded = true
|
|
|
|
|
2014-07-09 12:12:31 -04:00
|
|
|
ifUserNotFound: ->
|
|
|
|
console.warn 'user not found'
|
2014-07-14 06:14:43 -04:00
|
|
|
@render()
|