vedia/views/votes_show_open.erb

101 lines
3.1 KiB
Text

<div class="mb-5">
<h1><%= @vote.title %></h1>
<ul class="list-unstyled">
<li>
<span class="badge bg-primary"><%= _("Open") %></span>
</li>
<% if @vote.expire_on %>
<li><%= _("Closes on %{date}") % { date: format_date_and_time(@vote.expire_on) } %></li>
<% end %>
</ul>
</div>
<div class="mb-5">
<div class="lead">
<%= markdown(@vote.description) %>
</div>
</div>
<h2 class="mb-4"><%= _("Options") %></h2>
<% if @errors %>
<% @errors.each do |error| %>
<% if error.attribute == :rating and error.type == :blank %>
<p class="alert alert-warning mb-4"><%= _("Missing rating for candidate <i>%{name}</i>.") % { name: error.candidate.name } %></p>
<% end %>
<% end %>
<% end %>
<form action="/votes/<%= @vote.secure_id %>/ratings" method="post" class="mb-5">
<% @vote.candidates.each do |candidate| %>
<div class="card mb-4">
<div class="card-body">
<h3 class="mb-3"><%= candidate.name %></h3>
<%= markdown(candidate.description) %>
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
<% if rating
value = rating.value
elsif @params[candidate.id.to_s]
value = params[candidate.id.to_s].to_i
else
value = 0
end %>
<div class="btn-group">
<% settings.values.reverse.each do |v| %>
<input type="radio" name="<%= candidate.id %>" id="<%= candidate.id %>-<%= v[:id] %>" value="<%= v[:id] %>" class="btn-check" <% if value == v[:id] %>checked<% end %>>
<label for="<%= candidate.id %>-<%= v[:id] %>" class="btn btn-radio-<%= v[:id] %>"><%= _(v[:label]) %></label>
<% end %>
</div>
</div>
</div>
<% end %>
<button type="submit" class="btn btn-primary"><%= _("Vote") %></button>
</form>
<h2 class="mb-4"><%= _("Participants") %></h2>
<ul class="mb-5">
<% @vote.ratings.collect { |rating| rating.user }.uniq.each do |user| %>
<li><%= user.email %></li>
<% end %>
</ul>
<% if @vote.users.exists?(current_user.id) and @vote.expire_on.nil? %>
<form action="/votes/<%= @vote.secure_id %>/draft" method="post">
<button type="submit" class="btn btn-outline-danger mb-3"><%= _("Change back to draft vote") %></button>
</form>
<form action="/votes/<%= @vote.secure_id %>/close" method="post" class="mb-5">
<button type="submit" class="btn btn-outline-primary mb-3"><%= _("Close votes and show results") %></button>
</form>
<% end %>
<% unless @vote.organizers.blank? %>
<h2 class="mb-4"><%= _("Organizers") %></h2>
<ul>
<% @vote.organizers.each do |organizer| %>
<li><%= organizer.user.email %></li>
<% end %>
</ul>
<% end %>
<% if @vote.users.exists?(current_user.id) or @vote.expire_on.nil? %>
<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>
<% end %>