2014-07-06 14:45:27 -04:00
|
|
|
UserView = require 'views/kinds/UserView'
|
|
|
|
template = require 'templates/user/achievements'
|
|
|
|
{me} = require 'lib/auth'
|
2014-07-06 16:48:33 -04:00
|
|
|
Achievement = require 'models/Achievement'
|
2014-07-06 17:38:57 -04:00
|
|
|
EarnedAchievement = require 'models/EarnedAchievement'
|
2014-07-06 16:48:33 -04:00
|
|
|
AchievementCollection = require 'collections/AchievementCollection'
|
2014-07-06 17:38:57 -04:00
|
|
|
EarnedAchievementCollection = require 'collections/EarnedAchievementCollection'
|
2014-07-06 14:45:27 -04:00
|
|
|
|
2014-07-21 13:49:16 -04:00
|
|
|
module.exports = class AchievementsView extends UserView
|
2014-07-06 14:45:27 -04:00
|
|
|
id: 'user-achievements-view'
|
|
|
|
template: template
|
|
|
|
|
2014-07-21 13:49:16 -04:00
|
|
|
constructor: (userID, options) ->
|
2014-07-14 06:14:43 -04:00
|
|
|
super options, userID
|
2014-07-06 16:48:33 -04:00
|
|
|
|
|
|
|
onUserLoaded: (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-21 13:06:22 -04:00
|
|
|
super user
|
2014-07-07 06:44:44 -04:00
|
|
|
|
2014-07-07 13:56:30 -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()
|
2014-07-09 12:12:31 -04:00
|
|
|
if @user and not @user.isAnonymous()
|
|
|
|
context.achievements = @achievements.models
|
|
|
|
context.earnedAchievements = @earnedAchievements.models
|
2014-07-07 09:03:28 -04:00
|
|
|
context
|