fixed teamlogic

This commit is contained in:
Jacob Levine 2019-03-07 19:31:34 -06:00
parent 060a77f4b7
commit 251390fddf
2 changed files with 35 additions and 5 deletions

View File

@ -32,12 +32,9 @@
<h2>Team Membership</h2>
<div id="newstuff">
<div>
<input type="button" name="CNT" value="Create New Team" class="btn" onclick="cnt(document.getElementById('ntn').value);">
<input type="text" name="TMN" value="" placeholder="Team Name" id="ntn">
</div>
<div>
<input type="button" name="CNT" value="Request to Join a Team" class="btn" onclick="reqjt(document.getElementById('etn').value);">
<input type="button" name="CNT" value="Request to Join a Team" class="btn" onclick="reqjt(document.getElementById('etn').value,document.getElementById('jcn').value);">
<input type="text" name="TMN" value="" placeholder="Team Name" id="etn">
<input type="text" name="JC" value="" placeholder="Join Code" id="jcn">
</div>
</div>
<table id="teammem">

View File

@ -47,6 +47,7 @@ window.onload = function() {
} else {
window.location.replace('../');
}
firebase.firestore.settings({timestampsInSnapshots: true})
teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid);
teamAssoc.get().then(function(doc) {
if (doc.exists) {
@ -85,6 +86,38 @@ function cnt(tn) {
})
})
}
function checkKeyMatch(dt,tn,key){
for(i=0; i<Object.keys(dt).length; i++){
if (Object.keys(dt)[i]=="code-"+key){
if (dt[Object.keys(dt)[i]]==tn){
return true
}
}
}
return false
}
function reqjt(tn,tc){
user=firebase.auth().currentUser;
dict=firebase.firestore().collection('teamData').doc('joinCodes').data();
if checkKeyMatch(dict,tn,tc){
push={};
push[tn]='scout';
firebase.firestore().collection("UserAssociations").doc(user.uid).set(push, {
merge: true
})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></tr>"
}
} else {
document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>"
}
})
}
}
function signout() {
var user = firebase.auth().currentUser;