-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.js
57 lines (53 loc) · 1.59 KB
/
save.js
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
46
47
48
49
50
51
52
53
54
55
56
57
const save = {
all() {
this.projects()
this.employees()
this.sheets()
},
projects() {
makeSaveRequest(JSON.stringify({data: projects.list, type: 'projects'}))
// console.log('saved')
// console.trace()
},
employees() {
makeSaveRequest(JSON.stringify({data: employees.list, type: 'employees'}))
// console.log('saved')
// console.trace()
},
sheets() {
makeSaveRequest(JSON.stringify({data: sheets, type: 'sheets'}))
},
renameDir(oldName, newName) {
this.dir({oldName, newName}, 'rename')
},
dir(data, location) {
const http = new XMLHttpRequest()
http.open('POST', window.location.href)
http.setRequestHeader('Content-Type', 'application/json; charset=UTF-8')
http.setRequestHeader('request', location)
http.send(data ? JSON.stringify(data) : '')
return new Promise(function(resolve) {
http.onreadystatechange = function() {
if(this.readyState == 4) resolve(null)
}
})
},
duplicateDir(name) {
return this.dir(name, 'duplicate')
},
newDir() {
return this.dir(null, 'newDir')
},
deleteDir(name) {
return this.dir(name, 'delete')
}
}
function makeSaveRequest(data) {
const http = new XMLHttpRequest()
http.open('POST', window.location.href)
http.setRequestHeader('Content-Type', 'application/json; charset=UTF-8')
http.setRequestHeader('request', mainDirectory)
http.send(data)
}
function makeRestoreRequest() {
}