Improve loading for editing divisions

main
sudoer777 2022-03-09 16:55:07 -07:00
parent 3a54ce0d56
commit 29605613c0
2 changed files with 18 additions and 2 deletions

View File

@ -15,7 +15,7 @@ async function initializeForm() {
let params = new URLSearchParams(location.search);
let divisionID = params.get('division');
if(divisionID) {
const division = await Data.getDivision(divisionID);
const division = await (await fetch(`/fetch/manage/division?division=${divisionID}`)).json();
nameTextbox.value = division.name;
@ -27,7 +27,11 @@ async function initializeForm() {
if(gender == 'female') genderDropdown.selectedIndex = 1;
else genderDropdown.selectedIndex = 2;
Form.populateSports(sportDropdown, division.sportID);
let data = {};
data.sports = [division.sport];
data.latestGame = {sportID : division.sportID };
Form.populateSports(sportDropdown, null, data);
Form.addHiddenValue('division', divisionID, submissionForm);
}

View File

@ -136,6 +136,18 @@ router.get('/manage/divisions', async function (req, res, next) {
res.json(data);
});
router.get('/manage/division', async function (req, res, next) {
try {
const divisionID = req.query.division;
const data = await divisions.getFromID(divisionID);
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/teams', async function (req, res, next) {
const data = await teams.retrieve();