ModalRepoForm.js
987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { observable, useStrict, action } from 'mobx'
import EventEmitter from '../libs/eventEmitter'
import $ from 'jquery'
useStrict(true)
class ModalRepoFormStore {
@observable showNameError = false
@observable showModal = false
@observable name = ''
@action open() {
this.showModal = true
}
@action close() {
this.showModal = false
this.name = ""
}
@action handleChange(e) {
this.name = e.target.value
}
addRepo(headerStore, data) {
headerStore.addRepo(data)
}
@action save(e, name, headerStore) {
if (name.value.trim().length === 0) {
this.showNameError = true
return false
} else {
this.showNameError = false
e.preventDefault()
$.post('/regional_design/repos.json', { repo: {name: this.name} }, (data) => {
this.close()
this.addRepo(headerStore, data)
EventEmitter.dispatch('alert', '操作成功')
}, 'JSON')
}
}
}
export default new ModalRepoFormStore()