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