Remove name from loadModel

This commit is contained in:
Imperadeiro98 2016-02-18 16:44:40 +00:00
parent 5353dcff3d
commit 92dc72cce1
30 changed files with 92 additions and 99 deletions

View file

@ -54,7 +54,7 @@ module.exports = class LevelLoader extends CocoClass
if @level.loaded
@onLevelLoaded()
else
@level = @supermodel.loadModel(@level, 'level').model
@level = @supermodel.loadModel(@level).model
@listenToOnce @level, 'sync', @onLevelLoaded
onLevelLoaded: ->
@ -86,12 +86,12 @@ module.exports = class LevelLoader extends CocoClass
session = new LevelSession().setURL url
session.project = ['creator', 'team', 'heroConfig', 'codeLanguage', 'submittedCodeLanguage', 'state'] if @headless
@sessionResource = @supermodel.loadModel(session, 'level_session', {cache: false})
@sessionResource = @supermodel.loadModel(session, {cache: false})
@session = @sessionResource.model
if @opponentSessionID
opponentSession = new LevelSession().setURL "/db/level.session/#{@opponentSessionID}"
opponentSession.project = session.project if @headless
@opponentSessionResource = @supermodel.loadModel(opponentSession, 'opponent_session', {cache: false})
@opponentSessionResource = @supermodel.loadModel(opponentSession, {cache: false})
@opponentSession = @opponentSessionResource.model
if @session.loaded
@ -130,7 +130,7 @@ module.exports = class LevelLoader extends CocoClass
heroConfig.thangType ?= '529ffbf1cf1818f2be000001' # If all else fails, assign Tharin as the hero.
session.set 'heroConfig', heroConfig unless _.isEqual heroConfig, session.get('heroConfig')
url = "/db/thang.type/#{heroConfig.thangType}/version"
if heroResource = @maybeLoadURL(url, ThangType, 'thang')
if heroResource = @maybeLoadURL(url, ThangType)
@worldNecessities.push heroResource
else
heroThangType = @supermodel.getModel url
@ -139,7 +139,7 @@ module.exports = class LevelLoader extends CocoClass
for itemThangType in _.values(heroConfig.inventory)
url = "/db/thang.type/#{itemThangType}/version?project=name,components,original,rasterIcon,kind"
if itemResource = @maybeLoadURL(url, ThangType, 'thang')
if itemResource = @maybeLoadURL(url, ThangType)
@worldNecessities.push itemResource
else
itemThangType = @supermodel.getModel url
@ -218,16 +218,16 @@ module.exports = class LevelLoader extends CocoClass
for obj in objUniq componentVersions
url = "/db/level.component/#{obj.original}/version/#{obj.majorVersion}"
worldNecessities.push @maybeLoadURL(url, LevelComponent, 'component')
worldNecessities.push @maybeLoadURL(url, LevelComponent)
for obj in objUniq systemVersions
url = "/db/level.system/#{obj.original}/version/#{obj.majorVersion}"
worldNecessities.push @maybeLoadURL(url, LevelSystem, 'system')
worldNecessities.push @maybeLoadURL(url, LevelSystem)
for obj in objUniq articleVersions
url = "/db/article/#{obj.original}/version/#{obj.majorVersion}"
@maybeLoadURL url, Article, 'article'
@maybeLoadURL url, Article
if obj = @level.get 'nextLevel' # TODO: update to get next level from campaigns, not this old property
url = "/db/level/#{obj.original}/version/#{obj.majorVersion}"
@maybeLoadURL url, Level, 'level'
@maybeLoadURL url, Level
@worldNecessities = @worldNecessities.concat worldNecessities
@ -250,7 +250,7 @@ module.exports = class LevelLoader extends CocoClass
console.error "Some Thang had a blank required ThangType in components list:", components
for thangType in extantRequiredThangTypes
url = "/db/thang.type/#{thangType}/version?project=name,components,original,rasterIcon,kind,prerenderedSpriteSheetData"
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
@worldNecessities.push @maybeLoadURL(url, ThangType)
onThangNamesLoaded: (thangNames) ->
for thangType in thangNames.models
@ -263,7 +263,7 @@ module.exports = class LevelLoader extends CocoClass
return unless components = thangType.get('components')
for component in components
url = "/db/level.component/#{component.original}/version/#{component.majorVersion}"
@worldNecessities.push @maybeLoadURL(url, LevelComponent, 'component')
@worldNecessities.push @maybeLoadURL(url, LevelComponent)
onWorldNecessityLoaded: (resource) ->
index = @worldNecessities.indexOf(resource)
@ -297,7 +297,7 @@ module.exports = class LevelLoader extends CocoClass
# thangType = nameModelMap[thangTypeName]
# continue if not thangType or thangType.isFullyLoaded()
# thangType.fetch()
# thangType = @supermodel.loadModel(thangType, 'thang').model
# thangType = @supermodel.loadModel(thangType).model
# res = @supermodel.addSomethingResource 'sprite_sheet', 5
# res.thangType = thangType
# res.markLoading()
@ -305,10 +305,10 @@ module.exports = class LevelLoader extends CocoClass
@buildLoopInterval = setInterval @buildLoop, 5 if @spriteSheetsToBuild.length
maybeLoadURL: (url, Model, resourceName) ->
maybeLoadURL: (url, Model) ->
return if @supermodel.getModel(url)
model = new Model().setURL url
@supermodel.loadModel(model, resourceName)
@supermodel.loadModel(model)
onSupermodelLoaded: ->
return if @destroyed

