codecombat/app/views/editor/level/settings/SettingsTabView.coffee

59 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2014-07-17 20:20:11 -04:00
CocoView = require 'views/kinds/CocoView'
2014-01-03 13:32:13 -05:00
template = require 'templates/editor/level/settings_tab'
Level = require 'models/Level'
Surface = require 'lib/surface/Surface'
nodes = require './../treema_nodes'
2014-05-06 19:58:08 -04:00
{me} = require 'lib/auth'
2014-01-03 13:32:13 -05:00
2014-07-17 20:20:11 -04:00
module.exports = class SettingsTabView extends CocoView
2014-01-03 13:32:13 -05:00
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', 'banner', 'employerDescription'
]
2014-01-03 13:32:13 -05:00
subscriptions:
'level-loaded': 'onLevelLoaded'
constructor: (options) ->
super options
2014-04-16 02:28:59 -04:00
onLoaded: ->
2014-01-03 13:32:13 -05:00
onLevelLoaded: (e) ->
@level = e.level
data = _.pick @level.attributes, (value, key) => key in @editableSettings
2014-04-12 04:35:56 -04:00
schema = _.cloneDeep Level.schema
2014-01-03 13:32:13 -05:00
schema.properties = _.pick schema.properties, (value, key) => key in @editableSettings
schema.required = _.intersection schema.required, @editableSettings
thangIDs = @getThangIDs()
2014-01-03 13:32:13 -05:00
treemaOptions =
filePath: "db/level/#{@level.get('original')}"
supermodel: @supermodel
schema: schema
data: data
readOnly: me.get('anonymous')
2014-01-03 13:32:13 -05:00
callbacks: {change: @onSettingsChanged}
thangIDs: thangIDs
nodeClasses:
object: SettingsNode
thang: nodes.ThangNode
2014-01-03 13:32:13 -05:00
@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')
2014-01-03 13:32:13 -05:00
onSettingsChanged: (e) =>
$('.level-title').text @settingsTreema.data.name
for key in @editableSettings
2014-06-03 15:27:53 -04:00
continue if @settingsTreema.data[key] is undefined
2014-01-03 13:32:13 -05:00
@level.set key, @settingsTreema.data[key]
class SettingsNode extends TreemaObjectNode
nodeDescription: 'Settings'