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/fork'
|
|
|
|
forms = require 'lib/forms'
|
|
|
|
Level = require 'models/Level'
|
|
|
|
|
2014-07-23 10:02:45 -04:00
|
|
|
module.exports = class ForkLevelModal extends ModalView
|
2014-06-30 22:16:26 -04:00
|
|
|
id: 'editor-level-fork-modal'
|
2014-01-03 13:32:13 -05:00
|
|
|
template: template
|
|
|
|
instant: false
|
|
|
|
modalWidthPercent: 60
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click #fork-level-confirm-button': 'forkLevel'
|
|
|
|
'submit form': 'forkLevel'
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@level = options.level
|
|
|
|
|
2014-02-11 17:58:45 -05:00
|
|
|
getRenderData: (context={}) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
context = super(context)
|
|
|
|
context.level = @level
|
|
|
|
context
|
|
|
|
|
|
|
|
forkLevel: ->
|
|
|
|
@showLoading()
|
|
|
|
forms.clearFormAlerts(@$el)
|
2014-03-18 16:08:26 -04:00
|
|
|
newLevel = new Level($.extend(true, {}, @level.attributes))
|
2014-01-03 13:32:13 -05:00
|
|
|
newLevel.unset '_id'
|
|
|
|
newLevel.unset 'version'
|
|
|
|
newLevel.unset 'creator'
|
|
|
|
newLevel.unset 'created'
|
|
|
|
newLevel.unset 'original'
|
|
|
|
newLevel.unset 'parent'
|
|
|
|
newLevel.set 'commitMessage', "Forked from #{@level.get('name')}"
|
|
|
|
newLevel.set 'name', @$el.find('#level-name').val()
|
|
|
|
newLevel.set 'permissions', [access: 'owner', target: me.id]
|
|
|
|
res = newLevel.save()
|
|
|
|
return unless res
|
|
|
|
res.error =>
|
|
|
|
@hideLoading()
|
|
|
|
forms.applyErrorsToForm(@$el.find('form'), JSON.parse(res.responseText))
|
|
|
|
res.success =>
|
|
|
|
@hide()
|
2014-01-07 02:45:33 -05:00
|
|
|
application.router.navigate('editor/level/' + newLevel.get('slug'), {trigger: true})
|