2014-07-17 20:22:26 -04:00
|
|
|
ModalView = require 'views/kinds/ModalView'
|
2014-03-13 19:54:06 -04:00
|
|
|
template = require 'templates/play/level/modal/editor_config'
|
2014-06-30 22:16:26 -04:00
|
|
|
{me} = require 'lib/auth'
|
2014-03-13 19:54:06 -04:00
|
|
|
|
2014-07-17 20:22:26 -04:00
|
|
|
module.exports = class EditorConfigModal extends ModalView
|
2014-03-13 19:54:06 -04:00
|
|
|
id: 'level-editor-config-modal'
|
|
|
|
template: template
|
2014-03-13 21:09:11 -04:00
|
|
|
aceConfig: {}
|
|
|
|
|
|
|
|
defaultConfig:
|
2014-09-25 16:17:41 -04:00
|
|
|
language: 'python'
|
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-06-19 13:44:44 -04:00
|
|
|
liveCompletion: true
|
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-06-18 11:57:42 -04:00
|
|
|
'change #tome-live-completion': 'updateLiveCompletion'
|
2014-03-13 19:54:06 -04:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super(options)
|
2014-05-15 00:54:36 -04:00
|
|
|
@session = options.session
|
2014-03-13 19:54:06 -04:00
|
|
|
|
|
|
|
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-05-15 00:54:36 -04:00
|
|
|
c.languages = [
|
2014-09-25 16:17:41 -04:00
|
|
|
{id: 'python', name: 'Python'}
|
2014-05-15 00:54:36 -04:00
|
|
|
{id: 'javascript', name: 'JavaScript'}
|
|
|
|
{id: 'coffeescript', name: 'CoffeeScript'}
|
|
|
|
{id: 'clojure', name: 'Clojure (Experimental)'}
|
|
|
|
{id: 'lua', name: 'Lua (Experimental)'}
|
2014-05-26 11:59:48 -04:00
|
|
|
{id: 'io', name: 'Io (Experimental)'}
|
2014-05-15 00:54:36 -04:00
|
|
|
]
|
|
|
|
c.sessionLanguage = @session.get('codeLanguage') ? @aceConfig.language
|
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-06-18 11:57:42 -04:00
|
|
|
c.liveCompletion = @aceConfig.liveCompletion
|
2014-03-13 19:54:06 -04:00
|
|
|
c
|
|
|
|
|
2014-05-15 00:54:36 -04:00
|
|
|
updateSessionLanguage: ->
|
|
|
|
@session.set 'codeLanguage', @$el.find('#tome-session-language').val()
|
|
|
|
|
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-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: ->
|
2014-05-15 00:54:36 -04:00
|
|
|
oldLanguage = @session.get('codeLanguage') ? @aceConfig.language
|
|
|
|
newLanguage = @$el.find('#tome-session-language').val()
|
|
|
|
@session.set 'codeLanguage', newLanguage
|
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-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
|
2014-09-03 16:08:09 -04:00
|
|
|
Backbone.Mediator.publish 'tome:change-config', {}
|
2014-05-15 00:54:36 -04:00
|
|
|
Backbone.Mediator.publish 'tome:change-language', language: newLanguage unless newLanguage is oldLanguage
|
|
|
|
@session.save() unless newLanguage is oldLanguage
|
2014-06-11 17:17:31 -04:00
|
|
|
me.patch()
|
2014-03-13 21:09:11 -04:00
|
|
|
|
2014-03-13 19:54:06 -04:00
|
|
|
destroy: ->
|
|
|
|
super()
|