Add ability to remove sports

main
sudoer777 2021-11-22 22:10:47 -07:00
parent 35af76c90f
commit cf91548dac
2 changed files with 19 additions and 2 deletions

View File

@ -40,4 +40,19 @@ async function checkDataValidity() {
if(dataIsValid) submitButton.disabled = false;
else submitButton.disabled = true;
}
}
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();
});

View File

@ -50,8 +50,10 @@ router.get('/sport', function(req, res, next) {
router.post('/sport', function(req, res, next) {
const name = req.body['name'];
const id = req.body['sport'];
const remove = req.body['remove'];
if(id) sports.rename(id, name).then(res.redirect('/manage'));
if(remove) sports.remove(id).then(res.redirect('/manage'));
else if(id) sports.rename(id, name).then(res.redirect('/manage'));
else sports.add(name).then(res.redirect('/manage'));
});