codecombat/app/views/user/achievements.coffee

38 lines
1.4 KiB
CoffeeScript
Raw Normal View History

UserView = require 'views/kinds/UserView'
template = require 'templates/user/achievements'
{me} = require 'lib/auth'
Achievement = require 'models/Achievement'
2014-07-06 17:38:57 -04:00
EarnedAchievement = require 'models/EarnedAchievement'
AchievementCollection = require 'collections/AchievementCollection'
2014-07-06 17:38:57 -04:00
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
2014-07-06 17:16:00 -04:00
module.exports = class UserAchievementsView extends UserView
id: 'user-achievements-view'
template: template
constructor: (options, userID) ->
super options, userID
onUserLoaded: (user) ->
2014-07-07 06:44:44 -04:00
super user
2014-07-07 09:03:28 -04:00
@achievements = @supermodel.loadCollection(new AchievementCollection, 'achievements').model
@earnedAchievements = @supermodel.loadCollection(new EarnedAchievementCollection(@user), 'earnedAchievements').model
2014-07-07 06:44:44 -04:00
onLoaded: ->
console.log @earnedAchievements
console.log 'onLoaded'
_.each @earnedAchievements.models, (earned) =>
console.log earned
return unless relatedAchievement = _.find @achievements.models, (achievement) ->
achievement.get('_id') is earned.get 'achievement'
relatedAchievement.set 'unlocked', true
earned.set 'achievement', relatedAchievement
super()
2014-07-07 09:03:28 -04:00
getRenderData: ->
context = super()
if @user and not @user.isAnonymous()
context.achievements = @achievements.models
context.earnedAchievements = @earnedAchievements.models
2014-07-07 09:03:28 -04:00
context