2014-03-13 19:54:06 -04:00
|
|
|
View = require 'views/kinds/ModalView'
|
|
|
|
template = require 'templates/play/level/modal/editor_config'
|
|
|
|
{me} = require('lib/auth')
|
|
|
|
|
|
|
|
module.exports = class EditorConfigModal extends View
|
|
|
|
id: 'level-editor-config-modal'
|
|
|
|
template: template
|
2014-03-13 21:09:11 -04:00
|
|
|
aceConfig: {}
|
|
|
|
|
|
|
|
defaultConfig:
|
2014-03-15 17:00:29 -04:00
|
|
|
language: 'javascript'
|
2014-03-13 21:09:11 -04:00
|
|
|
keyBindings: 'default'
|
|
|
|
invisibles: false
|
|
|
|
indentGuides: false
|
2014-03-14 13:14:48 -04:00
|
|
|
behaviors: false
|
2014-03-13 19:54:06 -04:00
|
|
|
|
|
|
|
events:
|
2014-03-15 17:00:29 -04:00
|
|
|
'change #tome-invisibles': 'updateInvisibles'
|
|
|
|
'change #tome-language': 'updateLanguage'
|
|
|
|
'change #tome-key-bindings': 'updateKeyBindings'
|
2014-03-14 13:14:48 -04:00
|
|
|
'change #tome-indent-guides': 'updateIndentGuides'
|
|
|
|
'change #tome-behaviors': 'updateBehaviors'
|
2014-03-13 19:54:06 -04:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super(options)
|
|
|
|
|
|
|
|
getRenderData: ->
|
2014-03-14 10:46:36 -04:00
|
|
|
@aceConfig = _.cloneDeep me.get('aceConfig') ? {}
|
2014-03-13 21:09:11 -04:00
|
|
|
@aceConfig = _.defaults @aceConfig, @defaultConfig
|
2014-03-13 19:54:06 -04:00
|
|
|
c = super()
|
2014-03-15 17:00:29 -04:00
|
|
|
c.language = @aceConfig.language
|
2014-03-13 21:09:11 -04:00
|
|
|
c.keyBindings = @aceConfig.keyBindings
|
|
|
|
c.invisibles = @aceConfig.invisibles
|
|
|
|
c.indentGuides = @aceConfig.indentGuides
|
2014-03-14 13:14:48 -04:00
|
|
|
c.behaviors = @aceConfig.behaviors
|
2014-03-13 19:54:06 -04:00
|
|
|
c
|
|
|
|
|
2014-03-15 17:00:29 -04:00
|
|
|
updateLanguage: ->
|
|
|
|
@aceConfig.language = @$el.find('#tome-language').val()
|
|
|
|
|
|
|
|
updateInvisibles: ->
|
2014-03-14 13:14:48 -04:00
|
|
|
@aceConfig.invisibles = @$el.find('#tome-invisibles').prop('checked')
|
2014-03-13 21:09:11 -04:00
|
|
|
|
2014-03-15 17:00:29 -04:00
|
|
|
updateKeyBindings: ->
|
2014-03-14 13:14:48 -04:00
|
|
|
@aceConfig.keyBindings = @$el.find('#tome-key-bindings').val()
|
2014-03-13 21:09:11 -04:00
|
|
|
|
|
|
|
updateIndentGuides: ->
|
2014-03-14 13:14:48 -04:00
|
|
|
@aceConfig.indentGuides = @$el.find('#tome-indent-guides').prop('checked')
|
|
|
|
|
|
|
|
updateBehaviors: ->
|
|
|
|
@aceConfig.behaviors = @$el.find('#tome-behaviors').prop('checked')
|
2014-03-13 21:09:11 -04:00
|
|
|
|
2014-03-13 19:54:06 -04:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
|
2014-03-13 21:09:11 -04:00
|
|
|
onHidden: ->
|
2014-03-16 21:14:04 -04:00
|
|
|
oldLanguage = @aceConfig.language
|
2014-03-15 17:00:29 -04:00
|
|
|
@aceConfig.language = @$el.find('#tome-language').val()
|
2014-03-14 13:14:48 -04:00
|
|
|
@aceConfig.invisibles = @$el.find('#tome-invisibles').prop('checked')
|
|
|
|
@aceConfig.keyBindings = @$el.find('#tome-key-bindings').val()
|
|
|
|
@aceConfig.indentGuides = @$el.find('#tome-indent-guides').prop('checked')
|
|
|
|
@aceConfig.behaviors = @$el.find('#tome-behaviors').prop('checked')
|
2014-03-13 21:09:11 -04:00
|
|
|
me.set 'aceConfig', @aceConfig
|
2014-03-16 21:14:04 -04:00
|
|
|
Backbone.Mediator.publish 'tome:change-config'
|
2014-03-28 09:42:08 -04:00
|
|
|
Backbone.Mediator.publish 'tome:change-language' unless @aceConfig.language isnt oldLanguage
|
2014-03-13 21:09:11 -04:00
|
|
|
me.save()
|
|
|
|
|
2014-03-13 19:54:06 -04:00
|
|
|
destroy: ->
|
|
|
|
super()
|