diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index 3e5e131c8..a843e9d9b 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -123,6 +123,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| + 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] + 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/_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 e69de29bb..39d0fcfd6 100644 --- a/app/views/poll/update_poll_question.js.erb +++ b/app/views/poll/update_poll_question.js.erb @@ -0,0 +1,6 @@ +$("#poll_questions_<%= @poll_question.id%>").html("
" + + "<%= escape_javascript(render :partial => 'show_MC', :locals => {:poll_question => @poll_question}) %>" + + "
" + + "");