Add better loading for editing teams
parent
29605613c0
commit
8d830735ff
|
@ -14,14 +14,18 @@ async function initializeForm() {
|
||||||
let params = new URLSearchParams(location.search);
|
let params = new URLSearchParams(location.search);
|
||||||
let teamID = params.get('team');
|
let teamID = params.get('team');
|
||||||
if(teamID) {
|
if(teamID) {
|
||||||
const team = await Data.getTeam(teamID);
|
const team = await (await fetch(`/fetch/manage/team?team=${teamID}`)).json();
|
||||||
|
|
||||||
nameTextbox.value = team.name;
|
nameTextbox.value = team.name;
|
||||||
|
|
||||||
deleteButton.style.visibility = "visible";
|
deleteButton.style.visibility = "visible";
|
||||||
deleteButton.disabled = false;
|
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);
|
Form.addHiddenValue('team', teamID, submissionForm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ router.get('/team', async function(req, res, next) {
|
||||||
console.error("ERROR: " + err.message);
|
console.error("ERROR: " + err.message);
|
||||||
res.status(500).send("An error has occurred");
|
res.status(500).send("An error has occurred");
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
router.get('/games', async function(req, res, next) {
|
router.get('/games', async function(req, res, next) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -158,6 +158,18 @@ router.get('/manage/teams', async function (req, res, next) {
|
||||||
res.json(data);
|
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) {
|
router.get('/manage/games', checkLoginStatus.user, async function (req, res, next) {
|
||||||
try{
|
try{
|
||||||
const userIsAdmin = req.user[2];
|
const userIsAdmin = req.user[2];
|
||||||
|
|
Reference in New Issue