Add page to add divisions

main
sudoer777 2021-11-22 19:11:16 -07:00
parent f95015095d
commit 1a3b013a0f
4 changed files with 74 additions and 3 deletions

View File

@ -135,10 +135,10 @@ CATEGORIES.push(new Category(
.then(data => sportCell.textContent = data); .then(data => sportCell.textContent = data);
row.appendChild(sportCell); row.appendChild(sportCell);
}, },
async function addSeason() { async function addDivision() {
// window.location.href = "manage/adddivision";
}, },
async function editSeason() { async function editDivision() {
} }
)); ));

View File

@ -0,0 +1,18 @@
import * as Data from "../data.js";
const sportDropdown = document.getElementById('sport-dropdown');
async function listSports() {
sportDropdown.innerHTML = "";
const sportsList = await Data.getSports();
sportsList.forEach(sport => {
const option = document.createElement('option');
option.text = sport.name;
option.value = sport.id;
sportDropdown.appendChild(option);
});
}
listSports();

View File

@ -4,6 +4,8 @@ var genders = require('../database/scores/genders');
var games = require('../database/scores/games'); var games = require('../database/scores/games');
var seasons = require('../database/scores/seasons'); var seasons = require('../database/scores/seasons');
var sports = require('../database/scores/sports'); var sports = require('../database/scores/sports');
var divisions = require('../database/scores/divisions');
var genders = require('../database/scores/genders');
router.get('/', function(req, res, next) { router.get('/', function(req, res, next) {
@ -51,4 +53,25 @@ router.post('/submitsport', function(req, res, next) {
.then(res.send("SUCCESS")); .then(res.send("SUCCESS"));
}); });
router.get('/adddivision', function(req, res, next) {
res.render('manage/adddivision', { title: 'Add division' });
});
router.post('/submitdivision', function(req, res, next) {
const name = req.body['name'];
const sport = req.body['sport'];
const genderName = req.body['gender'];
if(genderName == "both") {
divisions.add(name, genders.FEMALE, sport)
.then(divisions.add(name, genders.MALE, sport)
.then(res.send("SUCCESS")));
}
else {
const gender = (genderName == "female") ? genders.FEMALE : genders.MALE;
divisions.add(name, gender, sport)
.then(res.send("SUCCESS"));
}
});
module.exports = router; module.exports = router;

View File

@ -0,0 +1,30 @@
extends layout
block stylesheets
link(rel='stylesheet', href='/stylesheets/submit.css')
link(rel='stylesheet', href='/stylesheets/form.css')
block content
div#mobile-view
h1 Add Division
form(action='./submitdivision', method='POST')
span(class='form-section')
label Sport
span(class='form-section-input')
select#sport-dropdown(name="sport" class="form-main-dropdown")
span(class='form-section')
label Gender
span(class='form-section-input')
select#gender-dropdown(name="gender" class="form-main-dropdown")
option(value="both") Both
option(value="female") Female
option(value="male") Male
span(class='form-section')
label Division name
span(class='form-section-input')
input(type="text", name="name")
span(class='form-section')
button#submit-button(type="submit") Submit
block scripts
script(src='/scripts/manage/division.js' type="module")