From aacff9cca1121b4afd4156fa7f5fa9d966b76620 Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:17:23 -0700 Subject: [PATCH] Add page to add teams --- public/scripts/manage.js | 6 +++--- public/scripts/manage/team.js | 18 ++++++++++++++++++ routes/manage.js | 13 +++++++++++++ views/manage/addteam.pug | 23 +++++++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 public/scripts/manage/team.js create mode 100644 views/manage/addteam.pug diff --git a/public/scripts/manage.js b/public/scripts/manage.js index 770a517..651047e 100644 --- a/public/scripts/manage.js +++ b/public/scripts/manage.js @@ -178,10 +178,10 @@ CATEGORIES.push(new Category( .then(data => sportCell.textContent = data); row.appendChild(sportCell); }, - async function addSeason() { - // + async function addTeam() { + window.location.href = "manage/addteam"; }, - async function editSeason() { + async function editTeam() { } )); diff --git a/public/scripts/manage/team.js b/public/scripts/manage/team.js new file mode 100644 index 0000000..6b37492 --- /dev/null +++ b/public/scripts/manage/team.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 72f17e8..04b2b9a 100644 --- a/routes/manage.js +++ b/routes/manage.js @@ -6,6 +6,7 @@ var seasons = require('../database/scores/seasons'); var sports = require('../database/scores/sports'); var divisions = require('../database/scores/divisions'); var genders = require('../database/scores/genders'); +var teams = require('../database/scores/teams'); router.get('/', function(req, res, next) { @@ -74,4 +75,16 @@ router.post('/submitdivision', function(req, res, next) { } }); +router.get('/addteam', function(req, res, next) { + res.render('manage/addteam', { title: 'Add team' }); +}); + +router.post('/submitteam', function(req, res, next) { + const name = req.body['name']; + const sport = req.body['sport']; + + teams.add(name, sport) + .then(res.send("SUCCESS")); +}); + module.exports = router; diff --git a/views/manage/addteam.pug b/views/manage/addteam.pug new file mode 100644 index 0000000..c3d422b --- /dev/null +++ b/views/manage/addteam.pug @@ -0,0 +1,23 @@ +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 Team + form(action='./submitteam', 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 Team 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/team.js' type="module") \ No newline at end of file