73 lines
3.2 KiB
JavaScript
73 lines
3.2 KiB
JavaScript
import * as Data from "./../data.js";
|
|
import * as Form from "./../form.js";
|
|
|
|
|
|
const submissionForm = document.getElementById('submission-form');
|
|
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 dateInput = document.getElementById('date-input');
|
|
const team1Dropdown = document.getElementById('team1-dropdown');
|
|
const team2Dropdown = document.getElementById('team2-dropdown');
|
|
const team1ScoreTextbox = document.getElementById('team1-score-textbox');
|
|
const team2ScoreTextbox = document.getElementById('team2-score-textbox');
|
|
const submitButton = document.getElementById('submit-button');
|
|
const deleteButton = document.getElementById('delete-button');
|
|
|
|
|
|
async function initializeForm() {
|
|
let params = new URLSearchParams(location.search);
|
|
let gameID = params.get('game');
|
|
if(gameID) {
|
|
deleteButton.style.visibility = "visible";
|
|
deleteButton.disabled = false;
|
|
|
|
const game = await Data.getGame(gameID);
|
|
|
|
Form.addHiddenValue('game', gameID, submissionForm);
|
|
|
|
Form.populateSeasons(seasonDropdown, game.seasonID);
|
|
Data.getDivision(game.divisionID)
|
|
.then(data => {
|
|
Form.populateSports(sportDropdown, data.sportID)
|
|
.then(() => {
|
|
Form.populateGenders(genderDropdown, sportDropdown.value, data.gender.name)
|
|
.then(() => {
|
|
Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value, game.divisionID);
|
|
});
|
|
Form.populateTeams(team1Dropdown, sportDropdown.value, game.team1ID);
|
|
Form.populateTeams(team2Dropdown, sportDropdown.value, game.team2ID);
|
|
});
|
|
});
|
|
dateInput.value = game.date;
|
|
team1ScoreTextbox.value = game.team1Score;
|
|
team2ScoreTextbox.value = game.team2Score;
|
|
}
|
|
else {
|
|
Form.populateSeasons(seasonDropdown);
|
|
Form.populateSports(sportDropdown)
|
|
.then(() => {
|
|
Form.populateGenders(genderDropdown, sportDropdown.value)
|
|
.then(() => {
|
|
Form.populateDivisions(divisionDropdown, sportDropdown.value, genderDropdown.value);
|
|
});
|
|
Form.populateTeams(team1Dropdown, sportDropdown.value);
|
|
Form.populateTeams(team2Dropdown, sportDropdown.value);
|
|
});
|
|
dateInput.value = (new Date()).toISOString().slice(0,10);
|
|
}
|
|
seasonDropdown.disabled = false;
|
|
sportDropdown.disabled = false;
|
|
genderDropdown.disabled = false;
|
|
divisionDropdown.disabled = false;
|
|
dateInput.disabled = false;
|
|
team1Dropdown.disabled = false;
|
|
team2Dropdown.disabled = false;
|
|
team1ScoreTextbox.disabled = false;
|
|
team2ScoreTextbox.disabled = false;
|
|
submitButton.disabled = false;
|
|
}
|
|
initializeForm();
|
|
|
|
Form.addRemoveFunction(deleteButton, submissionForm, "game");
|