Improve loading for editing divisions
parent
3a54ce0d56
commit
29605613c0
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Reference in New Issue