-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-save.js
98 lines (79 loc) · 2.82 KB
/
index-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
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
sessionData = {
Username: "undefined",
Application: "undefined",
PlayMins: 0,
Score: 0,
Level: 0,
Date: "0001-01-01"
}
function updateSession(input, origin) {
alert(`Updating session, code: ${input}`);
let dropdown;
switch (input) {
case "user":
dropdown = document.getElementById("dropdownUser");
sessionData.Username = dropdown.options[dropdown.selectedIndex].text;
//document.getElementById("test1").innerHTML = sessionData.Username;
break;
case "activity":
switch (origin) {
case "manual":
dropdown = document.getElementById("dropdownManualActivity");
sessionData.Application = dropdown.options[dropdown.selectedIndex].text;
break;
case "timer":
dropdown = document.getElementById("dropdownTimerActivity");
sessionData.Application = dropdown.options[dropdown.selectedIndex].text;
}
break;
case "time":
let playTime;
switch (origin) {
case "manual":
dropdown = document.getElementById("dropdownManualTime");
playTime = parseInt(dropdown.options[dropdown.selectedIndex].value, 10);
sessionData.PlayMins = playTime;
break;
case "timer":
dropdown = document.getElementById("saveTime").value;
playTime = parseInt(dropdown);
sessionData.PlayMins = playTime;
break;
}
//document.getElementById("test1").innerHTML = sessionData.PlayMins;
break;
}
}
function pushSessionData() {
if (sessionData.Username == ("undefined" || "Select user")) {
alert("Select a user to save data to!");
return;
} else if (sessionData.Application == "undefined") {
alert("Select an activity to log!");
return;
} else if (sessionData.PlayMins == 0) {
alert("You can't log 0 minutes of activity!");
return;
}
let d = new Date();
let today = d.toISOString();
today = today.slice(0, 10);
sessionData.Date = today;
sendToJSON(processUserData);
}
function sendToJSON(callback) {
//const url = "../json/users.json";
let newEntryNumber;
try {
newEntryNumber = Object.keys(allData[userID].data).length + 1;
} catch {
newEntryNumber = 0;
}
const request = new XMLHttpRequest();
allData[userID].data[newEntryNumber] = JSON.parse(JSON.stringify(sessionData));
console.log(allData);
//request.open('POST', url);
//request.setRequestHeader('Content-Type', 'application/json');
//request.send(JSON.stringify(allData));
callback();
}