diff --git a/public/scripts/data.js b/public/scripts/data.js index 27ba099..7e21436 100644 --- a/public/scripts/data.js +++ b/public/scripts/data.js @@ -20,4 +20,10 @@ export async function getDivisions(sportID, gender) { const response = await fetch(`/data/divisions?sport=${+sportID}&gender=${gender}`); const divisionsList = await response.json(); return divisionsList; +} + +export async function getTeams(sportID) { + const response = await fetch(`/data/teams?sport=${+sportID}`); + const teamsList = await response.json(); + return teamsList; } \ No newline at end of file diff --git a/public/scripts/submit.js b/public/scripts/submit.js index 678fa16..bd4d08a 100644 --- a/public/scripts/submit.js +++ b/public/scripts/submit.js @@ -5,6 +5,8 @@ const sportDropdown = document.getElementById('sport-dropdown'); const seasonDropdown = document.getElementById('year-dropdown'); const genderDropdown = document.getElementById('gender-dropdown'); const divisionDropdown = document.getElementById('division-dropdown'); +const team1Dropdown = document.getElementById('team1-dropdown'); +const team2Dropdown = document.getElementById('team2-dropdown'); @@ -37,6 +39,7 @@ async function listSports() { }); listGenders(); + listTeams(); } listSports(); @@ -76,9 +79,35 @@ async function listDivisions() { } } +async function listTeams() { + team1Dropdown.innerHTML = ""; + team2Dropdown.innerHTML = ""; + + const selectedSportID = sportDropdown.value; + + if(selectedSportID) { + const teamsList = await Data.getTeams(selectedSportID); + + teamsList.forEach(team => { + const optionT1 = document.createElement('option'); + optionT1.text = team.name; + optionT1.value = team.id; + team1Dropdown.appendChild(optionT1); + + const optionT2 = document.createElement('option'); + optionT2.text = team.name; + optionT2.value = team.id; + team2Dropdown.appendChild(optionT2); + }); + } +} -sportDropdown.onchange = listGenders; + +sportDropdown.onchange = (() => { + listGenders(); + listTeams(); +}); genderDropdown.onchange = listDivisions; \ No newline at end of file diff --git a/routes/data.js b/routes/data.js index 68a7e6d..fc6c947 100644 --- a/routes/data.js +++ b/routes/data.js @@ -4,6 +4,7 @@ var sports = require('../database/scores/sports'); var seasons = require('../database/scores/seasons'); var genders = require('../database/scores/genders'); var divisions = require('../database/scores/divisions'); +var teams = require('../database/scores/teams'); router.get('/sports', function(req, res, next) { @@ -28,4 +29,9 @@ router.get('/divisions', function(req, res, next) { .then(data => res.json(data)); }) +router.get('/teams', function(req, res, next) { + teams.retrieveBySport(req.query.sport) + .then(data => res.json(data)); +}) + module.exports = router; \ No newline at end of file