From 1a3b013a0f93f9c12e8d4a170173636c5704e005 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:11:16 -0700 Subject: [PATCH] Add page to add divisions --- public/scripts/manage.js | 6 +++--- public/scripts/manage/division.js | 18 ++++++++++++++++++ routes/manage.js | 23 +++++++++++++++++++++++ views/manage/adddivision.pug | 30 ++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 public/scripts/manage/division.js create mode 100644 views/manage/adddivision.pug diff --git a/public/scripts/manage.js b/public/scripts/manage.js index 2017341..770a517 100644 --- a/public/scripts/manage.js +++ b/public/scripts/manage.js @@ -135,10 +135,10 @@ CATEGORIES.push(new Category( .then(data => sportCell.textContent = data); row.appendChild(sportCell); }, - async function addSeason() { - // + async function addDivision() { + window.location.href = "manage/adddivision"; }, - async function editSeason() { + async function editDivision() { } )); diff --git a/public/scripts/manage/division.js b/public/scripts/manage/division.js new file mode 100644 index 0000000..6b37492 --- /dev/null +++ b/public/scripts/manage/division.js @@ -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(); \ No newline at end of file diff --git a/routes/manage.js b/routes/manage.js index 4582727..72f17e8 100644 --- a/routes/manage.js +++ b/routes/manage.js @@ -4,6 +4,8 @@ var genders = require('../database/scores/genders'); var games = require('../database/scores/games'); var seasons = require('../database/scores/seasons'); var sports = require('../database/scores/sports'); +var divisions = require('../database/scores/divisions'); +var genders = require('../database/scores/genders'); router.get('/', function(req, res, next) { @@ -51,4 +53,25 @@ router.post('/submitsport', function(req, res, next) { .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; diff --git a/views/manage/adddivision.pug b/views/manage/adddivision.pug new file mode 100644 index 0000000..4b8d7d1 --- /dev/null +++ b/views/manage/adddivision.pug @@ -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") \ No newline at end of file