71 lines
2.1 KiB
JavaScript
71 lines
2.1 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 genderDropdown = document.getElementById('gender-dropdown');
|
|
const nameTextbox = document.getElementById('name-textbox');
|
|
const submitButton = document.getElementById('submit-button');
|
|
const deleteButton = document.getElementById('delete-button');
|
|
const loadingSpan = document.getElementById('loading-message');
|
|
|
|
|
|
async function initializeForm() {
|
|
let params = new URLSearchParams(location.search);
|
|
let divisionID = params.get('division');
|
|
if(divisionID) {
|
|
const division = await (await fetch(`/fetch/manage/division?division=${divisionID}`)).json();
|
|
|
|
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;
|
|
|
|
let data = {};
|
|
data.sports = [division.sport];
|
|
data.latestGame = {sportID : division.sportID };
|
|
|
|
Form.populateSports(sportDropdown, null, data);
|
|
|
|
Form.addHiddenValue('division', divisionID, submissionForm);
|
|
}
|
|
else {
|
|
Form.populateSports(sportDropdown);
|
|
|
|
genderDropdown.disabled = false;
|
|
|
|
sportDropdown.disabled = false;
|
|
}
|
|
|
|
nameTextbox.disabled = false;
|
|
nameTextbox.addEventListener('keyup', checkDataValidity);
|
|
|
|
loadingSpan.textContent = '';
|
|
submissionForm.style.visibility = 'visible';
|
|
}
|
|
initializeForm();
|
|
|
|
async function checkDataValidity() {
|
|
let dataIsValid = true;
|
|
|
|
if(!nameTextbox.value) dataIsValid = false;
|
|
|
|
const sportHasContent = sportDropdown.options.length;
|
|
const genderHasContent = genderDropdown.options.length;
|
|
|
|
if(!sportHasContent || !genderHasContent) dataIsValid = false;
|
|
|
|
|
|
if(dataIsValid) submitButton.disabled = false;
|
|
else submitButton.disabled = true;
|
|
}
|
|
|
|
Form.addRemoveFunction(deleteButton, submissionForm, "division");
|
|
|