diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e81e74f34..bccb2132b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -50,6 +50,7 @@ //= require markdown_editor //= require cocoon //= require allegations +//= require legislation_questions //= require custom var initialize_modules = function() { @@ -74,6 +75,7 @@ var initialize_modules = function() { App.SocialShare.initialize(); App.MarkdownEditor.initialize(); App.Allegations.initialize(); + App.LegislationQuestions.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/legislation_questions.js.coffee b/app/assets/javascripts/legislation_questions.js.coffee new file mode 100644 index 000000000..f8bea46f3 --- /dev/null +++ b/app/assets/javascripts/legislation_questions.js.coffee @@ -0,0 +1,8 @@ +App.LegislationQuestions = + + initialize: -> + $('form#new_legislation_answer input.button').hide() + $('form#new_legislation_answer input[type=radio]').on + click: -> + $('form#new_legislation_answer').submit() + diff --git a/app/controllers/legislation/answers_controller.rb b/app/controllers/legislation/answers_controller.rb index 156cbc68b..b090a605a 100644 --- a/app/controllers/legislation/answers_controller.rb +++ b/app/controllers/legislation/answers_controller.rb @@ -6,10 +6,16 @@ class Legislation::AnswersController < Legislation::BaseController load_and_authorize_resource :question, through: :process load_and_authorize_resource :answer, through: :question + respond_to :html, :js + def create @answer.user = current_user @answer.save - redirect_to legislation_process_question_path(@process, @question) + + respond_to do |format| + format.js {} + format.html { redirect_to legislation_process_question_path(@process, @question) } + end end private diff --git a/app/views/legislation/answers/create.js.erb b/app/views/legislation/answers/create.js.erb new file mode 100644 index 000000000..468b2610b --- /dev/null +++ b/app/views/legislation/answers/create.js.erb @@ -0,0 +1 @@ +$("#legislation-answer-form").html('<%= j render("legislation/questions/answer_form", process: @process, question: @question, answer: @answer) %>'); diff --git a/app/views/legislation/questions/_answer_form.html.erb b/app/views/legislation/questions/_answer_form.html.erb new file mode 100644 index 000000000..01254f021 --- /dev/null +++ b/app/views/legislation/questions/_answer_form.html.erb @@ -0,0 +1,12 @@ +<% 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| %> + + <% end %> + <%= f.submit t('legislation.questions.show.answer_question'), class: "button" unless answer.persisted? %> + <% end %> +<% end %> diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index eda42d239..41e8f9f96 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -22,19 +22,8 @@

<%= @question.title %>

-
- <% if @question.question_options.any? %> - <%= form_for @answer, url: legislation_process_question_answers_path(@process, @question, @answer), class: "controls-stacked" do |f| %> - <% @question.question_options.each do |question_option| %> - - <% end %> - <%= f.submit t('.answer_question'), class: "button" unless @answer.persisted? %> - <% end %> - <% end %> +
+ <%= render 'answer_form', process: @process, question: @question, answer: @answer %>
diff --git a/spec/features/legislation/debate_spec.rb b/spec/features/legislation/questions_spec.rb similarity index 100% rename from spec/features/legislation/debate_spec.rb rename to spec/features/legislation/questions_spec.rb