5bb3bc4e5f
Add improved match entry form with player selection validation and better user experience for recording match results. Changes: - Add player validation to prevent same player on both teams - Add team score validation (must have winner) - Improve form layout and player selection UI - Add helper methods for player lookup and team building
107 lines
3.7 KiB
Plaintext
107 lines
3.7 KiB
Plaintext
<h1><%= tournament ? "Enter Match for #{tournament.name}" : "Enter New Match" %></h1>
|
|
|
|
<% if tournament %>
|
|
<p><strong>Format:</strong> <%= tournament.format %> | <strong>Status:</strong> <%= tournament.status %></p>
|
|
<hr>
|
|
<% end %>
|
|
|
|
<form action="/admin/matches" method="post">
|
|
<input type="hidden" name="_csrf_token" value="<%= csrf_token %>">
|
|
<input type="hidden" name="event_id" value="<%= tournament&.id %>">
|
|
|
|
<div>
|
|
<label for="played_at">Date/Time:</label>
|
|
<input type="datetime-local" id="played_at" name="played_at" required value="<%= Time.now.strftime('%Y-%m-%dT%H:%M') %>">
|
|
</div>
|
|
|
|
<% if tournament && teams.any? %>
|
|
<!-- Team-based selection for tournaments -->
|
|
<fieldset>
|
|
<legend>Team 1</legend>
|
|
<div>
|
|
<label for="team_1_id">Select Team:</label>
|
|
<select id="team_1_id" name="team_1_id" required>
|
|
<option value="">Select team...</option>
|
|
<% teams.each do |team| %>
|
|
<option value="<%= team.id %>" <%= 'selected' if team.id == preselected_team_1 %>>
|
|
<%= team.team_name %>
|
|
</option>
|
|
<% end %>
|
|
</select>
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
<legend>Team 2</legend>
|
|
<div>
|
|
<label for="team_2_id">Select Team:</label>
|
|
<select id="team_2_id" name="team_2_id" required>
|
|
<option value="">Select team...</option>
|
|
<% teams.each do |team| %>
|
|
<option value="<%= team.id %>" <%= 'selected' if team.id == preselected_team_2 %>>
|
|
<%= team.team_name %>
|
|
</option>
|
|
<% end %>
|
|
</select>
|
|
</div>
|
|
</fieldset>
|
|
<% else %>
|
|
<!-- Individual player selection (non-tournament) -->
|
|
<fieldset>
|
|
<legend>Team 1</legend>
|
|
<div>
|
|
<label for="team_1_p1_id">Player 1:</label>
|
|
<select id="team_1_p1_id" name="team_1_p1_id" required>
|
|
<option value="">Select player...</option>
|
|
<% players.each do |player| %>
|
|
<option value="<%= player.id %>"><%= player.name %></option>
|
|
<% end %>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="team_1_p2_id">Player 2:</label>
|
|
<select id="team_1_p2_id" name="team_1_p2_id" required>
|
|
<option value="">Select player...</option>
|
|
<% players.each do |player| %>
|
|
<option value="<%= player.id %>"><%= player.name %></option>
|
|
<% end %>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="team_1_score">Score:</label>
|
|
<input type="number" id="team_1_score" name="team_1_score" min="0" max="10" required value="10">
|
|
</div>
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
<legend>Team 2</legend>
|
|
<div>
|
|
<label for="team_2_p1_id">Player 1:</label>
|
|
<select id="team_2_p1_id" name="team_2_p1_id" required>
|
|
<option value="">Select player...</option>
|
|
<% players.each do |player| %>
|
|
<option value="<%= player.id %>"><%= player.name %></option>
|
|
<% end %>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="team_2_p2_id">Player 2:</label>
|
|
<select id="team_2_p2_id" name="team_2_p2_id" required>
|
|
<option value="">Select player...</option>
|
|
<% players.each do |player| %>
|
|
<option value="<%= player.id %>"><%= player.name %></option>
|
|
<% end %>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label for="team_2_score">Score:</label>
|
|
<input type="number" id="team_2_score" name="team_2_score" min="0" max="10" required value="7">
|
|
</div>
|
|
</fieldset>
|
|
<% end %>
|
|
|
|
<button type="submit">Save Match</button>
|
|
</form>
|
|
|
|
<p><a href="<%= tournament ? "/admin/tournaments/#{tournament.id}" : "/admin/matches" %>">Back</a></p>
|