Force ratings on all candidates before saving
This commit is contained in:
parent
fa57d465be
commit
b07b0da672
2 changed files with 35 additions and 5 deletions
16
vedia.rb
16
vedia.rb
|
|
@ -11,6 +11,7 @@ require 'gettext'
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
require 'chartkick'
|
require 'chartkick'
|
||||||
require 'mail'
|
require 'mail'
|
||||||
|
require 'ostruct'
|
||||||
require 'tzinfo'
|
require 'tzinfo'
|
||||||
require 'redcarpet'
|
require 'redcarpet'
|
||||||
|
|
||||||
|
|
@ -386,10 +387,24 @@ post '/votes/:id/reopen' do
|
||||||
redirect '/votes/' + @vote.secure_id
|
redirect '/votes/' + @vote.secure_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/votes/:id/ratings' do
|
||||||
|
redirect '/votes/' + params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
post '/votes/:id/ratings' do
|
post '/votes/:id/ratings' do
|
||||||
require_login
|
require_login
|
||||||
find_vote
|
find_vote
|
||||||
require_open_vote
|
require_open_vote
|
||||||
|
@errors = []
|
||||||
|
@vote.candidates.each do |candidate|
|
||||||
|
if not params[candidate.id.to_s]
|
||||||
|
@errors << OpenStruct.new(:attribute => :rating, :type => :blank, :candidate => candidate)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not @errors.empty?
|
||||||
|
@params = params
|
||||||
|
erb :votes_show_open
|
||||||
|
else
|
||||||
@vote.candidates.each do |candidate|
|
@vote.candidates.each do |candidate|
|
||||||
rating = Rating.find_or_initialize_by(vote: @vote, user: current_user, candidate: candidate)
|
rating = Rating.find_or_initialize_by(vote: @vote, user: current_user, candidate: candidate)
|
||||||
rating.value = params[candidate.id.to_s]
|
rating.value = params[candidate.id.to_s]
|
||||||
|
|
@ -397,6 +412,7 @@ post '/votes/:id/ratings' do
|
||||||
end
|
end
|
||||||
redirect '/votes/' + @vote.secure_id
|
redirect '/votes/' + @vote.secure_id
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
post '/votes/:id/organizers' do
|
post '/votes/:id/organizers' do
|
||||||
require_login
|
require_login
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
<h1><%= @vote.title %></h1>
|
<h1><%= @vote.title %></h1>
|
||||||
|
|
||||||
|
<% if @errors %>
|
||||||
|
<% @errors.each do |error| %>
|
||||||
|
<% if error.attribute == :rating and error.type == :blank %>
|
||||||
|
<p class="error"><%= _("Missing rating for candidate <i>%{name}</i>." % { name: error.candidate.name }) %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if @vote.expire_on %>
|
<% if @vote.expire_on %>
|
||||||
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
@ -12,7 +20,13 @@
|
||||||
<ul>
|
<ul>
|
||||||
<% @vote.candidates.each do |candidate| %>
|
<% @vote.candidates.each do |candidate| %>
|
||||||
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
|
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
|
||||||
<% value = rating ? rating.value : 0 %>
|
<% if rating
|
||||||
|
value = rating.value
|
||||||
|
elsif @params[candidate.id.to_s]
|
||||||
|
value = params[candidate.id.to_s].to_i
|
||||||
|
else
|
||||||
|
value = 0
|
||||||
|
end %>
|
||||||
<li>
|
<li>
|
||||||
<p><b><%= candidate.name %></b></p>
|
<p><b><%= candidate.name %></b></p>
|
||||||
<%= markdown(candidate.description) %>
|
<%= markdown(candidate.description) %>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue