2014-07-06 14:45:27 -04:00
|
|
|
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
|
2014-07-06 14:45:27 -04:00
|
|
|
|
2014-07-14 06:14:43 -04:00
|
|
|
constructor: (options, @userID) ->
|
2014-07-06 15:10:28 -04:00
|
|
|
super options
|
|
|
|
|
2014-07-06 16:48:33 -04:00
|
|
|
@listenTo @, 'userLoaded', @onUserLoaded
|
2014-07-09 12:12:31 -04:00
|
|
|
@listenTo @, 'userNotFound', @ifUserNotFound
|
2014-07-06 14:45:27 -04:00
|
|
|
|
2014-07-14 06:14:43 -04:00
|
|
|
@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
|
2014-07-09 12:12:31 -04:00
|
|
|
error: =>
|
|
|
|
console.debug 'Error while fetching user'
|
|
|
|
@trigger 'userNotFound'
|
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-07-14 06:14:43 -04:00
|
|
|
isMe: -> @userID is me.id
|
2014-07-06 16:48:33 -04:00
|
|
|
|
2014-07-14 06:14:43 -04:00
|
|
|
onUserLoaded: ->
|
|
|
|
console.log 'onUserLoaded', @user
|
|
|
|
@render()
|
2014-07-09 12:12:31 -04:00
|
|
|
|
|
|
|
ifUserNotFound: ->
|
|
|
|
console.warn 'user not found'
|
2014-07-14 06:14:43 -04:00
|
|
|
@render()
|
2014-07-07 06:44:44 -04:00
|
|
|
|
|
|
|
onLoaded: ->
|
|
|
|
super()
|