codecombat/app/views/editor/level/settings_tab_view.coffee
2014-03-07 13:13:58 -08:00

53 lines
1.7 KiB
CoffeeScript

View = require 'views/kinds/CocoView'
template = require 'templates/editor/level/settings_tab'
Level = require 'models/Level'
Surface = require 'lib/surface/Surface'
nodes = require './treema_nodes'
module.exports = class SettingsTabView extends View
id: 'editor-level-settings-tab-view'
className: 'tab-pane'
template: template
# not thangs or scripts or the backend stuff
editableSettings: [
'name', 'description', 'documentation', 'nextLevel', 'background', 'victory', 'i18n', 'icon', 'goals',
'type', 'showsGuide'
]
subscriptions:
'level-loaded': 'onLevelLoaded'
constructor: (options) ->
super options
@world = options.world
onLevelLoaded: (e) ->
@level = e.level
data = _.pick @level.attributes, (value, key) => key in @editableSettings
schema = _.cloneDeep Level.schema.attributes
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
schema.required = _.intersection schema.required, @editableSettings
thangIDs = @getThangIDs()
treemaOptions =
filePath: "db/level/#{@level.get('original')}"
supermodel: @supermodel
schema: schema
data: data
readOnly: true unless me.isAdmin() or @level.hasWriteAccess(me)
callbacks: {change: @onSettingsChanged}
thangIDs: thangIDs
nodeClasses:
thang: nodes.ThangNode
@settingsTreema = @$el.find('#settings-treema').treema treemaOptions
@settingsTreema.build()
@settingsTreema.open()
getThangIDs: ->
(t.id for t in @level.get('thangs') when t.id isnt 'Interface')
onSettingsChanged: (e) =>
$('.level-title').text @settingsTreema.data.name
for key in @editableSettings
@level.set key, @settingsTreema.data[key]