-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes.js
224 lines (180 loc) · 8.09 KB
/
notes.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
function get_notes(userid) {
//gathers up notes about specific contact and displays them.
notelist.clear()
db.transaction(function (tx) {
var pull = tx.executeSql(
"SELECT * FROM Notes WHERE contactid='" + userid + "'")
if (pull.rows.length >= 1) {
var num = 0
while (num < pull.rows.length) {
var d = new Date(pull.rows.item(num).date)
notelist.append({
notetitle: pull.rows.item(num).title,
summary: pull.rows.item(num).information,
date: d.toLocaleString(),
origin: pull.rows.item(num).origin
})
num = num + 1
}
}
})
remote_sync(userid)
}
function save_note(userid, notename, information, origin) {
//saves and or updates note about contact
var thedate = new Date().getTime()
var insert = "INSERT INTO Notes VALUES(?,?,?,?,?)"
var thedata = [userid, notename, information, thedate, thedate]
var update = "UPDATE Notes SET title ='" + notename + "', information='"
+ information + "', date='" + thedate + "' WHERE origin=" + origin
+ " AND contactid='" + userid + "'"
db.transaction(function (tx) {
var pull = tx.executeSql("SELECT * FROM Notes WHERE 1")
if (origin !== 0) {
tx.executeSql(update)
upload_note(userid, notename, information, thedate, origin)
} else {
tx.executeSql(insert, thedata)
upload_note(userid, notename, information, thedate, thedate)
}
})
}
function get_note(userid, title) {
//retrieves and single note displays it.
db.transaction(function (tx) {
var pull = tx.executeSql("SELECT * FROM Notes WHERE contactid='"
+ userid + "' AND title ='" + title + "'")
if (pull.rows.length === 1) {
nN.noteTile = pull.rows.item(0).title
nN.noteBody = pull.rows.item(0).information
nN.noteOrigin = pull.rows.item(0).origin
}
})
}
function delete_note(cid, origin) {
//Deletes Note
console.log("deleting")
db.transaction(function (tx) {
var pull = tx.executeSql(
"SELECT * FROM Notes WHERE contactid='" + cid + "' AND origin =" + origin)
if (pull.rows.length === 1) {
tx.executeSql(
"DELETE FROM Notes WHERE contactid='" + cid + "' AND origin =" + origin)
var http = new XMLHttpRequest()
var url = "https://openseed.vagueentertainment.com:8675/corescripts/narrative.php"
http.onreadystatechange = function () {
if (http.readyState == 4) {
if (http.responseText === 100) {
console.log("Incorrect DevID")
} else if (http.responseText === 101) {
console.log("Incorrect AppID")
} else {
console.log(http.responseText)
get_notes(cid)
}
}
}
http.open('POST', url.trim(), true)
http.setRequestHeader("Content-type",
"application/x-www-form-urlencoded")
http.send("&id=" + userid + "&devid=" + devId + "&appid=" + appId
+ "&speaker=" + usercardNum + "::note::" + cid
+ "&room=" + origin + "&type=delete")
}
})
}
//Open Seed functionality
function upload_note(cid, notename, information, date, origin) {
var mesgdate = new Date()
var http = new XMLHttpRequest()
var url = "https://openseed.vagueentertainment.com:8675/corescripts/narrative.php"
http.onreadystatechange = function () {
if (http.readyState == 4) {
if (http.responseText === 100) {
console.log("Incorrect DevID")
} else if (http.responseText === 101) {
console.log("Incorrect AppID")
}
}
}
http.open('POST', url.trim(), true)
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
http.send("&id=" + userid + "&devid=" + devId + "&appid=" + appId + "&message=" + information
+ "&name=" + notename + "&speaker=" + usercardNum + "::note::" + cid
+ "&date=" + date + "&room=" + origin + "&type=sending")
}
function remote_sync(cid) {
var http = new XMLHttpRequest()
var url = "https://openseed.vagueentertainment.com:8675/corescripts/narrative.php"
http.onreadystatechange = function () {
if (http.readyState == 4) {
if (http.responseText === 100) {
console.log("Incorrect DevID")
} else if (http.responseText === 101) {
console.log("Incorrect AppID")
} else {
//console.log(http.responseText);
var num = 1
while (http.responseText.split("><").length > num) {
var note = http.responseText.split("><")[num]
db.transaction(function (tx) {
var search = tx.executeSql(
"SELECT * FROM `Notes` WHERE origin=" + note.split(
"::")[0] + " AND date=" + note.split(
"::")[1])
if (search.rows.length === 0) {
remote_get(note.split("::")[0], note.split("::")[1])
}
})
num = num + 1
}
}
}
}
http.open('POST', url.trim(), true)
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
http.send("&id=" + userid + "&devid=" + devId + "&appid=" + appId
+ "&speaker=" + usercardNum + "::note::" + cid + "&type=check")
}
function remote_get(origin, updated) {
var http = new XMLHttpRequest()
var url = "https://openseed.vagueentertainment.com:8675/corescripts/narrative.php"
http.onreadystatechange = function () {
if (http.readyState == 4) {
if (http.responseText === 100) {
console.log("Incorrect DevID")
} else if (http.responseText === 101) {
console.log("Incorrect AppID")
} else {
var num = 1
while (http.responseText.split("><").length > num) {
var note = http.responseText.split("><")[num]
var noteinfo = note.split(":;:")
db.transaction(function (tx) {
var search = tx.executeSql(
"SELECT * FROM `Notes` WHERE origin=" + noteinfo[0])
if (search.rows.length === 0) {
var insert = "INSERT INTO `Notes` VALUES(?,?,?,?,?)"
var thedata = [noteinfo[1].split(
"::")[2], noteinfo[3], noteinfo[2], noteinfo[4], noteinfo[0]]
tx.executeSql(insert, thedata)
get_notes(noteinfo[1].split("::")[2])
} else {
var update = "UPDATE Notes SET title ='" + noteinfo[3]
+ "', information='" + noteinfo[2] + "', date='"
+ noteinfo[4] + "' WHERE origin=" + noteinfo[0]
+ " AND contactid='" + noteinfo[1].split(
"::")[2] + "'"
get_notes(noteinfo[1].split("::")[2])
}
})
num = num + 1
}
}
}
}
http.open('POST', url.trim(), true)
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
http.send("&id=" + userid + "&devid=" + devId + "&appid=" + appId + "&room="
+ origin + "&date=" + updated + "&type=pull")
}