Add ability to delete seasons

main
sudoer777 2021-11-23 14:48:19 -07:00
parent b5495b1f57
commit bd0ae3bdfd
3 changed files with 30 additions and 7 deletions

View File

@ -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();
}
}
));

View File

@ -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) {

View File

@ -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')