Extract methods in poll callout component
This commit is contained in:
@@ -1,32 +1,17 @@
|
|||||||
<% if can?(:answer, poll) %>
|
<% if can?(:answer, poll) %>
|
||||||
<% if poll.voted_in_booth?(current_user) %>
|
<% if voted_in_booth? %>
|
||||||
<div class="callout warning">
|
<%= callout(t("polls.show.already_voted_in_booth")) %>
|
||||||
<%= t("polls.show.already_voted_in_booth") %>
|
<% elsif voted_in_web? %>
|
||||||
</div>
|
<%= callout(t("polls.show.already_voted_in_web")) %>
|
||||||
<% elsif poll.voted_in_web?(current_user) %>
|
|
||||||
<div class="callout warning">
|
|
||||||
<%= t("polls.show.already_voted_in_web") %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<% if current_user.nil? %>
|
<% if current_user.nil? %>
|
||||||
<div class="callout primary">
|
<%= callout(not_logged_in_text, html_class: "primary") %>
|
||||||
<%= sanitize(t("polls.show.cant_answer_not_logged_in",
|
|
||||||
signin: link_to_signin(class: "probe-message"),
|
|
||||||
signup: link_to_signup(class: "probe-message"))) %>
|
|
||||||
</div>
|
|
||||||
<% elsif current_user.unverified? %>
|
<% elsif current_user.unverified? %>
|
||||||
<div class="callout warning">
|
<%= callout(unverified_text) %>
|
||||||
<%= sanitize(t("polls.show.cant_answer_verify",
|
|
||||||
verify_link: link_to(t("polls.show.verify_link"), verification_path))) %>
|
|
||||||
</div>
|
|
||||||
<% elsif poll.expired? %>
|
<% elsif poll.expired? %>
|
||||||
<div class="callout alert">
|
<%= callout(t("polls.show.cant_answer_expired"), html_class: "alert") %>
|
||||||
<%= t("polls.show.cant_answer_expired") %>
|
|
||||||
</div>
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="callout warning">
|
<%= callout(t("polls.show.cant_answer_wrong_geozone")) %>
|
||||||
<%= t("polls.show.cant_answer_wrong_geozone") %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -5,4 +5,29 @@ class Polls::CalloutComponent < ApplicationComponent
|
|||||||
def initialize(poll)
|
def initialize(poll)
|
||||||
@poll = poll
|
@poll = poll
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def voted_in_booth?
|
||||||
|
poll.voted_in_booth?(current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def voted_in_web?
|
||||||
|
poll.voted_in_web?(current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def callout(text, html_class: "warning")
|
||||||
|
tag.div(text, class: "callout #{html_class}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def not_logged_in_text
|
||||||
|
sanitize(t("polls.show.cant_answer_not_logged_in",
|
||||||
|
signin: link_to_signin(class: "probe-message"),
|
||||||
|
signup: link_to_signup(class: "probe-message")))
|
||||||
|
end
|
||||||
|
|
||||||
|
def unverified_text
|
||||||
|
sanitize(t("polls.show.cant_answer_verify",
|
||||||
|
verify_link: link_to(t("polls.show.verify_link"), verification_path)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user