codecombat/app/views/editor/level/versions.coffee

35 lines
996 B
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
View = require 'views/kinds/RootView'
template = require 'templates/editor/level/versions'
tableTemplate = require 'templates/editor/level/table'
Level = require 'models/Level'
class LevelVersionsCollection extends Backbone.Collection
url: '/db/level/'
model: Level
initialize: (@levelID) -> @url += levelID + '/versions'
module.exports = class LevelVersionsView extends View
id: "editor-level-versions-view"
template: template
startsLoading: true
constructor: (options, @levelID) ->
super options
@level = new Level(_id: @levelID)
@level.fetch()
@level.once('sync', @onLevelSync)
onLevelSync: =>
@collection = new LevelVersionsCollection(@level.attributes.original)
@collection.fetch()
2014-01-14 15:53:06 -05:00
@collection.on('sync', @onVersionFetched)
2014-01-03 13:32:13 -05:00
onVersionFetched: =>
@startsLoading = false
@render()
getRenderData: (context={}) =>
context = super(context)
context.levels = (m.attributes for m in @collection.models) if @collection
context