diff --git a/public/scripts/manage.js b/public/scripts/manage.js index 27ad375..8c89bfd 100644 --- a/public/scripts/manage.js +++ b/public/scripts/manage.js @@ -50,10 +50,30 @@ CATEGORIES.push(new Category( row.appendChild(spacerCell); }, async function addSeason() { - window.location.href = "/manage/addseason"; + window.location.href = "/manage/season"; }, - async function editSeason() { + async function editSeason(id) { + const verified = confirm(`This season will be removed.`); + + if(verified) { + const form = document.createElement('form'); + form.action = "/manage/season"; + form.method = "POST"; + form.style.visibility = "hidden"; + itemsListTable.appendChild(form); + const remove = document.createElement('input'); + remove.setAttribute('name', 'remove'); + remove.setAttribute('value', 1); + form.appendChild(remove); + + const seasonID = document.createElement('input'); + seasonID.setAttribute('name', 'season'); + seasonID.setAttribute('value', id); + form.appendChild(seasonID); + + form.submit(); + } } )); diff --git a/routes/manage.js b/routes/manage.js index e7c77ed..9757e69 100644 --- a/routes/manage.js +++ b/routes/manage.js @@ -41,15 +41,18 @@ router.post('/game', function(req, res, next) { .then(res.redirect("/manage")); }); -router.get('/addseason', function(req, res, next) { +router.get('/season', function(req, res, next) { res.render('manage/addseason', { title: 'Add Season', currentYear : (new Date()).getFullYear() }); }); -router.post('/submitseason', function(req, res, next) { +router.post('/season', function(req, res, next) { const year = req.body['year']; - seasons.add(year) - .then(res.send("SUCCESS")); + const seasonID = req.body['season']; + const remove = req.body['remove']; + + if(remove) seasons.remove(seasonID).then(res.redirect('/manage')); + else seasons.add(year).then(res.redirect("/manage")); }); router.get('/sport', function(req, res, next) { diff --git a/views/manage/addseason.pug b/views/manage/addseason.pug index 6539a76..bdb13fd 100644 --- a/views/manage/addseason.pug +++ b/views/manage/addseason.pug @@ -7,7 +7,7 @@ block stylesheets block content div#mobile-view h1 #{title} - form(action='./submitseason', method='POST') + form(action='./season', method='POST') span(class='form-section') label Ending year span(class='form-section-input')