1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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 %}
|