This commit is contained in:
Scott Erickson 2014-08-13 14:40:10 -07:00
commit f9e33a200a
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,17 @@
extends /templates/modal/modal_base
block modal-header-content
h3(data-i18n="editor.fork_title") Fork New Version
block modal-body-content
form.form
.form-group
label(for="model-name", data-i18n="general.name") Name
input#fork-model-name(name="name", type="text").form-control
block modal-footer-content
button.btn(data-dismiss="modal", data-i18n="common.cancel") Cancel
button.btn.btn-primary#fork-model-confirm-button(data-i18n="common.save") Save
block modal-body-wait-content
h3(data-i18n="editor.fork_creating") Creating Fork...

View file

@ -0,0 +1,43 @@
ModalView = require 'views/kinds/ModalView'
template = require 'templates/editor/fork-modal'
forms = require 'lib/forms'
module.exports = class ForkModal extends ModalView
id: 'fork-modal'
template: template
instant: false
modalWidthPercent: 60
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
forkModel: ->
@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'
newModel.set 'commitMessage', "Forked from #{@model.get('name')}"
newModel.set 'name', @$el.find('#fork-model-name').val()
if @model.get 'permissions'
newModel.set 'permissions', [access: 'owner', target: me.id]
newPathPrefix = "editor/#{@editorPath}/"
res = newModel.save()
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})