From bdb3e14189ba933bde6e64639f085f36d6c37bd1 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Wed, 13 Aug 2014 14:26:41 -0700 Subject: [PATCH] Added missing ForkModal. --- app/templates/editor/fork-modal.jade | 17 +++++++++++ app/views/editor/ForkModal.coffee | 43 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 app/templates/editor/fork-modal.jade create mode 100644 app/views/editor/ForkModal.coffee diff --git a/app/templates/editor/fork-modal.jade b/app/templates/editor/fork-modal.jade new file mode 100644 index 000000000..2b4db3463 --- /dev/null +++ b/app/templates/editor/fork-modal.jade @@ -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... diff --git a/app/views/editor/ForkModal.coffee b/app/views/editor/ForkModal.coffee new file mode 100644 index 000000000..5acbaa1df --- /dev/null +++ b/app/views/editor/ForkModal.coffee @@ -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})