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

51 lines
1.6 KiB
CoffeeScript
Raw Normal View History

CocoView = require 'views/core/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 'core/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'
subscriptions:
'editor:view-switched': 'onViewSwitched'
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
loadAchievements: ->
return if @loadingAchievements
@supermodel.loadCollection @achievements, 'achievements'
@loadingAchievements = true
@render()
2014-08-04 16:21:43 -04:00
getRenderData: ->
c = super()
c.achievements = @achievements
c.relatedID = @relatedID
c
onNewAchievementSaved: (achievement) ->
# We actually open the new tab in NewAchievementModal, so we don't replace this window.
#url = '/editor/achievement/' + (achievement.get('slug') or achievement.id)
#app.router.navigate(, {trigger: true}) # Let's open a new tab instead.
makeNewAchievement: ->
modal = new NewAchievementModal model: Achievement, modelLabel: 'Achievement', level: @level
modal.once 'model-created', @onNewAchievementSaved
@openModalView modal
onViewSwitched: (e) ->
# Lazily load.
return unless e.targetURL is '#related-achievements-view'
@loadAchievements()