2021-11-23 05:03:02 +00:00
|
|
|
import * as Data from "../data.js";
|
|
|
|
|
|
|
|
|
|
|
|
const mainHeader = document.getElementById('main-header');
|
|
|
|
const nameTextbox = document.getElementById('name-textbox');
|
|
|
|
const submitButton = document.getElementById('submit-button');
|
|
|
|
const deleteButton = document.getElementById('delete-button');
|
|
|
|
const submissionForm = document.getElementById('submission-form');
|
|
|
|
|
|
|
|
|
|
|
|
async function initializeForm() {
|
|
|
|
let params = new URLSearchParams(location.search);
|
|
|
|
let sportID = params.get('sport')
|
|
|
|
if(sportID) {
|
|
|
|
mainHeader.textContent = "Edit Sport";
|
|
|
|
|
|
|
|
const sportName = await Data.getSportName(sportID);
|
|
|
|
|
|
|
|
nameTextbox.value = sportName;
|
|
|
|
deleteButton.style.visibility = "visible";
|
|
|
|
deleteButton.disabled = false;
|
|
|
|
|
|
|
|
const sportIDInput = document.createElement('input');
|
|
|
|
sportIDInput.setAttribute('name', 'sport');
|
|
|
|
sportIDInput.setAttribute('value', sportID);
|
|
|
|
sportIDInput.setAttribute('type', 'hidden');
|
|
|
|
submissionForm.appendChild(sportIDInput);
|
|
|
|
}
|
|
|
|
nameTextbox.disabled = false;
|
|
|
|
|
|
|
|
nameTextbox.addEventListener('keyup', checkDataValidity);
|
|
|
|
}
|
|
|
|
initializeForm();
|
|
|
|
|
|
|
|
async function checkDataValidity() {
|
|
|
|
let dataIsValid = true;
|
|
|
|
|
|
|
|
if(!nameTextbox.value) dataIsValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
if(dataIsValid) submitButton.disabled = false;
|
|
|
|
else submitButton.disabled = true;
|
2021-11-23 05:10:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function removeSport() {
|
|
|
|
const removeInput = document.createElement('input');
|
|
|
|
removeInput.setAttribute('name', 'remove');
|
|
|
|
removeInput.setAttribute('value', 1);
|
|
|
|
removeInput.setAttribute('type', 'hidden');
|
|
|
|
submissionForm.appendChild(removeInput);
|
|
|
|
submissionForm.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteButton.addEventListener('click', () => {
|
|
|
|
const verified = confirm("This sport will be removed.");
|
|
|
|
|
|
|
|
if(verified) removeSport();
|
|
|
|
});
|