View file

@ -25,7 +25,7 @@ module.exports = class LevelSetupManager extends CocoClass
loadLevel: ->
levelURL = "/db/level/#{@options.levelID}"
@level = new Level().setURL levelURL
@level = @supermodel.loadModel(@level, 'level').model
@level = @supermodel.loadModel(@level).model
if @level.loaded then @onLevelSync() else @listenToOnce @level, 'sync', @onLevelSync
loadSession: ->
@ -33,7 +33,7 @@ module.exports = class LevelSetupManager extends CocoClass
#sessionURL += "?team=#{@team}" if @options.team # TODO: figure out how to get the teams for multiplayer PVP hero style
sessionURL += "?course=#{@options.courseID}" if @options.courseID
@session = new LevelSession().setURL sessionURL
@session = @supermodel.loadModel(@session, 'level_session').model
@session = @supermodel.loadModel(@session).model
if @session.loaded then @onSessionSync() else @listenToOnce @session, 'sync', @onSessionSync
onLevelSync: ->

View file

@ -27,11 +27,7 @@ module.exports = class SuperModel extends Backbone.Model
unfinished.push resource unless resource.isLoaded
unfinished
loadModel: (model, name, fetchOptions, value=1) ->
# Deprecating name. Handle if name is not included
value = fetchOptions if _.isNumber(fetchOptions)
fetchOptions = name if _.isObject(name)
loadModel: (model, fetchOptions, value=1) ->
# hero-ladder levels need remote opponent_session for latest session data (e.g. code)
# Can't apply to everything since other features rely on cached models being more recent (E.g. level_session)
# E.g.#2 heroConfig isn't necessarily saved to db in world map inventory modal, so we need to load the cached session on level start
@ -55,7 +51,7 @@ module.exports = class SuperModel extends Backbone.Model
# Deprecating name. Handle if name is not included
value = fetchOptions if _.isNumber(fetchOptions)
fetchOptions = name if _.isObject(name)
url = collection.getURL()
if cachedCollection = @collections[url]
console.debug 'Collection cache hit', url, 'already loaded', cachedCollection.loaded
@ -140,13 +136,13 @@ module.exports = class SuperModel extends Backbone.Model
# Tracking resources being loaded for this supermodel
finished: ->
return (@progress is 1.0) or (not @denom) or @failed
return (@progress is 1.0) or (not @denom) or @failed
addModelResource: (modelOrCollection, name, fetchOptions, value=1) ->
# Deprecating name. Handle if name is not included
value = fetchOptions if _.isNumber(fetchOptions)
fetchOptions = name if _.isObject(name)
modelOrCollection.saveBackups = modelOrCollection.saveBackups or @shouldSaveBackups(modelOrCollection)
@checkName(name)
res = new ModelResource(modelOrCollection, name, fetchOptions, value)
@ -160,7 +156,7 @@ module.exports = class SuperModel extends Backbone.Model
# Deprecating name. Handle if name is not included
value = jqxhrOptions if _.isNumber(jqxhrOptions)
jqxhrOptions = name if _.isObject(name)
@checkName(name)
res = new RequestResource(name, jqxhrOptions, value)
@storeResource(res, value)

