2014-11-28 20:49:41 -05:00
|
|
|
ModalView = require 'views/core/ModalView'
|
2014-08-13 17:26:41 -04:00
|
|
|
template = require 'templates/editor/fork-modal'
|
2014-11-28 20:49:41 -05:00
|
|
|
forms = require 'core/forms'
|
2014-08-13 17:26:41 -04:00
|
|
|
|
|
|
|
module.exports = class ForkModal extends ModalView
|
|
|
|
id: 'fork-modal'
|
|
|
|
template: template
|
|
|
|
instant: false
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click #fork-model-confirm-button': 'forkModel'
|
|
|
|
'submit form': 'forkModel'
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
|
|
|
@editorPath = options.editorPath # like 'level' or 'thang'
|
|
|
|
@model = options.model
|
|
|
|
@modelClass = @model.constructor
|
|
|
|
|
2014-08-21 15:49:06 -04:00
|
|
|
forkModel: (e) ->
|
|
|
|
e.preventDefault()
|
2014-08-13 17:26:41 -04:00
|
|
|
@showLoading()
|
|
|
|
forms.clearFormAlerts(@$el)
|
|
|
|
newModel = new @modelClass($.extend(true, {}, @model.attributes))
|
|
|
|
newModel.unset '_id'
|
|
|
|
newModel.unset 'version'
|
|
|
|
newModel.unset 'creator'
|
|
|
|
newModel.unset 'created'
|
|
|
|
newModel.unset 'original'
|
|
|
|
newModel.unset 'parent'
|
2015-03-20 16:19:38 -04:00
|
|
|
newModel.unset 'i18n'
|
2015-03-23 19:39:03 -04:00
|
|
|
newModel.unset 'i18nCoverage'
|
2014-08-13 17:26:41 -04:00
|
|
|
newModel.set 'commitMessage', "Forked from #{@model.get('name')}"
|
|
|
|
newModel.set 'name', @$el.find('#fork-model-name').val()
|
2014-09-08 19:03:29 -04:00
|
|
|
if @model.schema().properties.permissions
|
2014-08-13 17:26:41 -04:00
|
|
|
newModel.set 'permissions', [access: 'owner', target: me.id]
|
|
|
|
newPathPrefix = "editor/#{@editorPath}/"
|
2014-12-29 12:14:43 -05:00
|
|
|
res = newModel.save(null, {type: 'POST'}) # Override PUT so we can trigger postFirstVersion logic
|
2014-08-13 17:26:41 -04:00
|
|
|
return unless res
|
|
|
|
res.error =>
|
|
|
|
@hideLoading()
|
|
|
|
forms.applyErrorsToForm(@$el.find('form'), JSON.parse(res.responseText))
|
|
|
|
res.success =>
|
|
|
|
@hide()
|
|
|
|
application.router.navigate(newPathPrefix + newModel.get('slug'), {trigger: true})
|