MCPcopy Index your code
hub / github.com/codecombat/codecombat / forkModel

Method forkModel

app/views/editor/ForkModal.js:13–47  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

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
50ForkModal.prototype.id = 'fork-modal'

Callers

nothing calls this directly

Calls 11

schemaMethod · 0.80
hideLoadingMethod · 0.80
parseMethod · 0.80
navigateMethod · 0.80
showLoadingMethod · 0.45
setMethod · 0.45
getMethod · 0.45
saveMethod · 0.45
errorMethod · 0.45
successMethod · 0.45
hideMethod · 0.45

Tested by

no test coverage detected