View file

@ -14,7 +14,7 @@ module.exports = class AdministerUserModal extends ModalView
constructor: (options, @userHandle) ->
super(options)
@user = @supermodel.loadModel(new User({_id:@userHandle}), 'user', {cache: false}).model
@user = @supermodel.loadModel(new User({_id:@userHandle}), {cache: false}).model
options = {cache: false, url: '/stripe/coupons'}
options.success = (@coupons) =>
@couponsResource = @supermodel.addRequestResource('coupon', options)

View file

@ -60,8 +60,8 @@ module.exports = class ClanDetailsView extends RootView
@listenTo @memberAchievements, 'sync', @onMemberAchievementsSync
@listenTo @memberSessions, 'sync', @onMemberSessionsSync
@supermodel.loadModel @campaigns, 'campaigns', cache: false
@supermodel.loadModel @clan, 'clan', cache: false
@supermodel.loadModel @campaigns, cache: false
@supermodel.loadModel @clan, cache: false
@supermodel.loadCollection(@members, 'members', {cache: false})
@supermodel.loadCollection(@memberAchievements, 'member_achievements', {cache: false})
@ -204,7 +204,7 @@ module.exports = class ClanDetailsView extends RootView
unless @owner?
@owner = new User _id: @clan.get('ownerID')
@listenTo @owner, 'sync', => @render?()
@supermodel.loadModel @owner, 'owner', cache: false
@supermodel.loadModel @owner, cache: false
if @clan.get("dashboardType") is "premium"
@supermodel.loadCollection(@memberSessions, 'member_sessions', {cache: false})
@render?()

View file

@ -13,7 +13,7 @@ module.exports = class LevelSessionCodeView extends CocoView
@session = options.session
@level = LevelSession.getReferencedModel(@session.get('level'), LevelSession.schema.properties.level)
@level.setProjection ['employerDescription', 'name', 'icon', 'banner', 'slug']
@supermodel.loadModel @level, 'level'
@supermodel.loadModel @level
getRenderData: ->
c = super()

View file

@ -17,7 +17,7 @@ module.exports = class UserView extends RootView
@user = me
@onLoaded()
@user = new User _id: @userID
@supermodel.loadModel @user, 'user', cache: false
@supermodel.loadModel @user, cache: false
getRenderData: ->
context = super()

View file

@ -31,7 +31,7 @@ module.exports = class CourseDetailsView extends RootView
if @course.loaded
@onCourseSync()
else
@supermodel.loadModel @course, 'course'
@supermodel.loadModel @course
getRenderData: ->
context = super()
@ -67,7 +67,7 @@ module.exports = class CourseDetailsView extends RootView
if @campaign.loaded
@onCampaignSync()
else
@supermodel.loadModel @campaign, 'campaign'
@supermodel.loadModel @campaign
@render()
onCampaignSync: ->
@ -106,7 +106,7 @@ module.exports = class CourseDetailsView extends RootView
if @courseInstance.loaded
@onCourseInstanceSync()
else
@courseInstance = @supermodel.loadModel(@courseInstance, 'course_instance').model
@courseInstance = @supermodel.loadModel(@courseInstance).model
onCourseInstancesSync: ->
return if @destroyed
@ -128,14 +128,14 @@ module.exports = class CourseDetailsView extends RootView
# console.log 'onCourseInstanceSync'
if @courseInstance.get('classroomID')
@classroom = new Classroom({_id: @courseInstance.get('classroomID')})
@supermodel.loadModel @classroom, 'classroom'
@supermodel.loadModel @classroom
@singlePlayerMode = @courseInstance.get('name') is 'Single Player'
@teacherMode = @courseInstance.get('ownerID') is me.id and not @singlePlayerMode
@levelSessions = new CocoCollection([], { url: "/db/course_instance/#{@courseInstance.id}/level_sessions", model: LevelSession, comparator: '_id' })
@listenToOnce @levelSessions, 'sync', @onLevelSessionsSync
@supermodel.loadCollection @levelSessions, 'level_sessions', cache: false
@owner = new User({_id: @courseInstance.get('ownerID')})
@supermodel.loadModel @owner, 'user'
@supermodel.loadModel @owner
@render()
onLevelSessionsSync: ->
@ -192,7 +192,7 @@ module.exports = class CourseDetailsView extends RootView
if @nextCourseInstance
nextCourseID = @nextCourseInstance.get('courseID')
@nextCourse = @supermodel.getModel(Course, nextCourseID) or new Course _id: nextCourseID
@nextCourse = @supermodel.loadModel(@nextCourse, 'course').model
@nextCourse = @supermodel.loadModel(@nextCourse).model
else if @allCourses?.loaded
@nextCourse = _.find @allCourses.models, (course) => course.id > @course.id
else

