mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Added missing ForkModal.
This commit is contained in:
parent
31e3e7f98e
commit
bdb3e14189
2 changed files with 60 additions and 0 deletions
17
app/templates/editor/fork-modal.jade
Normal file
17
app/templates/editor/fork-modal.jade
Normal 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...
|
43
app/views/editor/ForkModal.coffee
Normal file
43
app/views/editor/ForkModal.coffee
Normal 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})
|
Loading…
Reference in a new issue