mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Got users and achievements to load in a neat way
This commit is contained in:
parent
10735867a4
commit
1b9c8b0066
4 changed files with 25 additions and 10 deletions
7
app/collections/AchievementCollection.coffee
Normal file
7
app/collections/AchievementCollection.coffee
Normal file
|
@ -0,0 +1,7 @@
|
|||
CocoCollection = require 'collections/CocoCollection'
|
||||
|
||||
module.exports = class AchievementCollection extends CocoCollection
|
||||
|
||||
initialize: (me = require('lib/auth').me) ->
|
||||
@url = "/db/user/#{me.id}/achievements"
|
||||
|
|
@ -58,9 +58,6 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
return res
|
||||
else
|
||||
@addCollection collection
|
||||
@listenToOnce collection, 'sync', (c) ->
|
||||
console.debug 'Registering collection', url
|
||||
@registerCollection c
|
||||
res = @addModelResource(collection, name, fetchOptions, value)
|
||||
res.load() if not (res.isLoading or res.isLoaded)
|
||||
return res
|
||||
|
|
|
@ -9,11 +9,13 @@ module.exports = class UserView extends RootView
|
|||
constructor: (options, @nameOrID) ->
|
||||
super options
|
||||
|
||||
# TODO Ruben Assume ID for now
|
||||
@user = @supermodel.loadModel(new User(_id: nameOrID), 'user').model
|
||||
@listenTo @, 'userLoaded', @onUserLoaded
|
||||
|
||||
onLoaded: ->
|
||||
@render()
|
||||
# TODO Ruben Assume ID for now
|
||||
@user = User.getByID(@nameOrID, {}, true) # Force fetching a user isn't really the clean way to go
|
||||
@user.fetch
|
||||
success: =>
|
||||
@trigger 'userLoaded', @user
|
||||
|
||||
getRenderData: ->
|
||||
context = super()
|
||||
|
@ -21,4 +23,6 @@ module.exports = class UserView extends RootView
|
|||
context.user = @user
|
||||
context
|
||||
|
||||
isMe: -> @nameOrID is me.id
|
||||
isMe: -> @nameOrID is me.id
|
||||
|
||||
onUserLoaded: ->
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
UserView = require 'views/kinds/UserView'
|
||||
template = require 'templates/user/achievements'
|
||||
{me} = require 'lib/auth'
|
||||
Achievement = require 'models/Achievement'
|
||||
AchievementCollection = require 'collections/AchievementCollection'
|
||||
|
||||
module.exports = class UserAchievementsViewe extends UserView
|
||||
id: 'user-achievements-view'
|
||||
template: template
|
||||
|
||||
constructor: (options, @nameOrID) ->
|
||||
super options, @nameOrID
|
||||
events:
|
||||
'userLoaded': 'onUserLoaded'
|
||||
|
||||
constructor: (options, nameOrID) ->
|
||||
super options, nameOrID
|
||||
|
||||
onUserLoaded: (user) ->
|
||||
@achievements = @supermodel.loadCollection(new AchievementCollection(@user), 'achievements').model
|
||||
|
|
Loading…
Reference in a new issue