codecombat/app/views/editor/level/systems/NewLevelSystemModal.coffee

37 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2014-07-17 20:22:26 -04:00
ModalView = require 'views/kinds/ModalView'
2014-01-03 13:32:13 -05:00
template = require 'templates/editor/level/system/new'
LevelSystem = require 'models/LevelSystem'
forms = require 'lib/forms'
{me} = require 'lib/auth'
module.exports = class NewLevelSystemModal extends ModalView
2014-06-30 22:16:26 -04:00
id: 'editor-level-system-new-modal'
2014-01-03 13:32:13 -05:00
template: template
instant: false
modalWidthPercent: 60
events:
'click #new-level-system-submit': 'makeNewLevelSystem'
'submit form': 'makeNewLevelSystem'
makeNewLevelSystem: (e) ->
e.preventDefault()
system = @$el.find('#level-system-system').val()
name = @$el.find('#level-system-name').val()
system = new LevelSystem()
system.set 'name', name
system.set 'code', system.get('code').replace(/Jitter/g, name)
system.set 'permissions', [{access: 'owner', target: me.id}] # Private until saved in a published Level
res = system.save()
return unless res
@showLoading()
res.error =>
@hideLoading()
2014-06-30 22:16:26 -04:00
console.log 'Got errors:', JSON.parse(res.responseText)
2014-01-03 13:32:13 -05:00
forms.applyErrorsToForm(@$el, JSON.parse(res.responseText))
res.success =>
@supermodel.registerModel system
2014-01-03 13:32:13 -05:00
Backbone.Mediator.publish 'edit-level-system', original: system.get('_id'), majorVersion: 0
@hide()