feat: Scoreboard-Layout-Verbesserungen und automatische Ergebnisberechnung

This commit is contained in:
Matthias Nagel 2025-10-02 16:38:50 +02:00
parent ec07bfc53b
commit 4b350ff5c6
5 changed files with 44 additions and 4 deletions

View File

@ -50,5 +50,5 @@ class GameResultForm(forms.ModelForm):
guest_team = game.team.name
for i in range(1, game.number_of_innings + 1):
self.fields[f'inning_{i}_home'] = forms.IntegerField(label=f'Inning {i} ({home_team})', required=False)
self.fields[f'inning_{i}_guest'] = forms.IntegerField(label=f'Inning {i} ({guest_team})', required=False)
self.fields[f'inning_{i}_home'] = forms.IntegerField(label=f'Inning {i} ({home_team})', required=False, widget=forms.NumberInput(attrs={'class': 'inning-score-input'}))
self.fields[f'inning_{i}_guest'] = forms.IntegerField(label=f'Inning {i} ({guest_team})', required=False, widget=forms.NumberInput(attrs={'class': 'inning-score-input'}))

View File

@ -17,10 +17,11 @@
{% for item in form_fields_by_inning %}
<th>{{ item.inning }}</th>
{% endfor %}
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<tr id="home-row">
<td>
{% if game.is_home_game %}
{{ game.team.name }} (Home)
@ -31,8 +32,9 @@
{% for item in form_fields_by_inning %}
<td>{{ item.home }}</td>
{% endfor %}
<td id="home-total">0</td>
</tr>
<tr>
<tr id="guest-row">
<td>
{% if not game.is_home_game %}
{{ game.team.name }} (Guest)
@ -43,6 +45,7 @@
{% for item in form_fields_by_inning %}
<td>{{ item.guest }}</td>
{% endfor %}
<td id="guest-total">0</td>
</tr>
</tbody>
</table>
@ -53,3 +56,36 @@
</div>
</div>
{% endblock %}
{% block javascript %}
<script>
document.addEventListener('DOMContentLoaded', function() {
const homeRow = document.getElementById('home-row');
const guestRow = document.getElementById('guest-row');
const homeTotalCell = document.getElementById('home-total');
const guestTotalCell = document.getElementById('guest-total');
function calculateTotal(row) {
let total = 0;
const inputs = row.querySelectorAll('.inning-score-input');
inputs.forEach(input => {
total += parseInt(input.value) || 0;
});
return total;
}
function updateTotalScores() {
homeTotalCell.textContent = calculateTotal(homeRow);
guestTotalCell.textContent = calculateTotal(guestRow);
}
const allInputs = document.querySelectorAll('.inning-score-input');
allInputs.forEach(input => {
input.addEventListener('input', updateTotalScores);
});
// Initial calculation
updateTotalScores();
});
</script>
{% endblock %}

Binary file not shown.

View File

@ -19,6 +19,10 @@
background-color: #fff3cd; /* light yellow background */
border-color: #ffc107; /* yellow border */
}
.inning-score-input {
width: 50px; /* Adjust as needed */
text-align: center;
}
</style>
</head>
<body>