Add better loading for editing teams

main
sudoer777 2022-03-09 17:57:18 -07:00
parent 29605613c0
commit 8d830735ff
3 changed files with 19 additions and 3 deletions

View File

@ -14,14 +14,18 @@ async function initializeForm() {
let params = new URLSearchParams(location.search);
let teamID = params.get('team');
if(teamID) {
const team = await Data.getTeam(teamID);
const team = await (await fetch(`/fetch/manage/team?team=${teamID}`)).json();
nameTextbox.value = team.name;
deleteButton.style.visibility = "visible";
deleteButton.disabled = false;
Form.populateSports(sportDropdown, team.sportID);
let data = {};
data.sports = [team.sport];
data.latestGame = {sportID : team.sportID };
Form.populateSports(sportDropdown, null, data);
Form.addHiddenValue('team', teamID, submissionForm);
}

View File

@ -98,7 +98,7 @@ router.get('/team', async function(req, res, next) {
console.error("ERROR: " + err.message);
res.status(500).send("An error has occurred");
}
})
});
router.get('/games', async function(req, res, next) {
try {

View File

@ -158,6 +158,18 @@ router.get('/manage/teams', async function (req, res, next) {
res.json(data);
});
router.get('/manage/team', async function (req, res, next) {
try {
const teamID = req.query.team;
const data = await teams.getFromID(teamID);
data.sport = await sports.getFromID(data.sportID);
res.json(data);
} catch(err) {
console.error("ERROR: " + err.message);
res.status(500).send("An error has occurred");
}
});
router.get('/manage/games', checkLoginStatus.user, async function (req, res, next) {
try{
const userIsAdmin = req.user[2];