diff --git a/public/scripts/manage/sport.js b/public/scripts/manage/sport.js index 2b12593..c30fbce 100644 --- a/public/scripts/manage/sport.js +++ b/public/scripts/manage/sport.js @@ -40,4 +40,19 @@ async function checkDataValidity() { if(dataIsValid) submitButton.disabled = false; else submitButton.disabled = true; -} \ No newline at end of file +} + +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(); +}); \ No newline at end of file diff --git a/routes/manage.js b/routes/manage.js index a42f734..145dfa0 100644 --- a/routes/manage.js +++ b/routes/manage.js @@ -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')); });