codecombat/app/views/kinds/UserView.coffee

40 lines
894 B
CoffeeScript
Raw Normal View History

RootView = require 'views/kinds/RootView'
template = require 'templates/kinds/user'
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
constructor: (@userID, options) ->
super options
@listenTo @, 'userNotFound', @ifUserNotFound
@fetchUser @userID
2014-08-14 11:25:41 -04:00
fetchUser: ->
if @isMe()
@user = me
@onLoaded()
2014-08-14 11:25:41 -04:00
@user = new User _id: @userID
@supermodel.loadModel @user, 'user'
getRenderData: ->
context = super()
2014-07-15 10:15:21 -04:00
context.viewName = @viewName
context.user = @user unless @user?.isAnonymous()
context
isMe: -> @userID is me.id
onLoaded: ->
2014-08-14 11:25:41 -04:00
@onUserLoaded @user if @user.loaded and not @userLoaded
super()
2014-08-14 11:25:41 -04:00
onUserLoaded: ->
@userLoaded = true
ifUserNotFound: ->
console.warn 'user not found'
@render()