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

41 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2014-08-04 16:21:43 -04:00
CocoView = require 'views/kinds/CocoView'
template = require 'templates/editor/level/related-achievements'
2014-08-04 16:21:43 -04:00
RelatedAchievementsCollection = require 'collections/RelatedAchievementsCollection'
Achievement = require 'models/Achievement'
NewAchievementModal = require './modals/NewAchievementModal'
app = require 'application'
2014-08-04 16:21:43 -04:00
module.exports = class RelatedAchievementsView extends CocoView
id: 'related-achievements-view'
template: template
className: 'tab-pane'
events:
'click #new-achievement-button': 'makeNewAchievement'
2014-08-04 16:21:43 -04:00
constructor: (options) ->
super options
@level = options.level
@relatedID = @level.get('original')
2014-08-04 16:21:43 -04:00
@achievements = new RelatedAchievementsCollection @relatedID
@supermodel.loadCollection @achievements, 'achievements'
onLoaded: ->
console.debug 'related achievements loaded'
@achievements.loading = false
2014-08-04 16:21:43 -04:00
super()
getRenderData: ->
c = super()
c.achievements = @achievements
c.relatedID = @relatedID
c
onNewAchievementSaved: (achievement) ->
app.router.navigate('/editor/achievement/' + (achievement.get('slug') or achievement.id), {trigger: true})
makeNewAchievement: ->
modal = new NewAchievementModal model: Achievement, modelLabel: 'Achievement', level: @level
modal.once 'model-created', @onNewAchievementSaved
@openModalView modal