This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
score-tracker/public/scripts/manage/team.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-11-23 02:17:23 +00:00
import * as Data from "../data.js";
2021-11-23 06:45:24 +00:00
import * as Form from "../form.js";
2021-11-23 02:17:23 +00:00
2021-11-23 06:45:24 +00:00
const submissionForm = document.getElementById('submission-form');
2021-11-23 02:17:23 +00:00
const sportDropdown = document.getElementById('sport-dropdown');
2021-11-23 06:45:24 +00:00
const nameTextbox = document.getElementById('name-textbox');
const submitButton = document.getElementById('submit-button');
const deleteButton = document.getElementById('delete-button');
2022-03-09 18:00:27 +00:00
const loadingSpan = document.getElementById('loading-message');
2021-11-23 02:17:23 +00:00
2021-11-23 06:45:24 +00:00
async function initializeForm() {
let params = new URLSearchParams(location.search);
let teamID = params.get('team');
if(teamID) {
2022-03-10 00:57:18 +00:00
const team = await (await fetch(`/fetch/manage/team?team=${teamID}`)).json();
2021-11-23 06:45:24 +00:00
nameTextbox.value = team.name;
deleteButton.style.visibility = "visible";
deleteButton.disabled = false;
2022-03-10 00:57:18 +00:00
let data = {};
data.sports = [team.sport];
data.latestGame = {sportID : team.sportID };
Form.populateSports(sportDropdown, null, data);
2021-11-23 06:45:24 +00:00
Form.addHiddenValue('team', teamID, submissionForm);
}
else {
sportDropdown.disabled = false;
Form.populateSports(sportDropdown);
}
nameTextbox.disabled = false;
nameTextbox.addEventListener('keyup', checkDataValidity);
2022-03-09 18:00:27 +00:00
loadingSpan.textContent = '';
submissionForm.style.visibility = 'visible';
2021-11-23 02:17:23 +00:00
}
2021-11-23 06:45:24 +00:00
initializeForm();
async function checkDataValidity() {
let dataIsValid = true;
if(!nameTextbox.value) dataIsValid = false;
2021-11-26 21:10:09 +00:00
const sportHasContent = sportDropdown.options.length;
if(!sportHasContent) dataIsValid = false;
2021-11-23 06:45:24 +00:00
2021-11-26 21:10:09 +00:00
submitButton.disabled = !dataIsValid;
2021-11-23 06:45:24 +00:00
}
Form.addRemoveFunction(deleteButton, submissionForm, "team");