diff --git a/app/controllers/poll_controller.rb b/app/controllers/poll_controller.rb
index 3b4bf3694..72209b834 100644
--- a/app/controllers/poll_controller.rb
+++ b/app/controllers/poll_controller.rb
@@ -24,6 +24,7 @@ class PollController < ApplicationController
render_403
else
@can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin?
+ @percent = get_percent(@poll,User.current)
poll_questions = @poll.poll_questions
@poll_questions = paginateHelper poll_questions,3 #分页
respond_to do |format|
@@ -131,8 +132,7 @@ class PollController < ApplicationController
#修改单选题
def update_poll_question
@poll_question = PollQuestion.find params[:poll_question]
- @poll = @poll_question.poll
-
+ #@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]
################处理选项
@@ -182,7 +182,7 @@ class PollController < ApplicationController
def commit_answer
pq = PollQuestion.find(params[:poll_question_id])
if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?)
- render :text => 'failure'
+ render :json => {:text => "failure"}
return
end
if pq.question_type == 1
@@ -195,9 +195,10 @@ class PollController < ApplicationController
end
pv.poll_answer_id = params[:poll_answer_id]
if pv.save
- render :text => "ok"
+ @percent = get_percent(@poll,User.current)
+ render :json => {:text => "ok" ,:percent => format("%.2f" ,@percent)}
else
- render :text => "failure"
+ render :json => {:text => "failure"}
end
elsif pq.question_type == 2
pv = PollVote.find_by_poll_answer_id_and_user_id(params[:poll_answer_id],User.current.id)
@@ -207,38 +208,64 @@ class PollController < ApplicationController
pv.poll_question_id = params[:poll_question_id]
pv.poll_answer_id = params[:poll_answer_id]
if pv.save
- render :text => "true"
+ @percent = get_percent(@poll,User.current)
+ render :json => {:text => "true",:percent => format("%.2f" ,@percent)}
else
- render :text => "failure"
+ render :json => {:text => "failure"}
end
else
if pv.delete
- render :text => "false"
+ @percent = get_percent(@poll,User.current)
+ render :json => {:text => "false" ,:percent => format("%.2f" ,@percent)}
else
- render :text => "failure"
+ render :json => {:text => "failure"}
end
end
elsif pq.question_type == 3 || pq.question_type == 4
pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id)
if pv.nil?
- pv = PollVote.new
- pv.user_id = User.current.id
- pv.poll_question_id = params[:poll_question_id]
- end
- pv.vote_text = params[:vote_text]
- if pv.save
- render :text => pv.vote_text
+ if params[:vote_text].nil? || params[:vote_text].blank?
+ @percent = get_percent(@poll,User.current)
+ render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
+ else
+ pv = PollVote.new
+ pv.user_id = User.current.id
+ pv.poll_question_id = params[:poll_question_id]
+ pv.vote_text = params[:vote_text]
+ if pv.save
+ @percent = get_percent(@poll,User.current)
+ render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ end
else
- render :text => "failure"
+ if params[:vote_text].nil? || params[:vote_text].blank?
+ if pv.delete
+ @percent = get_percent(@poll,User.current)
+ render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ else
+ pv.vote_text = params[:vote_text]
+ if pv.save
+ @percent = get_percent(@poll,User.current)
+ render :json => {:text => pv.vote_text,:percent => format("%.2f" ,@percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ end
end
+
else
- render :text => "failure"
+ render :json => {:text => "failure"}
end
end
#提交问卷
def commit_poll
- @uncomplete_question = get_uncomplete_question(@poll)
+ @uncomplete_question = get_uncomplete_question(@poll,User.current)
if @uncomplete_question.count < 1
pu = get_poll_user(@poll.id,User.current.id)
pu.user_id = User.current.id
@@ -287,17 +314,41 @@ class PollController < ApplicationController
end
#获取未完成的题目
- def get_uncomplete_question poll
+ def get_uncomplete_question poll,user
necessary_questions = poll.poll_questions.where("#{PollQuestion.table_name}.is_necessary = 1")
uncomplete_question = []
necessary_questions.each do |question|
- if question.poll_votes.nil? || question.poll_votes.count < 1
+ answers = get_user_answer(question,user)
+ if answers.nil? || answers.count < 1
uncomplete_question << question
end
end
uncomplete_question
end
+ #获取用户对某个问题的答案
+ def get_user_answer(question,user)
+ user_answer = question.poll_votes.where("#{PollVote.table_name}.user_id = #{user.id}")
+ user_answer
+ end
+
+ def get_complete_question(poll,user)
+ questions = poll.poll_questions
+ complete_question = []
+ questions.each do |question|
+ answers = get_user_answer(question,user)
+ if !(answers.nil? || answers.count < 1)
+ complete_question << question
+ end
+ end
+ complete_question
+ end
+
+ def get_percent poll,user
+ complete_count = get_complete_question(poll,user).count
+ (complete_count.to_f / poll.poll_questions.count.to_f)*100
+ end
+
#PollUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个
def get_poll_user poll_id,user_id
pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id)
diff --git a/app/views/poll/_commit_alert.html.erb b/app/views/poll/_commit_alert.html.erb
index 76bbda416..3910bc8b5 100644
--- a/app/views/poll/_commit_alert.html.erb
+++ b/app/views/poll/_commit_alert.html.erb
@@ -3,7 +3,7 @@
提交成功!
<%= link_to "确定", poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course'),:class => 'commit'%>
<% elsif status == 1 %>
- 您还有尚未作答的题目请完成后在提交!
+ 您还有尚未作答的必答题目请完成后再提交!
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
<% else %>
发生未知错误,请检查您的网络。
diff --git a/app/views/poll/_edit_MCQ.html.erb b/app/views/poll/_edit_MCQ.html.erb
index cf64e7f3e..f34319569 100644
--- a/app/views/poll/_edit_MCQ.html.erb
+++ b/app/views/poll/_edit_MCQ.html.erb
@@ -1,33 +1,28 @@
-
+<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
-
\ No newline at end of file
+
+<% end%>
\ No newline at end of file
diff --git a/app/views/poll/_edit_mulit.html.erb b/app/views/poll/_edit_mulit.html.erb
index c4a9e0e0f..684a285e3 100644
--- a/app/views/poll/_edit_mulit.html.erb
+++ b/app/views/poll/_edit_mulit.html.erb
@@ -1,18 +1,21 @@
+<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
\ No newline at end of file
+
+<% end%>
\ No newline at end of file
diff --git a/app/views/poll/_edit_single.html.erb b/app/views/poll/_edit_single.html.erb
index 4e98babe4..b8157ee6c 100644
--- a/app/views/poll/_edit_single.html.erb
+++ b/app/views/poll/_edit_single.html.erb
@@ -1,13 +1,17 @@
+<%= form_for("",:url => update_poll_question_poll_index_path(:poll_question => poll_question.id),:remote => true) do |f|%>
\ No newline at end of file
+
+<% end%>
\ No newline at end of file
diff --git a/app/views/poll/_new_MC.html.erb b/app/views/poll/_new_MC.html.erb
index 013bf0ed0..5ff70e9eb 100644
--- a/app/views/poll/_new_MC.html.erb
+++ b/app/views/poll/_new_MC.html.erb
@@ -1,6 +1,5 @@
<%= 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
index 6739c233e..d94964bbf 100644
--- a/app/views/poll/_new_MCQ.html.erb
+++ b/app/views/poll/_new_MCQ.html.erb
@@ -1,33 +1,41 @@
-
+<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>
-
\ No newline at end of file
+<% end%>
\ No newline at end of file
diff --git a/app/views/poll/_new_mulit.html.erb b/app/views/poll/_new_mulit.html.erb
index 6c3528473..e034e54af 100644
--- a/app/views/poll/_new_mulit.html.erb
+++ b/app/views/poll/_new_mulit.html.erb
@@ -1,18 +1,21 @@
+<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>
\ No newline at end of file
+
+<% end%>
\ No newline at end of file
diff --git a/app/views/poll/_new_single.html.erb b/app/views/poll/_new_single.html.erb
index b7d5a9725..ec06933a8 100644
--- a/app/views/poll/_new_single.html.erb
+++ b/app/views/poll/_new_single.html.erb
@@ -1,13 +1,16 @@
-
\ No newline at end of file
+<%= 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/_poll_content.html.erb b/app/views/poll/_poll_content.html.erb
index 6c2e61215..40c9a6181 100644
--- a/app/views/poll/_poll_content.html.erb
+++ b/app/views/poll/_poll_content.html.erb
@@ -1,10 +1,26 @@
<% poll.poll_questions.each do |poll_question|%>
- <%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %>
+ <% if poll_question.question_type == 1%>
+ <%= render :partial => 'show_MC', :locals => {:poll_question => poll_question} %>
+ <% elsif poll_question.question_type == 2%>
+ <%= render :partial => 'show_MCQ', :locals => {:poll_question => poll_question} %>
+ <% elsif poll_question.question_type == 3%>
+ <%= render :partial => 'show_single', :locals => {:poll_question => poll_question} %>
+ <% elsif poll_question.question_type == 4%>
+ <%= render :partial => 'show_mulit', :locals => {:poll_question => poll_question} %>
+ <% end%>
- <%= render :partial => 'edit_MC', :locals => {:poll_question => poll_question} %>
+ <% if poll_question.question_type == 1%>
+ <%= render :partial => 'edit_MC', :locals => {:poll_question => poll_question} %>
+ <% elsif poll_question.question_type == 2%>
+ <%= render :partial => 'edit_MCQ', :locals => {:poll_question => poll_question} %>
+ <% elsif poll_question.question_type == 3%>
+ <%= render :partial => 'edit_single', :locals => {:poll_question => poll_question} %>
+ <% elsif poll_question.question_type == 4%>
+ <%= render :partial => 'edit_mulit', :locals => {:poll_question => poll_question} %>
+ <% end%>
<% 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 598ef1207..1b30c973d 100644
--- a/app/views/poll/_poll_form.html.erb
+++ b/app/views/poll/_poll_form.html.erb
@@ -60,6 +60,19 @@
+
+
+ <%= render :partial => 'show_head', :locals => {:poll => @poll}%>
+
+
+ <%= render :partial => 'edit_head', :locals => {:poll => @poll}%>
+
+
+
+
+ <%= render :partial => 'poll_content', :locals => {:poll => @poll}%>
+
+
-
-
- <%= render :partial => 'show_head', :locals => {:poll => @poll}%>
-
-
- <%= render :partial => 'edit_head', :locals => {:poll => @poll}%>
-
-
-
-
- <%= render :partial => 'poll_content', :locals => {:poll => @poll}%>
-
-
diff --git a/app/views/poll/_show_MC.html.erb b/app/views/poll/_show_MC.html.erb
index f3fc9c8b5..594baea9d 100644
--- a/app/views/poll/_show_MC.html.erb
+++ b/app/views/poll/_show_MC.html.erb
@@ -7,7 +7,7 @@
<%if poll_question.is_necessary == 1%>
*
<%end%>
-
+ (单选题)
<%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id),
method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %>
diff --git a/app/views/poll/_show_MCQ.html.erb b/app/views/poll/_show_MCQ.html.erb
index e56de53b9..64e39523a 100644
--- a/app/views/poll/_show_MCQ.html.erb
+++ b/app/views/poll/_show_MCQ.html.erb
@@ -1,28 +1,31 @@
- 第2题: 多选题 *
+
+ 第<%= poll_question.question_number%>题:
+
+ <%= poll_question.question_title %>
+ <%if poll_question.is_necessary == 1%>
+ *
+ <%end%>
+ (多选题)
-
-
+ <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id),
+ method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %>
+
diff --git a/app/views/poll/_show_mulit.html.erb b/app/views/poll/_show_mulit.html.erb
index 35e37ef06..23bdbe6eb 100644
--- a/app/views/poll/_show_mulit.html.erb
+++ b/app/views/poll/_show_mulit.html.erb
@@ -1,10 +1,18 @@
- 第4题: 多行主观
+
+ 第<%= poll_question.question_number%>题:
+
+ <%= poll_question.question_title %>
+ <%if poll_question.is_necessary == 1%>
+ *
+ <%end%>
+ (多行主观)
-
-
+ <%= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id),
+ method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %>
+