Got users and achievements to load in a neat way

This commit is contained in:
Ruben Vereecken 2014-07-06 22:48:33 +02:00
parent 10735867a4
commit 1b9c8b0066
4 changed files with 25 additions and 10 deletions

View 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"

View file

@ -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

View file

@ -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: ->

View file

@ -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