codecombat/app/views/kinds/UserView.coffee

49 lines
1.2 KiB
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 @, 'userLoaded', @onUserLoaded
@listenTo @, 'userNotFound', @ifUserNotFound
@userID ?= me.id # TODO Ruben really?
@fetchUser @userID
# TODO Ruben make this use the new getByNameOrID as soon as that is merged in
fetchUser: (id) ->
User.getByID id, {}, true,
success: (@user) =>
2014-07-21 16:02:08 -04:00
@userLoaded = true
@trigger 'userNotFound' unless @user
@trigger 'userLoaded', @user
error: =>
2014-07-21 16:02:08 -04:00
@userLoaded = true
@trigger 'userNotFound'
getRenderData: ->
context = super()
2014-07-15 10:15:21 -04:00
context.viewName = @viewName
context.user = @user unless @user?.isAnonymous()
2014-07-21 16:02:08 -04:00
context.userLoaded = @userLoaded
context
isMe: -> @userID is me.id
onUserLoaded: ->
console.log 'onUserLoaded', @user
@render()
ifUserNotFound: ->
console.warn 'user not found'
@render()
2014-07-07 06:44:44 -04:00
onLoaded: ->
super()