diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index cec9b3a34..feeb3c324 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -60,12 +60,14 @@ class PollController < ApplicationController end def update - @poll.polls_name = params[:polls_name] + @poll.polls_name = params[:polls_name].empty? ? l(:label_poll_title) : params[:polls_name] + @poll.polls_description = params[:polls_description].empty? ? l(:label_poll_description) : params[:polls_description] if @poll.save respond_to do |format| - format.html { redirect_to poll_index_url(:polls_type => @course.class.to_s, :polls_group_id => @course.id) } + format.js end else + render_404 end end @@ -87,7 +89,7 @@ class PollController < ApplicationController def create_poll_question question_title = params[:poll_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] option = { - :is_necessary => params[:is_necessary] || true, + :is_necessary => (params[:is_necessary]=="true" ? 1 : 0), :question_title => question_title, :question_type => params[:question_type] || 1, :question_number => @poll.poll_questions.count + 1 @@ -98,7 +100,7 @@ class PollController < ApplicationController 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] question_option = { :answer_position => i, - :answer_text => params[:question_answer].values[i-1] + :answer_text => answer } @poll_questions.poll_answers.new question_option end @@ -110,6 +112,32 @@ class PollController < ApplicationController end end + #修改单选题 + def update_poll_question + @poll_question = PollQuestion.find params[:poll_question] + @poll = @poll_question.poll + + respond_to do |format| + format.js + end + end + + #删除单选题 + def delete_poll_question + @poll_question = PollQuestion.find params[:poll_question] + @poll = @poll_question.poll + poll_questions = @poll.poll_questions.where("question_number > #{@poll_question.question_number}") + poll_questions.each do |question| + question.question_number -= 1 + question.save + end + if @poll_question && @poll_question.destroy + respond_to do |format| + format.js + end + end + end + #提交答案 def commit_answer pq = PollQuestion.find(params[:poll_question_id]) diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb index 0f031f61c..fa0e8d802 100644 --- a/app/views/poll/_edit_MC.html.erb +++ b/app/views/poll/_edit_MC.html.erb @@ -1,45 +1,31 @@ -<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> -
- -
-
- - - - - -
-
-
    -
  • - - - - -
  • -
    -
  • - - - - -
  • -
    -
  • - - - - -
  • -
    -
-
- -
+<%= form_for(poll_question,:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%> + +
+
+ + + + /> +
- +
+
    + <% poll_question.poll_answers.reorder("answer_position").each do |poll_answer| %> +
  • + + + + +
  • +
    + <% end%> +
+
+ +
+ <% end%> \ No newline at end of file diff --git a/app/views/poll/_edit_head.html.erb b/app/views/poll/_edit_head.html.erb index 759fe58a1..ea36cbedf 100644 --- a/app/views/poll/_edit_head.html.erb +++ b/app/views/poll/_edit_head.html.erb @@ -1,21 +1,15 @@ - -
-
- -
-
- -
- -
-
\ No newline at end of file +<%= form_for @poll,:remote => true do |f|%> +
+
+ +
+
+ +
+ +
+
+<% end%> diff --git a/app/views/poll/_new_MC.html.erb b/app/views/poll/_new_MC.html.erb new file mode 100644 index 000000000..013bf0ed0 --- /dev/null +++ b/app/views/poll/_new_MC.html.erb @@ -0,0 +1,45 @@ +<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%> +
+ +
+
+ + + + + +
+
+
    +
  • + + + + +
  • +
    +
  • + + + + +
  • +
    +
  • + + + + +
  • +
    +
+
+ +
+
+ +
+<% end%> \ No newline at end of file diff --git a/app/views/poll/_new_MCQ.html.erb b/app/views/poll/_new_MCQ.html.erb new file mode 100644 index 000000000..6739c233e --- /dev/null +++ b/app/views/poll/_new_MCQ.html.erb @@ -0,0 +1,33 @@ +
+
+
+ + + + +
+
+
    +
  • + + + + +
  • +
    +
  • + + + + +
  • +
    +
+
+ +
+
+
\ No newline at end of file diff --git a/app/views/poll/_new_mulit.html.erb b/app/views/poll/_new_mulit.html.erb new file mode 100644 index 000000000..6c3528473 --- /dev/null +++ b/app/views/poll/_new_mulit.html.erb @@ -0,0 +1,18 @@ +
+
+ + + + +
+
+ + , + +
+ +
+
\ No newline at end of file diff --git a/app/views/poll/_new_single.html.erb b/app/views/poll/_new_single.html.erb new file mode 100644 index 000000000..b7d5a9725 --- /dev/null +++ b/app/views/poll/_new_single.html.erb @@ -0,0 +1,13 @@ +
+
+ + + + +
+ +
+
\ No newline at end of file diff --git a/app/views/poll/_poll_content.html.erb b/app/views/poll/_poll_content.html.erb new file mode 100644 index 000000000..6c2e61215 --- /dev/null +++ b/app/views/poll/_poll_content.html.erb @@ -0,0 +1,10 @@ +<% poll.poll_questions.each do |poll_question|%> +
+
+ <%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %> +
+ +
+<% end %> \ No newline at end of file diff --git a/app/views/poll/_poll_form.html.erb b/app/views/poll/_poll_form.html.erb index 473c1df83..04d8e2f6e 100644 --- a/app/views/poll/_poll_form.html.erb +++ b/app/views/poll/_poll_form.html.erb @@ -4,16 +4,42 @@ 问卷调查_问卷编辑 <%= stylesheet_link_tag 'polls', :media => 'all' %> + <%#= javascript_include_tag "polls" %>