2014-11-28 20:49:41 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/editor/level/component/new'
|
|
|
|
LevelComponent = require 'models/LevelComponent'
|
2014-11-28 20:49:41 -05:00
|
|
|
forms = require 'core/forms'
|
|
|
|
{me} = require 'core/auth'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class NewLevelComponentModal extends ModalView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'editor-level-component-new-modal'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
|
|
|
instant: false
|
|
|
|
modalWidthPercent: 60
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click #new-level-component-submit': 'makeNewLevelComponent'
|
|
|
|
'submit form': 'makeNewLevelComponent'
|
2014-08-27 15:24:03 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
makeNewLevelComponent: (e) ->
|
|
|
|
e.preventDefault()
|
|
|
|
system = @$el.find('#level-component-system').val()
|
|
|
|
name = @$el.find('#level-component-name').val()
|
|
|
|
component = new LevelComponent()
|
|
|
|
component.set 'system', system
|
|
|
|
component.set 'name', name
|
2014-09-16 23:19:52 -04:00
|
|
|
component.set 'code', component.get('code', true).replace(/AttacksSelf/g, name)
|
2014-01-03 13:32:13 -05:00
|
|
|
component.set 'permissions', [{access: 'owner', target: me.id}] # Private until saved in a published Level
|
2014-12-29 12:14:43 -05:00
|
|
|
res = component.save(null, {type: 'POST'}) # Override PUT so we can trigger postFirstVersion logic
|
2014-01-03 13:32:13 -05:00
|
|
|
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 =>
|
2014-04-25 17:30:06 -04:00
|
|
|
@supermodel.registerModel component
|
2014-01-03 13:32:13 -05:00
|
|
|
@hide()
|