diff options
Diffstat (limited to 'templates/admin.html')
| -rw-r--r-- | templates/admin.html | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..19c7bd9 --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,138 @@ +{% extends "base.html" %} + +{% block content %} + <h2>League Administration</h2> + + <div style="display: flex; gap: 2rem; flex-wrap: wrap;"> + <div style="flex: 1; min-width: 300px;"> + <h3>Create New Season</h3> + <form method="POST"> + <input type="hidden" name="action" value="create_season"> + <div> + <label for="name">Season Name:</label> + <input type="text" id="name" name="name" required> + </div> + <button type="submit">Create Season</button> + </form> + </div> + + <div style="flex: 1; min-width: 300px;"> + <h3>Create Team/User</h3> + <form method="POST"> + <input type="hidden" name="action" value="create_team"> + <div> + <label for="username">Username:</label> + <input type="text" id="username" name="username" required> + </div> + <div> + <label for="password">Password:</label> + <input type="password" id="password" name="password" required> + </div> + <div> + <label for="team_name">Team Name:</label> + <input type="text" id="team_name" name="team_name" required> + </div> + <button type="submit">Create Team</button> + </form> + </div> + </div> + + <div style="margin-top: 2rem;"> + <h3>Manage Seasons</h3> + {% if seasons %} + <table> + <tr> + <th>ID</th> + <th>Name</th> + <th>Status</th> + <th>Actions</th> + </tr> + {% for season in seasons %} + <tr> + <td>{{ season.id }}</td> + <td>{{ season.name }}</td> + <td>{{ season.status }}</td> + <td> + <form method="GET" action="{{ url_for('admin_manage_teams', season_id=season.id) }}" style="display:inline;"> + <button type="submit">Manage Teams</button> + </form> + <button onclick="toggleScheduleForm({{ season.id }})">Generate Schedule/Playoffs</button> + + <div id="form-{{ season.id }}" style="display:none; background: #f0f0f0; padding: 1rem; border: 1px solid #ccc; margin-top: 10px; text-align: left;"> + <form id="sched-form-{{ season.id }}" onsubmit="submitGenerate(event, {{ season.id }})"> + <div> + <label>Total Games (per team):</label> + <input type="number" name="total_games" value="10" required style="width: 60px;"> + </div> + <div> + <label>Games Per Week:</label> + <input type="number" name="games_per_week" value="3" required style="width: 60px;"> + </div> + <div> + <label>Playoff Teams (2 or 4):</label> + <input type="number" name="playoff_teams" value="4" required style="width: 60px;"> + </div> + <div> + <label>Series Length (1, 3, 5):</label> + <input type="number" name="playoff_series_length" value="3" required style="width: 60px;"> + </div> + <button type="submit" style="margin-top: 10px;">Generate</button> + </form> + </div> + <form method="POST" action="{{ url_for('admin_delete_season', season_id=season.id) }}" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this season and all its games?')"> + <button type="submit" style="background-color: #cc0000; color: white;">Delete</button> + </form> + </td> + </tr> + {% endfor %} + </table> + + <script> + function toggleScheduleForm(id) { + var f = document.getElementById('form-' + id); + f.style.display = f.style.display === 'none' ? 'block' : 'none'; + } + + function submitGenerate(event, id, confirmed = false) { + event.preventDefault(); + var form = document.getElementById('sched-form-' + id); + var formData = new FormData(form); + if (confirmed) formData.append('confirm', 'true'); + + fetch('/admin/season/' + id + '/generate_schedule', { + method: 'POST', + body: formData, + headers: {'X-Requested-With': 'XMLHttpRequest'} + }) + .then(response => response.json()) + .then(data => { + if (data.status === 'confirm_required') { + if (confirm(data.message)) { + submitGenerate(event, id, true); + } + } else if (data.status === 'success') { + window.location.href = data.redirect; + } else { + alert('An error occurred.'); + } + }); + } + </script> + {% else %} + <p>No seasons created yet.</p> + {% endif %} + </div> + + <div style="margin-top: 2rem;"> + <h3>Registered Teams</h3> + {% if teams %} + <ul> + {% for team in teams %} + <li>{{ team.team_name }} ({{ team.username }})</li> + {% endfor %} + </ul> + {% else %} + <p>No teams registered yet.</p> + {% endif %} + </div> +{% endblock %}
\ No newline at end of file |
