-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpageScript.js
More file actions
83 lines (72 loc) · 2.39 KB
/
Copy pathpageScript.js
File metadata and controls
83 lines (72 loc) · 2.39 KB
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
prev = window.onload();
window.onload = () => {
prev && prev();
if(isLoggedIn()) {
checkGroupMembership();
}
}
function checkGroupMembership() {
getGroupIBelongTo().then(group_id => {
switchToUserScreen();
}).catch(err => {
reset_swaps();
swap("loginScreen", "groupJoinScreen");
});
}
function logInSignUp(type) {
const usernameElm = document.getElementById("username");
if(!checkWarnTextVal(usernameElm)) return;
const passwordElm = document.getElementById("password");
if(!checkWarnTextVal(passwordElm)) return;
const username = usernameElm.value;
const password = passwordElm.value;
login(username, password);
}
function joinGroupButton() {
const groupElm = document.getElementById("groupID");
if(!checkWarnTextVal(groupElm)) return;
const group_id = groupElm.value;
joinGroup(group_id).then(() => {
reset_swaps();
checkGroupMembership();
});
}
function createGroupButton() {
const groupElm = document.getElementById("groupID");
if(!checkWarnTextVal(groupElm)) return;
const group_id = groupElm.value;
// TODO: change your group id to this one
reset_swaps();
// checkGroupMembership();
}
function createTaskElement(task) {
const elm = document.createElement("div");
// add task properties to div
return elm;
}
function createRewardElement(reward) {
const elm = document.createElement("div");
// add task properties to div
return elm;
}
async function switchToUserScreen() {
reset_swaps();
swap("login_gui", "user_panel");
const myPoints = await getMyPoints();
const myTasks = await getTasksFromGroupIBelong();
const myRewards = await getRewardsFromGroupIBelong();
const userInfoTextElm = document.getElementById("userInfoText");
userInfoTextElm.innerHTML = `${username} - ${myPoints} points`;
const tasks = getTaskFromGroupIBelong(task);
const rewards = getRewardsFromGroupIBelong(task);
const task_container = document.getElementById("task_container");
const reward_container = document.getElementById("reward_container");
task_container.children = []
reward_container.children = []
for(const task of tasks) {
task_container.appendChild(createTaskElement(task));
}
for(const reward of rewards) {
task_container.appendChild(createRewardElement(reward));
}
}