mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 20:07:25 -05:00
37 lines
1.4 KiB
CoffeeScript
37 lines
1.4 KiB
CoffeeScript
UserView = require 'views/kinds/UserView'
|
|
template = require 'templates/user/achievements'
|
|
{me} = require 'lib/auth'
|
|
Achievement = require 'models/Achievement'
|
|
EarnedAchievement = require 'models/EarnedAchievement'
|
|
AchievementCollection = require 'collections/AchievementCollection'
|
|
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
|
|
|
|
module.exports = class AchievementsView extends UserView
|
|
id: 'user-achievements-view'
|
|
template: template
|
|
|
|
constructor: (userID, options) ->
|
|
super options, userID
|
|
|
|
onUserLoaded: (user) ->
|
|
@achievements = @supermodel.loadCollection(new AchievementCollection, 'achievements').model
|
|
@earnedAchievements = @supermodel.loadCollection(new EarnedAchievementCollection(@user), 'earnedAchievements').model
|
|
super user
|
|
|
|
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()
|
|
|
|
getRenderData: ->
|
|
context = super()
|
|
if @user and not @user.isAnonymous()
|
|
context.achievements = @achievements.models
|
|
context.earnedAchievements = @earnedAchievements.models
|
|
context
|