2021-11-23 02:11:16 +00:00
|
|
|
import * as Data from "../data.js";
|
2021-11-23 06:23:57 +00:00
|
|
|
import * as Form from "../form.js";
|
2021-11-23 02:11:16 +00:00
|
|
|
|
|
|
|
|
2021-11-23 06:23:57 +00:00
|
|
|
const submissionForm = document.getElementById('submission-form');
|
2021-11-23 02:11:16 +00:00
|
|
|
const sportDropdown = document.getElementById('sport-dropdown');
|
2021-11-23 06:23:57 +00:00
|
|
|
const genderDropdown = document.getElementById('gender-dropdown');
|
|
|
|
const nameTextbox = document.getElementById('name-textbox');
|
|
|
|
const submitButton = document.getElementById('submit-button');
|
|
|
|
const deleteButton = document.getElementById('delete-button');
|
2021-11-23 02:11:16 +00:00
|
|
|
|
2021-11-23 06:23:57 +00:00
|
|
|
|
|
|
|
async function initializeForm() {
|
|
|
|
let params = new URLSearchParams(location.search);
|
|
|
|
let divisionID = params.get('division');
|
|
|
|
if(divisionID) {
|
|
|
|
const division = await Data.getDivision(divisionID);
|
|
|
|
|
|
|
|
nameTextbox.value = division.name;
|
|
|
|
|
|
|
|
deleteButton.style.visibility = "visible";
|
|
|
|
deleteButton.disabled = false;
|
|
|
|
|
|
|
|
const gender = division.gender.name;
|
|
|
|
|
|
|
|
if(gender == 'female') genderDropdown.selectedIndex = 1;
|
|
|
|
else genderDropdown.selectedIndex = 2;
|
|
|
|
|
|
|
|
Form.populateSports(sportDropdown, division.sportID);
|
|
|
|
|
|
|
|
Form.addHiddenValue('division', divisionID, submissionForm);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Form.populateSports(sportDropdown);
|
|
|
|
|
|
|
|
genderDropdown.disabled = false;
|
|
|
|
|
|
|
|
sportDropdown.disabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nameTextbox.disabled = false;
|
|
|
|
nameTextbox.addEventListener('keyup', checkDataValidity);
|
|
|
|
}
|
|
|
|
initializeForm();
|
|
|
|
|
|
|
|
async function checkDataValidity() {
|
|
|
|
let dataIsValid = true;
|
|
|
|
|
|
|
|
if(!nameTextbox.value) dataIsValid = false;
|
|
|
|
|
2021-11-26 21:09:00 +00:00
|
|
|
const sportHasContent = sportDropdown.options.length;
|
|
|
|
const genderHasContent = genderDropdown.options.length;
|
|
|
|
|
|
|
|
if(!sportHasContent || !genderHasContent) dataIsValid = false;
|
|
|
|
|
2021-11-23 06:23:57 +00:00
|
|
|
|
|
|
|
if(dataIsValid) submitButton.disabled = false;
|
|
|
|
else submitButton.disabled = true;
|
2021-11-23 02:11:16 +00:00
|
|
|
}
|
2021-11-23 06:23:57 +00:00
|
|
|
|
|
|
|
Form.addRemoveFunction(deleteButton, submissionForm, "division");
|
|
|
|
|