Poll voter token
This commit is contained in:
@@ -70,6 +70,7 @@
|
||||
//= require polls_admin
|
||||
//= require leaflet
|
||||
//= require map
|
||||
//= require polls
|
||||
|
||||
var initialize_modules = function() {
|
||||
App.Comments.initialize();
|
||||
@@ -108,6 +109,7 @@ var initialize_modules = function() {
|
||||
App.TagAutocomplete.initialize();
|
||||
App.PollsAdmin.initialize();
|
||||
App.Map.initialize();
|
||||
App.Polls.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
|
||||
21
app/assets/javascripts/polls.js.coffee
Normal file
21
app/assets/javascripts/polls.js.coffee
Normal file
@@ -0,0 +1,21 @@
|
||||
App.Polls =
|
||||
generateToken: ->
|
||||
rand = Math.random().toString(36).substr(2) # remove `0.`
|
||||
token = rand + rand # to make it longer
|
||||
return token
|
||||
|
||||
replaceToken: ->
|
||||
for link in $('.js-question-answer')
|
||||
token_param = link.search.slice(-6)
|
||||
if token_param == "token="
|
||||
link.href = link.href + @token
|
||||
|
||||
initialize: ->
|
||||
@token = App.Polls.generateToken()
|
||||
App.Polls.replaceToken()
|
||||
|
||||
$(".js-question-answer").on "click", (@token) ->
|
||||
token_message = $(".js-token-message")
|
||||
token_message.html(token_message.html() + "<br><strong>" + @token + "</strong>");
|
||||
token_message.show()
|
||||
false
|
||||
@@ -17,9 +17,8 @@ class Poll::Answer < ActiveRecord::Base
|
||||
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
||||
|
||||
def record_voter_participation(token)
|
||||
Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web") do |poll_voter|
|
||||
poll_voter.token = token unless poll_voter.token.present?
|
||||
poll_voter.token_seen_at = Time.current unless poll_voter.token_seen_at.present?
|
||||
Poll::Voter.find_or_create_by(user: author, poll: poll, origin: "web") do |poll_voter|
|
||||
poll_voter.token = token unless poll_voter.token.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
method: :post,
|
||||
remote: true,
|
||||
title: t("poll_questions.show.vote_answer", answer: answer.title),
|
||||
class: "button secondary hollow" %>
|
||||
class: "button secondary hollow js-question-answer" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
|
||||
@@ -38,6 +38,13 @@
|
||||
<%= t("polls.show.already_voted_in_booth") %>
|
||||
</div>
|
||||
<% else %>
|
||||
|
||||
<% if !@poll.voters.find_by_user_id(current_user).present? %>
|
||||
<div class="callout primary js-token-message" style="display: none">
|
||||
<%= t('poll_questions.show.voted_token') %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% @questions.each do |question| %>
|
||||
<%= render 'polls/questions/question', question: question, token: @token %>
|
||||
<% end %>
|
||||
|
||||
@@ -497,7 +497,7 @@ en:
|
||||
show:
|
||||
vote_answer: "Vote %{answer}"
|
||||
voted: "You have voted %{answer}"
|
||||
voted_token: "You can write down this vote identifier, to check your vote on the final results."
|
||||
voted_token: "You can write down this vote identifier, to check your vote on the final results:"
|
||||
proposal_notifications:
|
||||
new:
|
||||
title: "Send message"
|
||||
|
||||
@@ -497,7 +497,7 @@ es:
|
||||
show:
|
||||
vote_answer: "Votar %{answer}"
|
||||
voted: "Has votado %{answer}"
|
||||
voted_token: "Puedes apuntar este identificador de voto, para comprobar tu votación en el resultado final"
|
||||
voted_token: "Puedes apuntar este identificador de voto, para comprobar tu votación en el resultado final:"
|
||||
proposal_notifications:
|
||||
new:
|
||||
title: "Enviar mensaje"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class AddTokenToPollVoters < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :poll_voters, :token, :string
|
||||
add_column :poll_voters, :token_seen_at, :date
|
||||
end
|
||||
end
|
||||
|
||||
@@ -761,7 +761,6 @@ ActiveRecord::Schema.define(version: 20171006145053) do
|
||||
t.string "origin"
|
||||
t.integer "officer_id"
|
||||
t.string "token"
|
||||
t.date "token_seen_at"
|
||||
end
|
||||
|
||||
add_index "poll_voters", ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id", using: :btree
|
||||
|
||||
Reference in New Issue
Block a user