mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-18 19:42:36 -05:00
47 lines
No EOL
1.4 KiB
CoffeeScript
47 lines
No EOL
1.4 KiB
CoffeeScript
View = require 'views/kinds/ModalView'
|
|
template = require 'templates/editor/level/fork'
|
|
forms = require 'lib/forms'
|
|
Level = require 'models/Level'
|
|
application = require('application')
|
|
|
|
module.exports = class LevelForkView extends View
|
|
id: "editor-level-fork-modal"
|
|
template: template
|
|
instant: false
|
|
modalWidthPercent: 60
|
|
modalTitle: "Fork New Version"
|
|
|
|
events:
|
|
'click #fork-level-confirm-button': 'forkLevel'
|
|
'submit form': 'forkLevel'
|
|
|
|
constructor: (options) ->
|
|
super options
|
|
@level = options.level
|
|
|
|
getRenderData: (context={}) =>
|
|
context = super(context)
|
|
context.level = @level
|
|
context
|
|
|
|
forkLevel: ->
|
|
@showLoading()
|
|
forms.clearFormAlerts(@$el)
|
|
newLevel = new Level(_.cloneDeep(@level.attributes))
|
|
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()
|
|
application.router.navigate('editor/level/' + newLevel.get('slug'), {trigger: true}) |