This commit is contained in:
huang 2015-01-16 16:48:46 +08:00
commit b43e6558e1
4 changed files with 38 additions and 14 deletions

View File

@ -189,20 +189,26 @@ class PollController < ApplicationController
#单选题
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.poll_answer_id = params[:poll_answer_id]
if pv.save
#保存成功返回成功信息及当前以答题百分比
@percent = get_percent(@poll,User.current)
render :json => {:text => "ok" ,:percent => format("%.2f" ,@percent)}
else
#返回失败信息
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)
if pv.nil?
#尚未答该题,添加答案
pv = PollVote.new
pv.user_id = User.current.id
pv.poll_question_id = params[:poll_question_id]
@ -214,6 +220,7 @@ class PollController < ApplicationController
render :json => {:text => "failure"}
end
else
#pv不为空则当前选项之前已被选择再次点击则是不再选择该项故删除该答案
if pv.delete
@percent = get_percent(@poll,User.current)
render :json => {:text => "false" ,:percent => format("%.2f" ,@percent)}
@ -222,12 +229,16 @@ class PollController < ApplicationController
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为空之前尚未答题添加答案
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]
@ -240,7 +251,9 @@ class PollController < ApplicationController
end
end
else
#pv不为空说明用户之前已作答
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)}
@ -248,6 +261,7 @@ class PollController < ApplicationController
render :json => {:text => "failure"}
end
else
#用户修改答案
pv.vote_text = params[:vote_text]
if pv.save
@percent = get_percent(@poll,User.current)
@ -346,7 +360,11 @@ class PollController < ApplicationController
def get_percent poll,user
complete_count = get_complete_question(poll,user).count
(complete_count.to_f / poll.poll_questions.count.to_f)*100
if poll.poll_questions.count == 0
return 0
else
return (complete_count.to_f / poll.poll_questions.count.to_f)*100
end
end
#PollUser记录用户是否已提交问卷有对应的记录则已提交没有则新建一个

View File

@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问卷调查_问卷页面</title>
<title><%= l(:label_poll_title) %></title>
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<style type="text/css">
.alert_box{width:480px;height:180px;position:fixed;z-index:100;left:55%;top:50%;margin:-215px 0 0 -300px; background:#fff; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; box-shadow:0px 0px 8px #194a81; overflow:auto;}
@ -46,10 +46,10 @@
<!-- 单选题 -->
<li class="ur_question_item radio">
<div class="ur_title">
<span class="title_index"><%= pq.question_number %>题:</span>
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
@ -95,10 +95,10 @@
<!-- 多选题 -->
<li class="ur_question_item checkbox">
<div class="ur_title">
<span class="title_index"><%= pq.question_number %>题:</span>
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
@ -151,10 +151,10 @@
<!-- 单行文字-->
<li class="ur_question_item text">
<div class="ur_title">
<span class="title_index"><%= pq.question_number %>题:</span>
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
@ -188,10 +188,10 @@
<li class="ur_question_item textarea">
<div class="ur_preview">
<div class="ur_title">
<span class="title_index"><%= pq.question_number %>题:</span>
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="必答">*</span>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
@ -237,11 +237,11 @@
<div class="cl"></div>
<div class="ur_buttons" style="width: 100px;">
<% if @poll.polls_status == 2 %>
<%= link_to "提交",commit_poll_poll_path(@poll), :method => :post,:class => "ur_button",:format => 'js',:remote=>true %>
<%= link_to l(:button_submit),commit_poll_poll_path(@poll), :method => :post,:class => "ur_button",:format => 'js',:remote=>true %>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_progress_text">答题已完成 <strong class="ur_progress_number"><span id="percent"><%= format "%.2f" ,@percent %></span>%</strong> </div>
<div class="ur_progress_text"><%= l(:label_complete_question) %> <strong class="ur_progress_number"><span id="percent"><%= format "%.2f" ,@percent %></span>%</strong> </div>
</div>

View File

@ -1817,8 +1817,10 @@ en:
label_record: 湘ICP备09019772
label_check_comment: Check comment
label_notification: Notification
label_must_answer: Will answer
label_poll_title: The questionnaire survey _ questionnaire page
label_question_number: 'question %{question_number}:'
label_complete_question: The answer has been completed
#end
# ajax异步验证

View File

@ -964,6 +964,8 @@ zh:
label_default: 默认
label_search_titles_only: 仅在标题中搜索
label_user_mail_option_all: "收取我的项目的所有通知"
label_must_answer: "必答"
label_poll_title: 问卷调查_问卷页面
#huang
label_file_new: 下载
label_user_edit: "修改资料"
@ -1419,6 +1421,8 @@ zh:
other: 参与了 %{count} 个项目:
#end
label_total_commit: 共%{total_commit}次提交
label_question_number: 第%{question_number}题:
label_complete_question: 答题已完成
#modify by men
label_x_total_commit:
zero: 共 %{count} 次提交