Allow editing candidates

This commit is contained in:
ricola 2025-12-04 01:26:32 +01:00
parent 62e70e3935
commit a5a9e92e18
3 changed files with 40 additions and 0 deletions

View file

@ -333,6 +333,30 @@ post '/votes/:id/candidates' do
redirect '/votes/' + @vote.secure_id redirect '/votes/' + @vote.secure_id
end end
get '/votes/:id/candidates/:cid' do
require_login
find_vote
require_organizer
require_draft_vote
find_candidate
require_candidate_in_vote
erb :candidates_edit
end
post '/votes/:id/candidates/:cid' do
require_login
find_vote
require_organizer
require_draft_vote
find_candidate
require_candidate_in_vote
@candidate.name = params[:name]
@candidate.description = params[:description]
@candidate.save
redirect '/votes/' + @vote.secure_id
erb :candidates_edit
end
post '/votes/:id/candidates/:cid/delete' do post '/votes/:id/candidates/:cid/delete' do
require_login require_login
find_vote find_vote

13
views/candidates_edit.erb Normal file
View file

@ -0,0 +1,13 @@
<h1 class="mb-5"><%= _("Edit candidate") %></h1>
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= @candidate.id %>" method="post">
<div class="mb-3">
<label for="name" class="form-label"><%= _("Name") %></label>
<input type="text" name="name" value="<%= @candidate.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"><%= @candidate.description %></textarea>
</div>
<button type="submit" class="btn btn-primary"><%= _("Save") %></button>
</form>

View file

@ -24,6 +24,9 @@
<div class="card-body"> <div class="card-body">
<h3 class="mb-3"><%= candidate.name %></h3> <h3 class="mb-3"><%= candidate.name %></h3>
<%= markdown(candidate.description) %> <%= markdown(candidate.description) %>
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>" method="get" class="mb-3">
<button type="submit" class="btn btn-outline-primary"><%= _("Edit") %></button>
</form>
<form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>/delete" method="post"> <form action="/votes/<%= @vote.secure_id %>/candidates/<%= candidate.id %>/delete" method="post">
<button type="submit" class="btn btn-outline-danger"><%= _("Delete") %></button> <button type="submit" class="btn btn-outline-danger"><%= _("Delete") %></button>
</form> </form>