vedia/views/votes_edit.erb
2025-12-04 17:27:13 -06:00

106 lines
3.9 KiB
Text

<div class="mb-5">
<h1><%= @vote.title %></h1>
<ul class="list-unstyled">
<li>
<span class="badge bg-secondary"><%= _("Draft") %></span>
<span class="badge bg-warning text-bg-warning"><%= _("Organizer") %></span>
</li>
</ul>
</div>
<div class="mb-5">
<div class="lead">
<%= markdown(@vote.description) %>
</div>
<form action="/votes/<%= @vote.secure_id %>/edit" method="get" class="mb-5">
<button type="submit" class="btn btn-outline-primary"><%= _("Edit") %></button>
</form>
</div>
<h2 class="mb-4"><%= _("Candidates") %></h2>
<% @vote.candidates.each do |candidate| %>
<div class="card mb-4">
<div class="card-body">
<h3 class="mb-3"><%= candidate.name %></h3>
<%= markdown(candidate.description) %>
<div class="d-flex">
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>" method="get" class="me-3">
<button type="submit" class="btn btn-outline-primary"><%= _("Edit") %></button>
</form>
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>/delete" method="post">
<button type="submit" class="btn btn-outline-danger"><%= _("Delete") %></button>
</form>
</div>
</div>
</div>
<% end %>
<div class="card mb-4">
<div class="card-body">
<h3 class="mb-3"><%= _("Add candidate") %></h3>
<% if @vote.candidates.empty? %>
<p class="alert alert-primary mb-4"><%= _("This vote has no candidates yet. Add a first candidate.") %></p>
<% end %>
<% if @errors %>
<% @errors.each do |error| %>
<% if error.attribute == :name and error.type == :blank %>
<p class="alert alert-warning mb-4"><%= _("Enter a name.") %></p>
<% end %>
<% end %>
<% end %>
<form action="/votes/<%= @vote.secure_id %>/candidates" method="post">
<div class="mb-3">
<label for="name" class="form-label"><%= _("Name") %></label>
<input type="text" name="name" value="<%= params[:name] %>" class="form-control">
</div>
<div class="mb-3">
<label for="description" class="form-label"><%= _("Description") %></label>
<textarea type="text" name="description" class="form-control"><%= params[:description] %></textarea>
<small class="form-text text-muted"><%= _("You can use <a href=\"https://www.markdownguide.org/basic-syntax/\">Markdown</a>.") %></small>
</div>
<% if @vote.candidates.length < 2 %>
<button type="submit" class="btn btn-primary"><%= _("Add") %></button>
<% else %>
<button type="submit" class="btn btn-outline-primary"><%= _("Add") %></button>
<% end %>
</form>
</div>
</div>
<% if @vote.candidates.length < 2 %>
<p class="alert alert-warning mb-4"><%= _("Add at least 2 candidates before opening the vote to participants.") %></p>
<% end %>
<div class="d-flex">
<form action="/votes/<%= @vote.secure_id %>/open" method="get" class="me-3">
<% if @vote.candidates.length < 2 %>
<fieldset disabled="">
<% end %>
<button type="submit" class="btn btn-primary"><%= _("Open vote to participants") %></button>
<% if @vote.candidates.length < 2 %>
</fieldset>
<% end %>
</form>
<form action="/votes/<%= @vote.secure_id %>/delete" method="post" class="mb-5">
<button type="submit" class="btn btn-outline-danger"><%= _("Delete vote") %></button>
</form>
</div>
<h2 class="mb-4"><%= _("Organizers") %></h2>
<ul>
<% @vote.organizers.each do |organizer| %>
<li><%= organizer.user.email %></li>
<% end %>
</ul>
<h3 class="mb-3"><%= _("Add organizer") %></h3>
<form action="/votes/<%= @vote.secure_id %>/organizers" method="post" class="mb-5">
<div class="mb-3">
<label for="email" class="form-label"><%= _("Email") %></label>
<input type="text" name="email" class="form-control">
</div>
<button type="submit" class="btn btn-outline-primary"><%= _("Add organizer") %></button>
</form>