mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-25 00:28:31 -05:00
45 lines
1.1 KiB
CoffeeScript
45 lines
1.1 KiB
CoffeeScript
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'
|
|
|
|
constructor: (options, @userID) ->
|
|
super options
|
|
|
|
@listenTo @, 'userLoaded', @onUserLoaded
|
|
@listenTo @, 'userNotFound', @ifUserNotFound
|
|
|
|
@userID ?= me.id
|
|
@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) =>
|
|
@trigger 'userNotFound' unless @user
|
|
@trigger 'userLoaded', @user
|
|
error: =>
|
|
console.debug 'Error while fetching user'
|
|
@trigger 'userNotFound'
|
|
|
|
getRenderData: ->
|
|
context = super()
|
|
context.currentUserView = 'Achievements'
|
|
context.user = @user unless @user?.isAnonymous()
|
|
context
|
|
|
|
isMe: -> @userID is me.id
|
|
|
|
onUserLoaded: ->
|
|
console.log 'onUserLoaded', @user
|
|
@render()
|
|
|
|
ifUserNotFound: ->
|
|
console.warn 'user not found'
|
|
@render()
|
|
|
|
onLoaded: ->
|
|
super()
|