From cf91548daca5c4b4b174adca65204ab9d57e18a4 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Mon, 22 Nov 2021 22:10:47 -0700 Subject: [PATCH] Add ability to remove sports --- public/scripts/manage/sport.js | 17 ++++++++++++++++- routes/manage.js | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) 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')); });