From f41cd0a8ab7f1d682e1df454535c1095772e8fd1 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 16 Jan 2015 10:11:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=8D=95=E9=80=89?= =?UTF-8?q?=E9=A2=98=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?= =?UTF-8?q?=202.=E5=88=A0=E9=99=A4=E9=80=89=E9=A1=B9=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=8D=95=E9=80=89=E9=A2=98=E8=87=B3=E5=B0=91=E6=9C=89=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 24 ++++++++++++++++++++++ app/views/poll/_edit_MC.html.erb | 2 +- app/views/poll/_poll_form.html.erb | 2 +- app/views/poll/update_poll_question.js.erb | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 356a669b7..2f3c344cb 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -117,6 +117,30 @@ class PollController < ApplicationController @poll_question = PollQuestion.find params[:poll_question] @poll = @poll_question.poll + @poll_question.is_necessary = params[:is_necessary]=="true" ? 1 : 0 + @poll_question.question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] + ################处理选项 + if params[:question_answer] + @poll_question.poll_answers.each do |answer| + @poll_question.poll_answers.destroy answer unless params[:question_answer].keys.include? answer.id.to_s + end + for i in 1..params[:question_answer].count + question = @poll_question.poll_answers.find_by_id params[:question_answer].keys[i-1] + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + if question + question.answer_position = i + question.answer_text = answer + question.save + else + question_option = { + :answer_position => i, + :answer_text => answer + } + @poll_question.poll_answers.new question_option + end + end + end + @poll_question.save respond_to do |format| format.js end diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb index fa0e8d802..12dc9f92b 100644 --- a/app/views/poll/_edit_MC.html.erb +++ b/app/views/poll/_edit_MC.html.erb @@ -1,4 +1,4 @@ -<%= form_for(poll_question,:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%> +<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
diff --git a/app/views/poll/_poll_form.html.erb b/app/views/poll/_poll_form.html.erb index 04d8e2f6e..598ef1207 100644 --- a/app/views/poll/_poll_form.html.erb +++ b/app/views/poll/_poll_form.html.erb @@ -47,7 +47,7 @@ { if(doc.parent().siblings("li").length == 0) { - doc.parent().parent().parent().parent().parent().parent().remove(); + alert("选择题至少有一个选项"); } else { diff --git a/app/views/poll/update_poll_question.js.erb b/app/views/poll/update_poll_question.js.erb index e69de29bb..267a27ae2 100644 --- a/app/views/poll/update_poll_question.js.erb +++ b/app/views/poll/update_poll_question.js.erb @@ -0,0 +1,2 @@ + +pollQuestionCancel(<%= @poll_question.id%>); \ No newline at end of file From 9fb0275563b12d3416662f35a7e9b71bbc478724 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 16 Jan 2015 10:43:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=8D=95=E9=80=89=E9=A2=98=E6=97=B6=E9=A1=B5=E9=9D=A2js?= =?UTF-8?q?=E7=9A=84=E5=88=B7=E6=96=B0=202.=E4=BF=AE=E6=94=B9=E5=8D=95?= =?UTF-8?q?=E9=80=89=E9=A2=98=E6=97=B6=E5=88=A0=E9=99=A4=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_controller.rb | 2 +- app/views/poll/_poll_question.html.erb | 12 ++++++++++++ app/views/poll/update_poll_question.js.erb | 8 ++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 app/views/poll/_poll_question.html.erb diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 2f3c344cb..c82b9a385 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -122,7 +122,7 @@ class PollController < ApplicationController ################处理选项 if params[:question_answer] @poll_question.poll_answers.each do |answer| - @poll_question.poll_answers.destroy answer unless params[:question_answer].keys.include? answer.id.to_s + answer.destroy unless params[:question_answer].keys.include? answer.id.to_s end for i in 1..params[:question_answer].count question = @poll_question.poll_answers.find_by_id params[:question_answer].keys[i-1] diff --git a/app/views/poll/_poll_question.html.erb b/app/views/poll/_poll_question.html.erb new file mode 100644 index 000000000..7731c9821 --- /dev/null +++ b/app/views/poll/_poll_question.html.erb @@ -0,0 +1,12 @@ + +<% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %> + + + + + +<% end %> + \ No newline at end of file diff --git a/app/views/poll/update_poll_question.js.erb b/app/views/poll/update_poll_question.js.erb index 267a27ae2..39d0fcfd6 100644 --- a/app/views/poll/update_poll_question.js.erb +++ b/app/views/poll/update_poll_question.js.erb @@ -1,2 +1,6 @@ - -pollQuestionCancel(<%= @poll_question.id%>); \ No newline at end of file +$("#poll_questions_<%= @poll_question.id%>").html("
" + + "<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_question}) %>" + + "
" + + "");