View file

@ -46,7 +46,7 @@ module.exports = class HourOfCodeView extends RootView
if @lastSession
@lastLevel = new Level()
levelData = @lastSession.get('level')
@supermodel.loadModel(@lastLevel, 'level', {
@supermodel.loadModel(@lastLevel, {
url: "/db/level/#{levelData.original}/version/#{levelData.majorVersion}"
data: {
project: 'name,slug'

View file

@ -36,7 +36,7 @@ module.exports = class DeltaView extends CocoView
@[modelName] = options[modelName]
continue unless @[modelName] and options.loadModels
if not @[modelName].isLoaded
@[modelName] = @supermodel.loadModel(@[modelName], 'document').model
@[modelName] = @supermodel.loadModel(@[modelName]).model
@buildDeltas() if @supermodel.finished()

View file

@ -27,7 +27,7 @@ module.exports = class PatchModal extends ModalView
@originalSource = @targetModel.clone(false)
else
@originalSource = new @targetModel.constructor({_id:targetID})
@supermodel.loadModel @originalSource, 'source_document'
@supermodel.loadModel @originalSource
applyDelta: ->
@headModel = null

View file

@ -22,7 +22,7 @@ module.exports = class AchievementEditView extends RootView
super options
@achievement = new Achievement(_id: @achievementID)
@achievement.saveBackups = true
@supermodel.loadModel @achievement, 'achievement'
@supermodel.loadModel @achievement
@pushChangesToPreview = _.throttle(@pushChangesToPreview, 500)
onLoaded: ->

View file

@ -20,7 +20,7 @@ module.exports = class ArticleEditView extends RootView
super options
@article = new Article(_id: @articleID)
@article.saveBackups = true
@supermodel.loadModel @article, 'article'
@supermodel.loadModel @article
@pushChangesToPreview = _.throttle(@pushChangesToPreview, 500)
onLoaded: ->

View file

@ -32,7 +32,7 @@ module.exports = class CampaignEditorView extends RootView
constructor: (options, @campaignHandle) ->
super(options)
@campaign = new Campaign({_id:@campaignHandle})
@supermodel.loadModel(@campaign, 'campaign')
@supermodel.loadModel(@campaign)
@listenToOnce @campaign, 'sync', (model, response, jqXHR) ->
@campaign.set '_id', response._id
@campaign.url = -> '/db/campaign/' + @id
@ -72,7 +72,7 @@ module.exports = class CampaignEditorView extends RootView
thangType = new ThangType()
thangType.setProjection(thangTypeProject)
thangType.setURL("/db/thang.type/#{original}/version")
@supermodel.loadModel(thangType, 'thang')
@supermodel.loadModel(thangType)
onFundamentalLoaded: ->
# Load any levels which haven't been denormalized into our campaign.
@ -82,7 +82,7 @@ module.exports = class CampaignEditorView extends RootView
model = new Level({})
model.setProjection Campaign.denormalizedLevelProperties
model.setURL("/db/level/#{level.original}/version")
@levels.add @supermodel.loadModel(model, 'level').model
@levels.add @supermodel.loadModel(model).model
achievements = new RelatedAchievementsCollection level.original
achievements.setProjection achievementProject
@supermodel.loadCollection achievements, 'achievements'
@ -109,20 +109,20 @@ module.exports = class CampaignEditorView extends RootView
rewardObject.hero = reward
thangType = new ThangType({}, {project: thangTypeProject})
thangType.setURL("/db/thang.type/#{reward}/version")
@supermodel.loadModel(thangType, 'thang')
@supermodel.loadModel(thangType)
if rewardType is 'levels'
rewardObject.level = reward
if not @levels.findWhere({original: reward})
level = new Level({}, {project: Campaign.denormalizedLevelProperties})
level.setURL("/db/level/#{reward}/version")
@supermodel.loadModel(level, 'level')
@supermodel.loadModel(level)
if rewardType is 'items'
rewardObject.item = reward
thangType = new ThangType({}, {project: thangTypeProject})
thangType.setURL("/db/thang.type/#{reward}/version")
@supermodel.loadModel(thangType, 'thang')
@supermodel.loadModel(thangType)
rewards.push rewardObject
campaignLevel.rewards = rewards

View file

@ -71,7 +71,7 @@ module.exports = class ThangComponentsEditView extends CocoView
levelComponent = new LevelComponent(componentRef)
url = "/db/level.component/#{componentRef.original}/version/#{componentRef.majorVersion}"
levelComponent.setURL(url)
resource = @supermodel.loadModel levelComponent, 'component'
resource = @supermodel.loadModel levelComponent
continue unless resource.isLoading
@listenToOnce resource, 'loaded', ->
return if @handlingChange

View file

@ -30,7 +30,7 @@ module.exports = class SystemsTabView extends CocoView
for system in @buildDefaultSystems()
url = "/db/level.system/#{system.original}/version/#{system.majorVersion}"
ls = new LevelSystem().setURL(url)
@supermodel.loadModel(ls, 'system')
@supermodel.loadModel(ls)
afterRender: ->
@buildSystemsTreema()

View file

@ -30,7 +30,7 @@ module.exports = class VersionsModal extends ModalView
constructor: (options, @ID, @model) ->
super options
@original = new @model(_id: @ID)
@original = @supermodel.loadModel(@original, 'document').model
@original = @supermodel.loadModel(@original).model
@listenToOnce(@original, 'sync', @onViewSync)
onViewSync: ->

View file

@ -25,7 +25,7 @@ module.exports = class PollEditView extends RootView
loadPoll: ->
@poll = new Poll _id: @pollID
@poll.saveBackups = true
@supermodel.loadModel @poll, 'poll'
@supermodel.loadModel @poll
loadUserPollsRecord: ->
url = "/db/user.polls.record/-/user/#{me.id}"
@ -34,7 +34,7 @@ module.exports = class PollEditView extends RootView
return if @destroyed
@userPollsRecord.url = -> '/db/user.polls.record/' + @id
@listenToOnce @userPollsRecord, 'sync', onRecordSync
@userPollsRecord = @supermodel.loadModel(@userPollsRecord, 'user_polls_record').model
@userPollsRecord = @supermodel.loadModel(@userPollsRecord).model
onRecordSync.call @ if @userPollsRecord.loaded
onLoaded: ->

View file

@ -13,7 +13,7 @@ module.exports = class ThangTypeColorsTabView extends CocoView
constructor: (@thangType, options) ->
super options
@supermodel.loadModel @thangType, 'thang'
@supermodel.loadModel @thangType
@colorConfig = {hue: 0, saturation: 0.5, lightness: 0.5}
@spriteBuilder = new SpriteBuilder(@thangType) if @thangType.get('raw')
f = =>

View file

@ -174,7 +174,7 @@ module.exports = class ThangTypeEditView extends RootView
super options
@mockThang = $.extend(true, {}, @mockThang)
@thangType = new ThangType(_id: @thangTypeID)
@thangType = @supermodel.loadModel(@thangType, 'thang').model
@thangType = @supermodel.loadModel(@thangType).model
@thangType.saveBackups = true
@listenToOnce @thangType, 'sync', ->
@files = @supermodel.loadCollection(new DocumentFiles(@thangType), 'files').model

View file

@ -19,7 +19,7 @@ module.exports = class I18NEditModelView extends RootView
constructor: (options, @modelHandle) ->
super(options)
@model = new @modelClass(_id: @modelHandle)
@model = @supermodel.loadModel(@model, 'model').model
@model = @supermodel.loadModel(@model).model
@model.saveBackups = true
@selectedLanguage = me.get('preferredLanguage', true)
@ -172,7 +172,7 @@ module.exports = class I18NEditModelView extends RootView
# Override PUT so we can trigger postNewVersion logic
# or you're POSTing a Patch
type = 'POST'
res = modelToSave.save(null, {type: type})
res = modelToSave.save(null, {type: type})
return button.text('Failed to Submit Changes') unless res
button.text('Submitting...')
res.error => button.text('Error Submitting Changes')

View file

@ -41,7 +41,7 @@ module.exports = class LadderView extends RootView
constructor: (options, @levelID, @leagueType, @leagueID) ->
super(options)
@level = @supermodel.loadModel(new Level(_id: @levelID), 'level').model
@level = @supermodel.loadModel(new Level(_id: @levelID)).model
@sessions = @supermodel.loadCollection(new LevelSessionsCollection(@levelID), 'your_sessions', {cache: false}).model
@teams = []
@loadLeague()
@ -51,8 +51,7 @@ module.exports = class LadderView extends RootView
@leagueID = @leagueType = null unless @leagueType in ['clan', 'course']
return unless @leagueID
modelClass = if @leagueType is 'clan' then Clan else CourseInstance
resourceString = if @leagueType is 'clan' then 'clans.clan' else 'courses.course'
@league = @supermodel.loadModel(new modelClass(_id: @leagueID), resourceString).model
@league = @supermodel.loadModel(new modelClass(_id: @leagueID)).model
if @leagueType is 'course'
if @league.loaded
@onCourseInstanceLoaded @league
@ -62,7 +61,7 @@ module.exports = class LadderView extends RootView
onCourseInstanceLoaded: (courseInstance) ->
return if @destroyed
course = new Course({_id: courseInstance.get('courseID')})
@course = @supermodel.loadModel(course, 'courses.course').model
@course = @supermodel.loadModel(course).model
@listenToOnce @course, 'sync', @render
onLoaded: ->

View file

@ -13,7 +13,7 @@ module.exports = class ModelModal extends ModalView
super options
@models = options.models
for model in @models when not model.loaded
@supermodel.loadModel model, 'source_document'
@supermodel.loadModel model
model.fetch cache: false
afterRender: ->

View file

@ -82,7 +82,7 @@ module.exports = class CampaignView extends RootView
@campaign = new Campaign({_id:@terrain})
@campaign.saveBackups = @editorMode
@campaign = @supermodel.loadModel(@campaign, 'campaign').model
@campaign = @supermodel.loadModel(@campaign).model
# Temporary attempt to make sure all earned rewards are accounted for. Figure out a better solution...
@earnedAchievements = new CocoCollection([], {url: '/db/earned_achievement', model:EarnedAchievement, project: ['earnedRewards']})
@ -442,11 +442,11 @@ module.exports = class CampaignView extends RootView
preloadLevel: (levelSlug) ->
levelURL = "/db/level/#{levelSlug}"
level = new Level().setURL levelURL
level = @supermodel.loadModel(level, 'level', null, 0).model
level = @supermodel.loadModel(level, null, 0).model
sessionURL = "/db/level/#{levelSlug}/session"
@preloadedSession = new LevelSession().setURL sessionURL
@listenToOnce @preloadedSession, 'sync', @onSessionPreloaded
@preloadedSession = @supermodel.loadModel(@preloadedSession, 'level_session', {cache: false}).model
@preloadedSession = @supermodel.loadModel(@preloadedSession, {cache: false}).model
@preloadedSession.levelSlug = levelSlug
onSessionPreloaded: (session) ->
@ -604,7 +604,7 @@ module.exports = class CampaignView extends RootView
continue if @supermodel.getModel url
fullHero = new ThangType()
fullHero.setURL url
@supermodel.loadModel fullHero, 'thang'
@supermodel.loadModel fullHero
updateVolume: (volume) ->
volume ?= me.get('volume') ? 1.0
@ -675,7 +675,7 @@ module.exports = class CampaignView extends RootView
else
console.log 'Poll will be ready in', (22 * 60 * 60 * 1000 - interval) / (60 * 60 * 1000), 'hours.'
@listenToOnce @userPollsRecord, 'sync', onRecordSync
@userPollsRecord = @supermodel.loadModel(@userPollsRecord, 'user_polls_record', null, 0).model
@userPollsRecord = @supermodel.loadModel(@userPollsRecord, null, 0).model
onRecordSync.call @ if @userPollsRecord.loaded
loadPoll: ->
@ -693,7 +693,7 @@ module.exports = class CampaignView extends RootView
delete @poll
@listenToOnce @poll, 'sync', onPollSync
@listenToOnce @poll, 'error', onPollError
@poll = @supermodel.loadModel(@poll, 'poll', null, 0).model
@poll = @supermodel.loadModel(@poll, null, 0).model
onPollSync.call @ if @poll.loaded
activatePoll: ->

View file

@ -17,7 +17,7 @@ module.exports = class CourseVictoryModal extends ModalView
template: template
closesOnClickOutside: false
initialize: (options) ->
@courseID = options.courseID
@courseInstanceID = options.courseInstanceID
@ -27,7 +27,7 @@ module.exports = class CourseVictoryModal extends ModalView
@level = options.level
@newItems = new ThangTypes()
@newHeroes = new ThangTypes()
@achievements = options.achievements
if not @achievements
@achievements = new Achievements()
@ -36,18 +36,18 @@ module.exports = class CourseVictoryModal extends ModalView
@listenToOnce @achievements, 'sync', @onAchievementsLoaded
else
@onAchievementsLoaded()
@playSound 'victory'
@nextLevel = options.nextLevel
if (nextLevel = @level.get('nextLevel')) and not @nextLevel
@nextLevel = new Level().setURL "/db/level/#{nextLevel.original}/version/#{nextLevel.majorVersion}"
@nextLevel = @supermodel.loadModel(@nextLevel, 'level').model
@nextLevel = @supermodel.loadModel(@nextLevel).model
@campaign = new Campaign()
@course = options.course
if @courseID and not @course
@course = new Course().setURL "/db/course/#{@courseID}"
@course = @supermodel.loadModel(@course, 'course').model
@course = @supermodel.loadModel(@course).model
if @course.loading
@listenToOnce @course, 'sync', @onCourseLoaded
else
@ -58,16 +58,16 @@ module.exports = class CourseVictoryModal extends ModalView
if @courseInstanceID
@levelSessions = new LevelSessions()
@levelSessions.fetchForCourseInstance(@courseInstanceID)
@levelSessions = @supermodel.loadCollection(@levelSessions, 'sessions', {
@levelSessions = @supermodel.loadCollection(@levelSessions, 'sessions', {
data: { project: 'state.complete level.original playtime changed' }
}).model
onCourseLoaded: ->
@campaign.set('_id', @course.get('campaignID'))
@campaign = @supermodel.loadModel(@campaign, 'campaign').model
@campaign = @supermodel.loadModel(@campaign).model
onAchievementsLoaded: ->
@achievements.models = _.filter @achievements.models, (m) -> not m.get('query')?.ladderAchievementDifficulty # Don't show higher AI difficulty achievements
itemOriginals = []
@ -89,9 +89,9 @@ module.exports = class CourseVictoryModal extends ModalView
thang= new ThangType()
thang.url = "/db/thang.type/#{original}/version"
thang.project = project
@supermodel.loadModel(thang, 'thang')
@supermodel.loadModel(thang)
newThangTypeCollection.add(thang)
@newEarnedAchievements = []
for achievement in @achievements.models
continue unless achievement.completed
@ -108,25 +108,25 @@ module.exports = class CourseVictoryModal extends ModalView
model.sr.markLoaded()
if _.all((ea.id for ea in @newEarnedAchievements))
unless me.loading
@supermodel.loadModel(me, 'user', {cache: false})
@supermodel.loadModel(me, {cache: false})
@newEarnedAchievementsResource.markLoaded()
# have to use a something resource because addModelResource doesn't handle models being upserted/fetched via POST like we're doing here
@newEarnedAchievementsResource = @supermodel.addSomethingResource('earned achievements') if @newEarnedAchievements.length
onLoaded: ->
super()
@views = []
# TODO: Add main victory view
# TODO: Add level up view
# TODO: Add new hero view?
for newItem in @newItems.models
@views.push(new NewItemView({item: newItem}))
progressView = new ProgressView({
level: @level
nextLevel: @nextLevel
@ -134,15 +134,15 @@ module.exports = class CourseVictoryModal extends ModalView
campaign: @campaign
levelSessions: @levelSessions
})
progressView.once 'done', @onDone, @
progressView.once 'next-level', @onNextLevel, @
for view in @views
view.on 'continue', @onViewContinue, @
@views.push(progressView)
@showView(_.first(@views))
afterRender: ->
super()
@showView(@currentView)
@ -166,5 +166,3 @@ module.exports = class CourseVictoryModal extends ModalView
onDone: ->
link = "/courses/#{@courseID}/#{@courseInstanceID}"
application.router.navigate(link, {trigger: true})

View file

@ -66,10 +66,10 @@ module.exports = class HeroVictoryModal extends ModalView
if @level.get('type', true) is 'course'
if nextLevel = @level.get('nextLevel')
@nextLevel = new Level().setURL "/db/level/#{nextLevel.original}/version/#{nextLevel.majorVersion}"
@nextLevel = @supermodel.loadModel(@nextLevel, 'level').model
@nextLevel = @supermodel.loadModel(@nextLevel).model
if @courseID
@course = new Course().setURL "/db/course/#{@courseID}"
@course = @supermodel.loadModel(@course, 'course').model
@course = @supermodel.loadModel(@course).model
if @level.get('type', true) in ['course', 'course-ladder']
@saveReviewEventually = _.debounce(@saveReviewEventually, 2000)
@loadExistingFeedback()
@ -123,7 +123,7 @@ module.exports = class HeroVictoryModal extends ModalView
thangType.url = "/db/thang.type/#{thangTypeOriginal}/version"
#thangType.project = ['original', 'rasterIcon', 'name', 'soundTriggers', 'i18n'] # This is what we need, but the PlayHeroesModal needs more, and so we load more to fill up the supermodel.
thangType.project = ['original', 'rasterIcon', 'name', 'slug', 'soundTriggers', 'featureImages', 'gems', 'heroClass', 'description', 'components', 'extendedName', 'unlockLevelName', 'i18n']
@thangTypes[thangTypeOriginal] = @supermodel.loadModel(thangType, 'thang').model
@thangTypes[thangTypeOriginal] = @supermodel.loadModel(thangType).model
@newEarnedAchievements = []
hadOneCompleted = false

View file

@ -170,7 +170,7 @@ module.exports = class CastButtonView extends CocoView
url = "/db/level/#{@options.level.get('slug') or @options.level.id}/session"
url += "?team=#{if me.team is 'humans' then 'ogres' else 'humans'}"
mirrorSession = new LevelSession().setURL url
@mirrorSession = @supermodel.loadModel(mirrorSession, 'level_session', {cache: false}).model
@mirrorSession = @supermodel.loadModel(mirrorSession, {cache: false}).model
updateLadderSubmissionViews: ->
@removeSubView subview for key, subview of @subviews when subview instanceof LadderSubmissionView

View file

@ -21,7 +21,7 @@ module.exports = class LeaderboardModal extends ModalView
@levelSlug = @options.levelSlug
level = new Level({_id: @levelSlug})
level.project = ['name', 'i18n', 'scoreType', 'original']
@level = @supermodel.loadModel(level, 'level').model
@level = @supermodel.loadModel(level).model
getRenderData: (c) ->
c = super c

View file

@ -139,7 +139,7 @@ module.exports = class PlayHeroesModal extends ModalView
return fullHero
fullHero = new ThangType()
fullHero.setURL url
fullHero = (@supermodel.loadModel fullHero, 'thang').model
fullHero = (@supermodel.loadModel fullHero).model
fullHero
preloadHero: (heroIndex) ->

View file

@ -27,14 +27,14 @@ describe 'SuperModel', ->
it 'starts loading the model if it isn\'t already loading', ->
s = new SuperModel()
m = new User({_id: '12345'})
s.loadModel(m, 'user')
s.loadModel(m)
request = jasmine.Ajax.requests.mostRecent()
expect(request).toBeDefined()
it 'also loads collections', ->
s = new SuperModel()
c = new ComponentsCollection()
s.loadModel(c, 'collection')
s.loadModel(c)
request = jasmine.Ajax.requests.mostRecent()
expect(request).toBeDefined()
@ -44,7 +44,7 @@ describe 'SuperModel', ->
m = new User({_id: '12345'})
triggered = false
s.once 'loaded-all', -> triggered = true
s.loadModel(m, 'user')
s.loadModel(m)
request = jasmine.Ajax.requests.mostRecent()
request.respondWith({status: 200, responseText: '{}'})
_.defer ->