now you can leave teams

This commit is contained in:
Jacob Levine 2019-03-07 20:13:32 -06:00
parent c5dc49f442
commit 77231d00cc
2 changed files with 90 additions and 61 deletions

View File

@ -25,7 +25,7 @@ var uiConfig = {
// function.
// Terms of service url/callback.
tosUrl: function() {
alert("this is a test app. don't use it");
alert("this is a test app. don't use it. If you are a 2022 captian, you agree to name Jacob Levine as your successor.");
},
// Privacy policy url/callback.
privacyPolicyUrl: function() {

View File

@ -61,7 +61,9 @@ window.onload = function() {
}
})
});
firebase.firestore.settings({timestampsInSnapshots: true})
firebase.firestore.settings({
timestampsInSnapshots: true
})
}
function cnt(tn) {
@ -78,7 +80,7 @@ function cnt(tn) {
teamNums = Object.keys(list)
document.getElementById('teammem').innerHTML = ""
for (var i = 0; i < teamNums.length; i++) {
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td></tr>"
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td>" + "<td><input type='button' class='btn' value='leave' onclick='leaveTeam(" + teamNums[i] + ")'></td></tr>"
}
} else {
document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>"
@ -86,6 +88,7 @@ function cnt(tn) {
})
})
}
function checkKeyMatch(dt, tn, key) {
for (i = 0; i < Object.keys(dt).length; i++) {
if (Object.keys(dt)[i] == "code-" + key) {
@ -96,6 +99,7 @@ function checkKeyMatch(dt,tn,key){
}
return false
}
function reqjt(tn, tc) {
user = firebase.auth().currentUser;
firebase.firestore().collection('teamData').doc('joinCodes').get().then(function(doc) {
@ -114,7 +118,7 @@ function reqjt(tn,tc){
teamNums = Object.keys(list)
document.getElementById('teammem').innerHTML = ""
for (var i = 0; i < teamNums.length; i++) {
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td></tr>"
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td>" + "<td><input type='button' class='btn' value='leave' onclick='leaveTeam(" + teamNums[i] + ")'></td></tr>"
}
} else {
document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>"
@ -133,6 +137,31 @@ function reqjt(tn,tc){
}
function leaveTeam(tn) {
teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid)
teamAssoc.get().then(function(doc) {
if (doc.exists) {
list = doc.data()
delete list[tn]
firebase.firestore().collection("UserAssociations").doc(user.uid).set(list).then(function() {
teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid)
teamAssoc.get().then(function(doc) {
if (doc.exists) {
list = doc.data()
teamNums = Object.keys(list)
document.getElementById('teammem').innerHTML = ""
for (var i = 0; i < teamNums.length; i++) {
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td>" + "<td><input type='button' class='btn' value='leave' onclick='leaveTeam(" + teamNums[i] + ")'></td></tr>"
}
} else {
document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>"
}
})
})
)
}
}
function signout() {
var user = firebase.auth().currentUser;
firebase.auth().signOut().then(