2014-08-04 16:21:43 -04:00
|
|
|
CocoView = require 'views/kinds/CocoView'
|
2014-08-08 11:14:57 -04:00
|
|
|
template = require 'templates/editor/level/related-achievements'
|
2014-08-04 16:21:43 -04:00
|
|
|
RelatedAchievementsCollection = require 'collections/RelatedAchievementsCollection'
|
|
|
|
Achievement = require 'models/Achievement'
|
2014-08-08 11:14:57 -04:00
|
|
|
NewAchievementModal = require './modals/NewAchievementModal'
|
2014-08-05 09:14:51 -04:00
|
|
|
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'
|
|
|
|
|
2014-08-05 09:14:51 -04:00
|
|
|
events:
|
|
|
|
'click #new-achievement-button': 'makeNewAchievement'
|
|
|
|
|
2014-08-04 16:21:43 -04:00
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2014-08-08 11:14:57 -04:00
|
|
|
@level = options.level
|
|
|
|
@relatedID = @level.id
|
2014-08-04 16:21:43 -04:00
|
|
|
@achievements = new RelatedAchievementsCollection @relatedID
|
|
|
|
@supermodel.loadCollection @achievements, 'achievements'
|
|
|
|
|
|
|
|
onLoaded: ->
|
|
|
|
console.debug 'related achievements loaded'
|
2014-08-05 08:33:33 -04:00
|
|
|
@achievements.loading = false
|
2014-08-04 16:21:43 -04:00
|
|
|
super()
|
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
|
|
|
c.achievements = @achievements
|
|
|
|
c.relatedID = @relatedID
|
|
|
|
c
|
2014-08-05 08:33:33 -04:00
|
|
|
|
2014-08-05 09:14:51 -04:00
|
|
|
onNewAchievementSaved: (achievement) ->
|
|
|
|
app.router.navigate('/editor/achievement/' + (achievement.get('slug') or achievement.id), {trigger: true})
|
|
|
|
|
|
|
|
makeNewAchievement: ->
|
2014-08-08 11:14:57 -04:00
|
|
|
modal = new NewAchievementModal model: Achievement, modelLabel: 'Achievement', level: @level
|
|
|
|
modal.once 'model-created', @onNewAchievementSaved
|
2014-08-05 09:14:51 -04:00
|
|
|
@openModalView modal
|