Fix supermodel with resource value and fix ladder view under supermodel resource management.

This commit is contained in:
Ting-Kuan 2014-04-19 13:06:47 -04:00
parent 375aca2c0a
commit 7321052c18
5 changed files with 11 additions and 28 deletions

View file

@ -192,7 +192,6 @@ class Resource extends Backbone.Model
@isLoaded = false
@model = null
@loadDeferred = null
@value = 1
addDependency: (depRes) ->
return if depRes.isLoaded
@ -282,8 +281,7 @@ class RequestResource extends Resource
class SomethingResource extends Resource
constructor: (name, value) ->
super(value)
@name = name
super(name, value)
@loadDeferred = $.Deferred()
load: ->

View file

@ -22,6 +22,7 @@ module.exports = class PatchesView extends CocoView
@patches = new PatchesCollection([], {}, @model, @status)
@patchesRes = @supermodel.addModelResource(@patches, 'patches')
@patchesRes.load()
@listenTo(@patchesRes, 'resource:loaded', @load)
load: ->
return unless @patchesRes.loaded
@ -48,7 +49,7 @@ module.exports = class PatchesView extends CocoView
reloadPatches: ->
@loaded = false
@initPatches()
@load()
# @load()
@render()
openPatchModal: (e) ->

View file

@ -89,16 +89,6 @@ module.exports = class LadderTabView extends CocoView
levelFrag = "#{@level.get('original')}.#{@level.get('version').major}"
url = "/db/level/#{levelFrag}/leaderboard_facebook_friends"
###
jqxhr = $.ajax url, {
data: { friendIDs: (f.id for f in @facebookData) }
method: 'POST'
success: @onFacebookFriendSessionsLoaded
}
@addRequestToLoad(jqxhr, 'facebook_friend_sessions', 'loadFacebookFriendSessions')
###
@fbFriendSessionRes = @supermodel.addRequestResource('facebook_friend_sessions', {
url: url
data: { friendIDs: (f.id for f in @facebookData) }
@ -140,14 +130,7 @@ module.exports = class LadderTabView extends CocoView
loadGPlusFriendSessions: ->
levelFrag = "#{@level.get('original')}.#{@level.get('version').major}"
url = "/db/level/#{levelFrag}/leaderboard_gplus_friends"
###
jqxhr = $.ajax url, {
data: { friendIDs: (f.id for f in @gplusData) }
method: 'POST'
success: @onGPlusFriendSessionsLoaded
}
@addRequestToLoad(jqxhr, 'gplus_friend_sessions', 'loadGPlusFriendSessions')
###
@gpFriendSessionRes = @supermodel.addRequestResource('gplus_friend_sessions', {
url: url
data: { friendIDs: (f.id for f in @gplusData) }
@ -172,10 +155,10 @@ module.exports = class LadderTabView extends CocoView
@leaderboards[team.id]?.destroy()
teamSession = _.find @sessions.models, (session) -> session.get('team') is team.id
@leaderboards[team.id] = new LeaderboardData(@level, team.id, teamSession)
# @addResourceToLoad @leaderboards[team.id], 'leaderboard', 3
@leaderboardRes = @supermodel.addModelResource(@leaderboards[team.id], 'leaderboard', 3)
@leaderboardRes.load()
onLoaded: -> @render()
render: ->
super()
@ -303,7 +286,6 @@ class LeaderboardData extends CocoClass
constructor: (@level, @team, @session) ->
super()
@fetch()
fetch: ->
@topPlayers = new LeaderboardCollection(@level, {order:-1, scoreOffset: HIGHEST_SCORE, team: @team, limit: @limit})

View file

@ -15,12 +15,15 @@ module.exports = class SimulateTabView extends CocoView
constructor: (options) ->
super(options)
@simulatorsLeaderboardData = new SimulatorsLeaderboardData(me)
@addResourceToLoad(@simulatorsLeaderboardData, 'top_simulators')
@simulatorsLeaderboardDataRes = @supermodel.addModelResource(@simulatorsLeaderboardData, 'top_simulators')
@simulatorsLeaderboardDataRes.load()
@simulator = new Simulator()
@listenTo(@simulator, 'statusUpdate', @updateSimulationStatus)
onLoaded: ->
super()
@render()
getRenderData: ->
ctx = super()
@ -81,7 +84,6 @@ class SimulatorsLeaderboardData extends CocoClass
constructor: (@me) ->
super()
@fetch()
fetch: ->
@topSimulators = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: -1, limit: 20})

View file

@ -48,7 +48,7 @@ module.exports = class LadderView extends RootView
onLoaded: ->
@teams = teamDataFromLevel @level
super()
@render()
getRenderData: ->
ctx = super()