Add ability to remove sports
parent
35af76c90f
commit
cf91548dac
|
@ -40,4 +40,19 @@ async function checkDataValidity() {
|
||||||
|
|
||||||
if(dataIsValid) submitButton.disabled = false;
|
if(dataIsValid) submitButton.disabled = false;
|
||||||
else submitButton.disabled = true;
|
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();
|
||||||
|
});
|
|
@ -50,8 +50,10 @@ router.get('/sport', function(req, res, next) {
|
||||||
router.post('/sport', function(req, res, next) {
|
router.post('/sport', function(req, res, next) {
|
||||||
const name = req.body['name'];
|
const name = req.body['name'];
|
||||||
const id = req.body['sport'];
|
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'));
|
else sports.add(name).then(res.redirect('/manage'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in New Issue