| 11 | } |
| 12 | |
| 13 | forkModel (e) { |
| 14 | e.preventDefault() |
| 15 | this.showLoading() |
| 16 | forms.clearFormAlerts(this.$el) |
| 17 | // eslint-disable-next-line new-cap |
| 18 | const newModel = new this.modelClass($.extend(true, {}, this.model.attributes)) |
| 19 | newModel.unset('_id') |
| 20 | newModel.unset('version') |
| 21 | newModel.unset('creator') |
| 22 | newModel.unset('created') |
| 23 | newModel.unset('original') |
| 24 | newModel.unset('parent') |
| 25 | newModel.unset('i18n') |
| 26 | newModel.unset('i18nCoverage') |
| 27 | newModel.unset('tasks') |
| 28 | newModel.set('commitMessage', `Forked from ${this.model.get('name')}`) |
| 29 | newModel.set('name', this.$el.find('#fork-model-name').val()) |
| 30 | if (this.model.get('kind') === 'Hero' || this.model.get('kind') === 'Junior Hero') { |
| 31 | newModel.set('releasePhase', 'beta') |
| 32 | } |
| 33 | if (this.model.schema().properties.permissions) { |
| 34 | newModel.set('permissions', [{ access: 'owner', target: me.id }]) |
| 35 | } |
| 36 | const newPathPrefix = `editor/${this.editorPath}/` |
| 37 | const res = newModel.save(null, { type: 'POST' }) // Override PUT so we can trigger postFirstVersion logic |
| 38 | if (!res) { return } |
| 39 | res.error(() => { |
| 40 | this.hideLoading() |
| 41 | forms.applyErrorsToForm(this.$el.find('form'), JSON.parse(res.responseText)) |
| 42 | }) |
| 43 | res.success(() => { |
| 44 | this.hide() |
| 45 | application.router.navigate(newPathPrefix + newModel.get('slug'), { trigger: true }) |
| 46 | }) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | ForkModal.prototype.id = 'fork-modal' |