codecombat/app/views/play/level/modal/editor_config_modal.coffee

93 lines
3.2 KiB
CoffeeScript
Raw Normal View History

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:
language: 'javascript'
2014-03-13 21:09:11 -04:00
keyBindings: 'default'
invisibles: false
indentGuides: false
behaviors: false
2014-06-19 13:44:44 -04:00
liveCompletion: true
2014-03-13 19:54:06 -04:00
events:
'change #tome-invisibles': 'updateInvisibles'
'change #tome-language': 'updateLanguage'
'change #tome-key-bindings': 'updateKeyBindings'
'change #tome-indent-guides': 'updateIndentGuides'
'change #tome-behaviors': 'updateBehaviors'
2014-06-18 11:57:42 -04:00
'change #tome-live-completion': 'updateLiveCompletion'
2014-03-13 19:54:06 -04:00
constructor: (options) ->
super(options)
@session = options.session
2014-03-13 19:54:06 -04:00
getRenderData: ->
@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()
c.languages = [
{id: 'javascript', name: 'JavaScript'}
{id: 'coffeescript', name: 'CoffeeScript'}
{id: 'python', name: 'Python (Experimental)'}
{id: 'clojure', name: 'Clojure (Experimental)'}
{id: 'lua', name: 'Lua (Experimental)'}
{id: 'io', name: 'Io (Experimental)'}
]
c.sessionLanguage = @session.get('codeLanguage') ? @aceConfig.language
c.language = @aceConfig.language
2014-03-13 21:09:11 -04:00
c.keyBindings = @aceConfig.keyBindings
c.invisibles = @aceConfig.invisibles
c.indentGuides = @aceConfig.indentGuides
c.behaviors = @aceConfig.behaviors
2014-06-18 11:57:42 -04:00
c.liveCompletion = @aceConfig.liveCompletion
2014-03-13 19:54:06 -04:00
c
updateSessionLanguage: ->
@session.set 'codeLanguage', @$el.find('#tome-session-language').val()
updateLanguage: ->
@aceConfig.language = @$el.find('#tome-language').val()
updateInvisibles: ->
@aceConfig.invisibles = @$el.find('#tome-invisibles').prop('checked')
2014-03-13 21:09:11 -04:00
updateKeyBindings: ->
@aceConfig.keyBindings = @$el.find('#tome-key-bindings').val()
2014-03-13 21:09:11 -04:00
updateIndentGuides: ->
@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-06-18 11:57:42 -04:00
updateLiveCompletion: ->
@aceConfig.liveCompletion = @$el.find('#tome-live-completion').prop('checked')
2014-03-13 19:54:06 -04:00
afterRender: ->
super()
2014-03-13 21:09:11 -04:00
onHidden: ->
oldLanguage = @session.get('codeLanguage') ? @aceConfig.language
newLanguage = @$el.find('#tome-session-language').val()
@session.set 'codeLanguage', newLanguage
@aceConfig.language = @$el.find('#tome-language').val()
@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-06-18 11:57:42 -04:00
@aceConfig.liveCompletion = @$el.find('#tome-live-completion').prop('checked')
2014-03-13 21:09:11 -04:00
me.set 'aceConfig', @aceConfig
Backbone.Mediator.publish 'tome:change-config'
Backbone.Mediator.publish 'tome:change-language', language: newLanguage unless newLanguage is oldLanguage
@session.save() unless newLanguage is oldLanguage
me.patch()
2014-03-13 21:09:11 -04:00
2014-03-13 19:54:06 -04:00
destroy: ->
super()