Check if debate phase is open to create answers
This commit is contained in:
@@ -9,12 +9,19 @@ class Legislation::AnswersController < Legislation::BaseController
|
||||
respond_to :html, :js
|
||||
|
||||
def create
|
||||
@answer.user = current_user
|
||||
@answer.save
|
||||
|
||||
respond_to do |format|
|
||||
format.js {}
|
||||
format.html { redirect_to legislation_process_question_path(@process, @question) }
|
||||
if @process.open_phase?(:debate)
|
||||
@answer.user = current_user
|
||||
@answer.save
|
||||
track_event
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { redirect_to legislation_process_question_path(@process, @question) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { redirect_to legislation_process_question_path(@process, @question), alert: t('legislation.questions.participation.phase_not_open') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,4 +31,11 @@ class Legislation::AnswersController < Legislation::BaseController
|
||||
:legislation_question_option_id,
|
||||
)
|
||||
end
|
||||
|
||||
def track_event
|
||||
ahoy.track "legislation_answer_created".to_sym,
|
||||
"legislation_answer_id": @answer.id,
|
||||
"legislation_question_option_id": @answer.legislation_question_option_id,
|
||||
"legislation_question_id": @answer.legislation_question_id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,12 +1,28 @@
|
||||
<% if question.question_options.any? %>
|
||||
<%= form_for answer, url: legislation_process_question_answers_path(process, question, answer), remote: true , html: { class: "controls-stacked participation-allowed"} do |f| %>
|
||||
<% question.question_options.each do |question_option| %>
|
||||
<label class="control radio <%= 'active' if @answer.legislation_question_option_id == question_option.id %>">
|
||||
<%= f.radio_button :legislation_question_option_id, question_option.id, label: false, disabled: answer.persisted? %>
|
||||
<span class="control-indicator"></span>
|
||||
<%= question_option.value %>
|
||||
</label>
|
||||
<% if process.open_phase?(:debate) && !answer.persisted? %>
|
||||
|
||||
<%= form_for answer, url: legislation_process_question_answers_path(process, question, answer), remote: true , html: { class: "controls-stacked"} do |f| %>
|
||||
<% question.question_options.each do |question_option| %>
|
||||
<label class="control radio <%= 'active' if @answer.legislation_question_option_id == question_option.id %>">
|
||||
<%= f.radio_button :legislation_question_option_id, question_option.id, label: false %>
|
||||
<span class="control-indicator"></span>
|
||||
<%= question_option.value %>
|
||||
</label>
|
||||
<% end %>
|
||||
<%= f.submit t('legislation.questions.show.answer_question'), class: "button" %>
|
||||
<% end %>
|
||||
<%= f.submit t('legislation.questions.show.answer_question'), class: "button" unless answer.persisted? %>
|
||||
|
||||
<% else %>
|
||||
|
||||
<form class="controls-stacked disabled">
|
||||
<% question.question_options.each do |question_option| %>
|
||||
<label class="control radio <%= 'active' if answer.persisted? && (answer.legislation_question_option_id == question_option.id) %>">
|
||||
<input id="quiz-1" name="radio" type="radio" disabled="true">
|
||||
<span class="control-indicator"></span>
|
||||
<%= question_option.value %>
|
||||
</label>
|
||||
<% end %>
|
||||
</form>
|
||||
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user