Refactored profile view to be a userView. Would still like to test remarks though

This commit is contained in:
Ruben Vereecken 2014-07-14 12:14:43 +02:00
parent 9db84befa6
commit d261f888d7
4 changed files with 31 additions and 36 deletions

View file

@ -20,7 +20,7 @@ module.exports = class CocoRouter extends Backbone.Router
'user/:nameOrID(/:subview)': 'userView'
# account views
'account(/:subview)(/*rest)': 'accountView'
# 'account(/:subview)(/*rest)': 'accountView'
# Direct links
'test/*subpath': go('TestView')
@ -61,9 +61,6 @@ module.exports = class CocoRouter extends Backbone.Router
view.render()
@openView if view then view else @notFoundView()
accountView: (nameOrID, subview) ->
cache: {}
openRoute: (route) ->
route = route.split('?')[0]

View file

@ -6,17 +6,21 @@ module.exports = class UserView extends RootView
template: template
className: 'user-view'
constructor: (options, @nameOrID) ->
constructor: (options, @userID) ->
super options
@listenTo @, 'userLoaded', @onUserLoaded
@listenTo @, 'userNotFound', @ifUserNotFound
# TODO Ruben Assume ID for now
@user = User.getByID @nameOrID, {}, true,
success: (user) =>
@trigger 'userNotFound' unless user
@trigger 'userLoaded', user
@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'
@ -27,13 +31,15 @@ module.exports = class UserView extends RootView
context.user = @user unless @user?.isAnonymous()
context
isMe: -> @nameOrID is me.id
isMe: -> @userID is me.id
onUserLoaded: (user) ->
console.log 'onUserLoaded', user
onUserLoaded: ->
console.log 'onUserLoaded', @user
@render()
ifUserNotFound: ->
console.warn 'user not found'
@render()
onLoaded: ->
super()

View file

@ -13,8 +13,8 @@ module.exports = class UserAchievementsView extends UserView
events:
'userLoaded': 'onUserLoaded'
constructor: (options, nameOrID) ->
super options, nameOrID
constructor: (options, userID) ->
super options, userID
onUserLoaded: (user) ->
super user

View file

@ -1,4 +1,4 @@
View = require 'views/kinds/RootView'
UserView = require 'views/kinds/UserView'
template = require 'templates/account/profile'
User = require 'models/User'
LevelSession = require 'models/LevelSession'
@ -25,7 +25,7 @@ adminContacts = [
{id: '52a57252a89409700d0000d9', name: 'Ignore'}
]
module.exports = class ProfileView extends View
module.exports = class ProfileView extends UserView
id: 'profile-view'
template: template
subscriptions:
@ -50,8 +50,7 @@ module.exports = class ProfileView extends View
'click .editable-profile a': 'onClickLinkWhileEditing'
'change #admin-contact': 'onAdminContactChanged'
constructor: (options, @userID) ->
@userID ?= me.id
constructor: (options, userID) ->
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
@onRemarkChanged = _.debounce @onRemarkChanged, 1000
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
@ -60,31 +59,23 @@ module.exports = class ProfileView extends View
window.contractCallback = =>
@authorizedWithLinkedIn = IN?.User?.isAuthorized()
@render()
super options
if User.isObjectID @userID
@finishInit()
else
$.ajax "/db/user/#{@userID}/nameToID", success: (@userID) =>
@finishInit() unless @destroyed
@render()
super options, userID
onUserLoaded: ->
@finishInit() unless @destroyed
super()
finishInit: ->
console.debug 'finishing that init'
return unless @userID
@uploadFilePath = "db/user/#{@userID}"
@highlightedContainers = []
if @userID is me.id
@user = me
else if me.isAdmin() or 'employer' in me.get('permissions')
@user = User.getByID(@userID)
@user.fetch()
@listenTo @user, 'sync', =>
@render()
if me.isAdmin() or 'employer' in me.get('permissions')
$.post "/db/user/#{me.id}/track/view_candidate"
$.post "/db/user/#{@userID}/track/viewed_by_employer" unless me.isAdmin()
else
@user = User.getByID(@userID)
@sessions = @supermodel.loadCollection(new LevelSessionsCollection(@userID), 'candidate_sessions').model
if me.isAdmin()
console.debug 'fetching that remark'
# Mimicking how the VictoryModal fetches LevelFeedback
@remark = new UserRemark()
@remark.setURL "/db/user/#{@userID}/remark"
@ -282,7 +273,8 @@ module.exports = class ProfileView extends View
_.delay ->
justSavedSection.removeClass 'just-saved', duration: 1500, easing: 'easeOutQuad'
, 500
if me.isAdmin()
console.debug @user
if me.isAdmin() and @user
visibleSettings = ['history', 'tasks']
data = _.pick (@remark.attributes), (value, key) -> key in visibleSettings
data.history ?= []