问卷增加其他选项、多行主观题的改版

This commit is contained in:
cxt 2016-10-13 10:17:09 +08:00
parent 399b982e0d
commit 8b4c02ec98
11 changed files with 650 additions and 409 deletions

View File

@ -106,8 +106,12 @@ class PollController < ApplicationController
polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2")
end
@polls = paginateHelper polls,20 #分页
respond_to do |format|
format.js
if params[:is_redirect]
redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id)
else
respond_to do |format|
format.js
end
end
end
end
@ -271,6 +275,7 @@ class PollController < ApplicationController
end
#修改该题对应答案
pv.poll_answer_id = params[:poll_answer_id]
pv.vote_text = params[:vote_text] if params[:vote_text]
if pv.save
#保存成功返回成功信息及当前以答题百分比
@percent = get_percent(@poll,User.current)
@ -288,9 +293,10 @@ class PollController < ApplicationController
pv.user_id = User.current.id
pv.poll_question_id = params[:poll_question_id]
pv.poll_answer_id = params[:poll_answer_id]
pv.vote_text = params[:vote_text] if params[:vote_text]
if pv.save
@percent = get_percent(@poll,User.current)
render :json => {:text => "true",:percent => format("%.2f" ,@percent)}
render :json => {:text => "ok",:percent => format("%.2f" ,@percent)}
else
render :json => {:text => "failure"}
end
@ -303,8 +309,8 @@ class PollController < ApplicationController
render :json => {:text => "failure"}
end
end
elsif pq.question_type == 3 || pq.question_type == 4
#单行文本,多行文本题
elsif pq.question_type == 3
#单行文本
pv = PollVote.find_by_poll_question_id_and_user_id(params[:poll_question_id],User.current.id)
if pv.nil?
#pv为空之前尚未答题添加答案
@ -346,6 +352,50 @@ class PollController < ApplicationController
end
end
end
elsif pq.question_type == 4
#多行文本题
pv = PollVote.find_by_poll_question_id_and_poll_answer_id_and_user_id(params[:poll_question_id],params[:poll_answer_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]
pv.poll_answer_id = params[:poll_answer_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
#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)}
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 :json => {:text => "failure"}
@ -585,19 +635,31 @@ class PollController < ApplicationController
complete_question = []
questions.each do |question|
answers = get_user_answer(question,user)
if !(answers.nil? || answers.count < 1)
complete_question << question
if question.question_type != 4
if !(answers.nil? || answers.count < 1)
complete_question << question
end
else
if !(answers.nil? || answers.count < 1)
answers.each do |ans|
complete_question << ans
end
end
end
end
complete_question
end
def get_percent poll,user
complete_count = get_complete_question(poll,user).count
if poll.poll_questions.count == 0
return 0
else
return (complete_count.to_f / poll.poll_questions.count.to_f)*100
complete_count = get_complete_question(poll,user).count
all_count = poll.poll_questions.where("question_type != 4").count
poll.poll_questions.where("question_type = 4").each do |pq|
all_count += pq.poll_answers.count
end
return (complete_count.to_f / all_count.to_f)*100
end
end

View File

@ -29,12 +29,16 @@ module PollHelper
end
#获取文本题答案
def get_anwser_vote_text(question_id,user_id)
pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id)
if pv.nil?
def get_anwser_vote_text(question_id,user_id,answer_id=0)
if answer_id != 0
pv = PollVote.find_by_poll_question_id_and_poll_answer_id_and_user_id(question_id,answer_id,user_id)
else
pv = PollVote.find_by_poll_question_id_and_user_id(question_id,user_id)
end
if pv.blank?
''
else
pv.vote_text
pv.vote_text.nil? ? '' : pv.vote_text
end
end

View File

@ -0,0 +1,18 @@
<div class="sy_popup_top">
<h3 class="fl">提示</h3>
<a href="javascript:void(0);" class="sy_icons_close fr" onclick="hideModal()"></a>
<div class="cl"></div>
</div>
<div>
<ul class="sy_popup_add mt10 mb10">
<li>
<p style="text-align: center">确认放弃该问卷吗?</p>
</li>
<li>
<label class="mr70">&nbsp;</label>
<%= link_to('确 定', poll_path(poll.id, :is_redirect => 1),:method => 'delete', :class => "sy_btn_blue fl") %>
<a href="javascript:void(0);" class="sy_btn_grey fl ml20" onclick="hideModal()">取&nbsp;&nbsp;消</a>
<div class="cl"></div>
</li>
</ul>
</div>

View File

@ -8,7 +8,7 @@
</tr>
<% poll_question.poll_answers.each do |poll_answer| %>
<tr>
<td class="td327"><%= poll_answer.answer_text %> </td>
<td class="td327"><%= poll_answer.answer_text == "" ? "其他" :poll_answer.answer_text %> </td>
<td class="td42"><%= poll_answer.poll_votes.count %> </td>
<td class="td287">
<div class="Bar">

View File

@ -1,7 +1,7 @@
<%= form_for @poll,:remote => true do |f|%>
<div class="testContainer"> <!--编辑头部start-->
<div>
<input type="text" maxlength="100" name="polls_name" id="polls_title" value="<%= @poll.polls_name %>" class="testTitle mb10" placeholder="新建卷,请先输入问卷标题"/>
<input type="text" maxlength="100" name="polls_name" id="polls_title" value="<%= @poll.polls_name %>" class="testTitle mb10" placeholder="新建卷,请先输入问卷标题"/>
</div>
<textarea name="polls_description" maxlength="300" id="polls_description" class="testDes" placeholder="请在此输入问卷描述">
<%= @poll.polls_description.html_safe if !@poll.polls_description.blank? %>

View File

@ -0,0 +1,31 @@
<% poll_question.poll_answers.each do |pa| %>
<div class="ml20">
<div class="ur_title_result">
<span class="title_index">
<%= pa.answer_position %>
</span>
<%= pa.answer_text %>
</div>
<div class="ur_table_result">
<table border="0" cellspacing="0" cellpadding="0" class="full_width">
<tbody>
<tr class="table_bluebg">
<td class="td_full"><%= l(:label_answer) %> </td>
</tr>
<% poll_question.poll_votes.where("poll_answer_id = #{pa.id}").each do |poll_vote| %>
<tr>
<td class="td_full"><%= poll_vote.vote_text.html_safe %> </td>
</tr>
<% end %>
<tr class="table_bluebg">
<td class="td_full">
<%= l(:label_poll_answer_valid_result) %>
<%= l(:label_answer_total) %>
<%= poll_question.poll_votes.where("poll_answer_id = #{pa.id}").count %>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<% end %>

View File

@ -51,12 +51,24 @@ function chooseQuestionType(quest_type,quest_id){
}
function add_MC(){
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_MC') %>");
$("#poll_questions_title_new").focus();
var forms = $("form.new_poll_question");
if($("#polls_head_edit").is(":visible")){
alert("请先保存问卷标题及问卷描述。");
}else if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_MC') %>");
$("#poll_questions_title_new").focus();
}
}
function insert_MC(quest_type,quest_num,quest_id){
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
var forms = $("form.new_poll_question");
if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") {
if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
'<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+
' <div class="questionEditContainer"> '+
'<div class="ur_editor_title"> '+
@ -111,171 +123,227 @@ function add_MC(){
'<div class="cl"></div>'+
'</div>'+
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
}
else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");
}
}
function add_MCQ(){
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_MCQ') %>");
$("#poll_questions_title_new").focus();
var forms = $("form.new_poll_question");
if($("#polls_head_edit").is(":visible")){
alert("请先保存问卷标题及问卷描述。");
}else if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_MCQ') %>");
$("#poll_questions_title_new").focus();
}
}
function insert_MCQ(quest_type,quest_num,quest_id){
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
'<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+
'<div class="questionEditContainer">'+
'<div class="ur_editor_title">'+
'<label>问题:&nbsp;&nbsp;</label>'+
'<input type="hidden" name="quest_id" value="'+quest_id+'"/>'+
'<input type="hidden" name="quest_num" value="'+quest_num+'"/>'+
'<input type="hidden" name="question_type" value="2"/>'+
'<input maxlength="250" class="questionTitle w570" type="text" name="poll_questions_title" id="poll_questions_title" placeholder="请输入多选题题目"/>'+
'<input type="checkbox" name="is_necessary" value="true" checked/>'+
'<label>必答</label>'+
'</div>'+
'<div class="ur_editor_content">'+
var forms = $("form.new_poll_question");
if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") {
if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
'<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+
'<div class="questionEditContainer">'+
'<div class="ur_editor_title">'+
'<label>问题:&nbsp;&nbsp;</label>'+
'<input type="hidden" name="quest_id" value="'+quest_id+'"/>'+
'<input type="hidden" name="quest_num" value="'+quest_num+'"/>'+
'<input type="hidden" name="question_type" value="2"/>'+
'<input maxlength="250" class="questionTitle w570" type="text" name="poll_questions_title" id="poll_questions_title" placeholder="请输入多选题题目"/>'+
'<input type="checkbox" name="is_necessary" value="true" checked/>'+
'<label>必答</label>'+
'</div>'+
'<div class="ur_editor_content">'+
'<ul>'+
'<li class="ur_item">'+
'<label>选项<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input maxlength="200" type="text" name="question_answer[0]" placeholder="输入选项内容"/>'+
'<a class="icon_remove" title="删除"" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item">'+
'<label>选项<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input maxlength="200" type="text" name="question_answer[1]" placeholder="输入选项内容"/>'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item">'+
'<label>选项<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input maxlength="200" type="text" name="question_answer[2]" placeholder="输入选项内容"/>'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'</ul>'+
'<ul>'+
'<li class="ur_item">'+
'<label>选项<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input maxlength="200" type="text" name="question_answer[0]" placeholder="输入选项内容"/>'+
'<a class="icon_remove" title="删除"" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item">'+
'<label>选项<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input maxlength="200" type="text" name="question_answer[1]" placeholder="输入选项内容"/>'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item">'+
'<label>选项<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input maxlength="200" type="text" name="question_answer[2]" placeholder="输入选项内容"/>'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'</ul>'+
'<ul>'+
'<li class="ur_item">'+
'<div class="dash-block new-question" onclick="add_single_answer($(this));">新建选项</div>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item">'+
'<a href="javascript:void(0);" class="ml50 fontGrey2" onclick="add_other_answer($(this))">添加[其他]选项</a>'+
'</li>'+
'<div class="cl"></div>'+
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="grey_btn fr borderRadius" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
'<%= l(:button_cancel)%>'+
'</a>'+
'<a class="blue_btn fr borderRadius mr5" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'</div>'+
'<div class="cl"></div>'+
'</div>'+
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
'<div class="dash-block new-question" onclick="add_single_answer($(this));">新建选项</div>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item">'+
'<a href="javascript:void(0);" class="ml50 fontGrey2" onclick="add_other_answer($(this))">添加[其他]选项</a>'+
'</li>'+
'<div class="cl"></div>'+
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="grey_btn fr borderRadius" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
'<%= l(:button_cancel)%>'+
'</a>'+
'<a class="blue_btn fr borderRadius mr5" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'</div>'+
'<div class="cl"></div>'+
'</div>'+
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
}
else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");
}
}
function add_single(){
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_single') %>");
$("#poll_questions_title_new").focus();
var forms = $("form.new_poll_question");
if($("#polls_head_edit").is(":visible")){
alert("请先保存问卷标题及问卷描述。");
}else if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_single') %>");
$("#poll_questions_title_new").focus();
}
}
function insert_SINGLE(quest_type,quest_num,quest_id){
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
'<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+
'<div class="questionEditContainer">'+
'<div class="ur_editor_title">'+
'<label for="ur_question_title">问题:&nbsp;&nbsp;</label>'+
'<input type="hidden" name="quest_id" value="'+quest_id+'"/>'+
'<input type="hidden" name="quest_num" value="'+quest_num+'"/>'+
'<input type="hidden" name="question_type" value="3"/>'+
'<input maxlength="250" id="poll_questions_title" class="questionTitle w570" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入单行主观题"/>'+
'<input type="checkbox" name="is_necessary" value="true" checked/>'+
'<label for="ur_question_require">必答</label>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="grey_btn fr borderRadius" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
'<%= l(:button_cancel)%>'+
'</a>'+
'<a class="blue_btn fr borderRadius mr5" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'</div>'+
'<div class="cl"></div>'+
'</div>'+
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
var forms = $("form.new_poll_question");
if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") {
if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
'<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+
'<div class="questionEditContainer">'+
'<div class="ur_editor_title">'+
'<label for="ur_question_title">问题:&nbsp;&nbsp;</label>'+
'<input type="hidden" name="quest_id" value="'+quest_id+'"/>'+
'<input type="hidden" name="quest_num" value="'+quest_num+'"/>'+
'<input type="hidden" name="question_type" value="3"/>'+
'<input maxlength="250" id="poll_questions_title" class="questionTitle w570" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入单行主观题"/>'+
'<input type="checkbox" name="is_necessary" value="true" checked/>'+
'<label for="ur_question_require">必答</label>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="grey_btn fr borderRadius" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
'<%= l(:button_cancel)%>'+
'</a>'+
'<a class="blue_btn fr borderRadius mr5" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'</div>'+
'<div class="cl"></div>'+
'</div>'+
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
}
else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");
}
}
function add_mulit(){
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_mulit') %>");
$("#poll_questions_title_new").focus();
var forms = $("form.new_poll_question");
if($("#polls_head_edit").is(":visible")){
alert("请先保存问卷标题及问卷描述。");
}else if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#new_poll_question_new").html("<%= escape_javascript(render :partial => 'new_mulit') %>");
$("#poll_questions_title_new").focus();
}
}
function insert_MULIT(quest_type,quest_num,quest_id){
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
'<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+
'<div class="questionEditContainer">'+
'<div class="ur_editor_title">'+
'<label for="ur_question_title">问题:&nbsp;&nbsp;</label>'+
'<input type="hidden" name="quest_id" value="'+quest_id+'"/>'+
'<input type="hidden" name="quest_num" value="'+quest_num+'"/>'+
'<input type="hidden" name="question_type" value="4"/>'+
'<input maxlength="250" id="poll_questions_title" class="questionTitle w570" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入多行主观题的问题描述"/>'+
'<label><input type="checkbox" name="is_necessary" value="true" checked/>'+
'必答</label>'+
'</div>'+
'<div class="ur_editor_content">'+
'<ul>'+
'<li class="ur_item new_answer">'+
'<label class="ml50">问题<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input placeholder="请输入主观题分题的问题" class="w520" type="text" name="question_answer[0]">'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item new_answer">'+
'<label class="ml50">问题<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input placeholder="请输入主观题分题的问题" class="w520" type="text" name="question_answer[1]">'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a> </li>'+
'<div class="cl"></div>'+
'</ul>'+
'<ul>'+
'<li class="ur_item">'+
'<div class="dash-block new-subjective w520" onclick="add_multi_question($(this))">新建选项</div>'+
'</li>'+
'<div class="cl"></div>'+
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="grey_btn fr borderRadius" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
'<%= l(:button_cancel)%>'+
'</a>'+
'<a class="blue_btn fr borderRadius mr5" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'</div>'+
'<div class="cl"></div>'+
'</div>'+
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
var forms = $("form.new_poll_question");
if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") {
if(forms.length > 0){
alert("请先保存正在编辑的题目再新建。");
} else{
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(
'<%= form_for PollQuestion.new,:url =>create_poll_question_poll_path(@poll.id),:remote => true do |f|%>'+
'<div class="questionEditContainer">'+
'<div class="ur_editor_title">'+
'<label for="ur_question_title">问题:&nbsp;&nbsp;</label>'+
'<input type="hidden" name="quest_id" value="'+quest_id+'"/>'+
'<input type="hidden" name="quest_num" value="'+quest_num+'"/>'+
'<input type="hidden" name="question_type" value="4"/>'+
'<input maxlength="250" id="poll_questions_title" class="questionTitle w570" contenteditable="true" type="text" name="poll_questions_title" placeholder="请输入多行主观题的问题描述"/>'+
'<label><input type="checkbox" name="is_necessary" value="true" checked/>'+
'必答</label>'+
'</div>'+
'<div class="ur_editor_content">'+
'<ul>'+
'<li class="ur_item new_answer">'+
'<label class="ml50">问题<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input placeholder="请输入主观题分题的问题" class="w520" type="text" name="question_answer[0]">'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>'+
'</li>'+
'<div class="cl"></div>'+
'<li class="ur_item new_answer">'+
'<label class="ml50">问题<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>'+
'<input placeholder="请输入主观题分题的问题" class="w520" type="text" name="question_answer[1]">'+
'<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a> </li>'+
'<div class="cl"></div>'+
'</ul>'+
'<ul>'+
'<li class="ur_item">'+
'<div class="dash-block new-subjective w520" onclick="add_multi_question($(this))">新建选项</div>'+
'</li>'+
'<div class="cl"></div>'+
'</ul>'+
'</div>'+
'<div class="ur_editor_footer">'+
'<a class="grey_btn fr borderRadius" data-button="cancel" onclick="$(this).parent().parent().parent().remove();">'+
'<%= l(:button_cancel)%>'+
'</a>'+
'<a class="blue_btn fr borderRadius mr5" data-button="ok" id="add_new_question">'+
'<%= l(:label_button_ok)%>'+
'</a>'+
'</div>'+
'<div class="cl"></div>'+
'</div>'+
'<% end%>'
);
$("#poll_questions_title").focus();
$("#add_new_question").one('click', function(){
add_poll_question($(this));
});
}
}
else {
$("#insert_new_poll_question_"+quest_type+"_"+quest_id).html("");
}
}
//选择导入调查问卷
@ -396,37 +464,46 @@ function insert_MCQ(quest_type,quest_num,quest_id){
"</li><div class='cl'></div>");
}
}
function poll_cancel()
{
var htmlvalue = "<%= escape_javascript(render :partial => 'cancel_poll', locals: {:poll => @poll}) %>";
pop_box_new(htmlvalue,460,190);
}
function poll_save()
{
var forms = $("form.new_poll_question");
if($("#polls_head_edit").is(":visible")){
alert("请先保存问卷标题及问卷描述。");
}else if(forms.length > 0){
alert("请先保存正在编辑的题目。");
} else {
window.location.href = "<%=edit_poll_path(@poll) %>";
}
}
function poll_submit()
{
var title = $.trim($("#polls_name_h").html());
if(title.length == 0)
{
alert("问卷标题不能为空");
}
else{
var forms = $("form.new_poll_question");
if($("#polls_head_edit").is(":visible")){
alert("请先保存问卷标题及问卷描述。");
}else if(forms.length > 0){
alert("请先保存正在编辑的题目再发布。");
} else{
if($("#show_result").is(":checked")) {
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'poll_submit', locals: { :poll => @poll,:is_remote => false,:show_result=> 1}) %>');
var htmlvalue = "<%= escape_javascript(render :partial => 'poll_submit', locals: { :poll => @poll,:is_remote => false,:show_result=> 1}) %>";
} else{
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'poll_submit', locals: { :poll => @poll,:is_remote => false,:show_result=> 0}) %>');
var htmlvalue = "<%= escape_javascript(render :partial => 'poll_submit', locals: { :poll => @poll,:is_remote => false,:show_result=> 0}) %>";
}
showModal('ajax-modal', '310px');
$('#ajax-modal').css('height','120px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<span style='float: right;cursor:pointer;'>" +
"<a href='javascript:' onclick='clickCanel();'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
$('#ajax-modal').parent().removeClass("alert_praise");
$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9");
$('#ajax-modal').parent().addClass("popbox_polls");
pop_box_new(htmlvalue,460,190);
}
}
</script>
<div class="homepageRight mt0 ml10">
<div class="resources" id="polls">
<!-- 头部 -->
<div id="polls_head_show" style="display: none;">
<div id="polls_head_show" style="<%=@poll.polls_name == "" ? 'display: none;' : '' %>">
<%= render :partial => 'show_head', :locals => {:poll => @poll}%>
</div>
<div id="polls_head_edit">
<div id="polls_head_edit" style="<%=@poll.polls_name == "" ? '' : 'display: none;' %>">
<%= render :partial => 'edit_head', :locals => {:poll => @poll}%>
</div>
@ -480,8 +557,8 @@ function insert_MCQ(quest_type,quest_num,quest_id){
<label for="">允许学生查看调查结果</label>
</div>
<div>
<a href="javascript:void(0);" class="grey_btn fr borderRadius">取消</a>
<a href="javascript:void(0);" class="blue_btn fr borderRadius mr5">保存</a>
<a href="javascript:void(0);" onclick="poll_cancel();" class="grey_btn fr borderRadius">取消</a>
<a href="javascript:void(0);" onclick="poll_save();" class="blue_btn fr borderRadius mr5">保存</a>
<a href="javascript:void(0);" onclick="poll_submit();" class="blue_btn fr borderRadius mr5" >发布</a>
</div>
<div class="cl"></div>

View File

@ -1,29 +1,23 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function clickCanel(){hideModal("#popbox02");}
</script>
</head>
<body>
<div id="popbox02">
<div class="upload_con">
<div class="upload_box">
<p class="polls_box_p">问卷发布后将不能对问卷进行修改,
<div class="sy_popup_top">
<h3 class="fl">提示</h3>
<a href="javascript:void(0);" class="sy_icons_close fr" onclick="hideModal()"></a>
<div class="cl"></div>
</div>
<div>
<ul class="sy_popup_add mt10 mb10">
<li>
<p style="text-align: center">问卷发布后将不能对问卷进行修改,
<br />
是否确定发布该问卷?
</p>
<div class="polls_btn_box">
<%= link_to "确 定",publish_poll_poll_path(poll.id,:is_remote => is_remote,:show_result => show_result), :class => "upload_btn", :onclick => "clickCanel();" %>
<a class="upload_btn upload_btn_grey" onclick="clickCanel();">
取&nbsp;&nbsp;消
</a>
</div>
</li>
<li>
<label class="mr70">&nbsp;</label>
<%= link_to('确 定', publish_poll_poll_path(poll.id,:is_remote => is_remote,:show_result => show_result), :class => "sy_btn_blue fl") %>
<a href="javascript:void(0);" class="sy_btn_grey fl ml20" onclick="hideModal()">取&nbsp;&nbsp;消</a>
<div class="cl"></div>
</div>
</div>
</li>
</ul>
</div>
</body>
</html>

View File

@ -1,225 +1,278 @@
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<div class="courseRSide fl">
<div class="polls_content polls_box" id="polls">
<div class="ur_page_head" >
<div class="homepageRight mt0 ml10">
<div class="resources" id="polls">
<div class="testStatus" >
<h1 class="ur_page_title">
<%= @poll.polls_name%>
</h1>
<%= @poll.polls_description.nil? ? "" : @poll.polls_description.html_safe%>
<div class="testDesEdit mt5"><%= @poll.polls_description.nil? ? "" : @poll.polls_description.html_safe%></div>
</div>
<div class="ur_card">
<ol class="ur_questions">
<% @poll_questions.each do |pq| %>
<% if pq.question_type == 1 %>
<!-- 单选题 -->
<li class="ur_question_item radio">
<div class="ur_title">
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<span class="title_index">[单选题]</span>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<form>
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label >
<script>
function click_<%= pa.id %>(obj)
{
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_answer_id: <%= pa.id %>,
poll_question_id: <%= pq.id %>
},
success: function (data) {
var dataObj = eval(data);
obj.checked = true;
var span = $('#percent');
span.html(dataObj.percent);
}
});
}
</script>
<%= radio_button "poll_vote","poll_answer_id",pa.id,:class=>"ur_radio",:onclick =>"click_#{pa.id}(this);return false;",:checked => answer_be_selected?(pa,User.current),:disabled => !@can_edit_poll %>
<%= pa.answer_text %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</form>
</div>
</li>
<% elsif pq.question_type == 2 %>
<!-- 多选题 -->
<li class="ur_question_item checkbox">
<div class="ur_title">
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<span class="title_index">[多选题]</span>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<form>
<table class="ur_table" >
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label >
<script>
function click_<%= pa.id %>(obj)
{
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_answer_id: <%= pa.id %>,
poll_question_id: <%= pq.id %>
},
success: function (data) {
var dataObj = eval(data);
if(dataObj.text == "true")
{
obj.checked = true;
}
else
{
obj.checked = false;
}
var span = $('#percent');
span.html(dataObj.percent);
}
});
}
</script>
<input class="ur_checkbox" type="checkbox" onclick="click_<%= pa.id %>(this);return false;" <%= answer_be_selected?(pa,User.current) ? "checked":"" %> <%= @can_edit_poll?"":"disabled=disabled" %> >
<%= pa.answer_text %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</form>
</div>
</li>
<% elsif pq.question_type == 3 %>
<!-- 单行文字-->
<li class="ur_question_item text">
<div class="ur_title">
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<span class="title_index">[单行主观]</span>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<script>
function onblur_<%= pq.id %>(obj)
{
$(window).unbind('beforeunload');
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_question_id: <%= pq.id %> ,
vote_text: obj.value
},
success: function (data) {
var dataObj = eval(data);
var span = $('#percent');
span.html(dataObj.percent);
// obj.value = data;
}
});
<% mc_question_list = @poll.poll_questions.where("question_type=1") %>
<% mcq_question_list = @poll.poll_questions.where("question_type=2") %>
<% single_question_list = @poll.poll_questions.where("question_type=3") %>
<% multi_question_list = @poll.poll_questions.where("question_type=4") %>
<div class="testStatus" id="mc_question_list" style="display: <%=mc_question_list.count > 0 ? "" : "none" %>">
<h3 class="fontGrey3">单选题</h3>
<% mc_question_list.each_with_index do |pq, list_index| %>
<div id="poll_questions_<%= pq.id%>">
<div id="show_poll_questions_<%= pq.id %>">
<div>
<div class="testEditTitle"><%= l(:label_question_number,:question_number => pq.question_number) %><%= pq.question_title %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<table class="ur_table" style="width:675px;">
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label>
<script>
function onblur_<%= pa.id %>(obj)
{
$(window).unbind('beforeunload');
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_question_id: <%= pq.id %>,
poll_answer_id: <%= pa.id %>,
vote_text: obj.value
},
success: function (data) {
var dataObj = eval(data);
document.getElementById("poll_vote_<%=pq.id %>poll_answer_id_<%=pa.id %>").checked = true;
var span = $('#percent');
span.html(dataObj.percent);
}
});
}
</script>
<input class="ur_text ur_textbox" type="text" size="" maxlength="" style="width: 100%" value="<%= get_anwser_vote_text(pq.id,User.current.id).html_safe %>" onblur="onblur_<%= pq.id %>(this);" <%= @can_edit_poll?"":"disabled=disabled" %>>
</div>
</li><!--单行输入 end-->
<% elsif pq.question_type == 4 %>
<!-- 多行文字-->
<li class="ur_question_item textarea">
<div class="ur_preview">
<div class="ur_title">
<span class="title_index"><%= l(:label_question_number,:question_number => pq.question_number) %></span>
<%= pq.question_title %>
<span class="title_index">[多行主观]</span>
<% if pq.is_necessary == 1 %>
<span class="ur_required" title="<%= l(:label_must_answer) %>">*</span>
<% end %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
}
function click_<%= pa.id %>(obj)
{
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_answer_id: <%= pa.id %>,
poll_question_id: <%= pq.id %>
},
success: function (data) {
var dataObj = eval(data);
if(dataObj.text == "ok")
{
obj.checked = true;
}
else
{
obj.checked = false;
}
var span = $('#percent');
span.html(dataObj.percent);
},
error: function () {
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
}
});
}
</script>
<%= radio_button "poll_vote",pq.id.to_s+"poll_answer_id",pa.id,:class=>"ur_radio",:onclick =>"click_#{pa.id}(this);return false;",:checked => answer_be_selected?(pa,User.current),:disabled => !@can_edit_poll %>
<% if pa.answer_text == "" %>
<input class="ur_text ur_textbox" type="text" size="" maxlength="" style="width: 93%" value="<%= get_anwser_vote_text(pq.id,User.current.id).html_safe %>" onblur="onblur_<%= pa.id %>(this);" <%= @can_edit_poll?"":"disabled=disabled" %> placeholder="其他">
<% else %>
<%= pa.answer_text %>
<% end %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
<% end %>
</div>
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
<h3 class="fontGrey3">多选题</h3>
<% mcq_question_list.each do |pq| %>
<div id="poll_questions_<%= pq.id%>">
<div id="show_poll_questions_<%= pq.id %>">
<div>
<div class="testEditTitle"><%= l(:label_question_number,:question_number => pq.question_number) %><%= pq.question_title %>
</div>
<div class="cl"></div>
<div class="ur_inputs">
<table class="ur_table" style="width:675px;">
<tbody>
<% pq.poll_answers.each do |pa| %>
<tr>
<td>
<label>
<script>
function onblur_<%= pa.id %>(obj)
{
$(window).unbind('beforeunload');
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_question_id: <%= pq.id %>,
poll_answer_id: <%= pa.id %>,
vote_text: obj.value
},
success: function (data) {
var dataObj = eval(data);
document.getElementById("poll_vote_<%=pq.id %>poll_answer_id_<%=pa.id %>").checked = true;
var span = $('#percent');
span.html(dataObj.percent);
}
});
}
function click_<%= pa.id %>(obj)
{
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_answer_id: <%= pa.id %>,
poll_question_id: <%= pq.id %>
},
success: function (data) {
var dataObj = eval(data);
if(dataObj.text == "ok")
{
obj.checked = true;
}
else
{
obj.checked = false;
}
var span = $('#percent');
span.html(dataObj.percent);
},
error: function () {
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
}
});
}
</script>
<input class="ur_radio" id="poll_vote_<%=pq.id %>poll_answer_id_<%=pa.id %>" type="checkbox" onclick="click_<%= pa.id %>(this);return false;" <%= answer_be_selected?(pa,User.current) ? "checked":"" %> <%= @can_edit_poll?"":"disabled=disabled" %> >
<% if pa.answer_text == "" %>
<input class="ur_text ur_textbox" type="text" size="" maxlength="" style="width: 93%" value="<%= get_anwser_vote_text(pq.id,User.current.id).html_safe %>" onblur="onblur_<%= pa.id %>(this);" <%= @can_edit_poll?"":"disabled=disabled" %> placeholder="其他">
<% else %>
<%= pa.answer_text %>
<% end %>
</label>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div><!--多选题显示 end-->
</div>
</div>
<% end %>
</div>
<div class="testStatus" id="single_question_list" style="display: <%=single_question_list.count > 0 ? "" : "none" %>">
<h3 class="fontGrey3">单行主观题</h3>
<% single_question_list.each do |pq| %>
<div id="poll_questions_<%= pq.id%>">
<div id="show_poll_questions_<%= pq.id %>">
<div>
<div class="testEditTitle"><%= l(:label_question_number,:question_number => pq.question_number) %><%= pq.question_title %>
</div>
<div class="cl"></div>
<div>
<script>
function onblur_<%= pq.id %>(obj)
{
$(window).unbind('beforeunload');
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_question_id: <%= pq.id %> ,
vote_text: obj.value
},
success: function (data) {
var dataObj = eval(data);
obj.value = dataObj.text;
var span = $('#percent');
span.html(dataObj.percent);
},
error: function () {
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
}
});
}
</script>
<input class="fillInput" placeholder="在此填入答案" type="text" value="<%= get_anwser_vote_text(pq.id,User.current.id).html_safe %>" onblur="onblur_<%= pq.id %>(this);" <%= @can_edit_poll?"":"disabled=disabled" %>>
</div>
</div>
</div>
</div>
<% end %>
</div>
<div class="testStatus" id="single_question_list" style="display: <%=single_question_list.count > 0 ? "" : "none" %>">
<h3 class="fontGrey3">多行主观题</h3>
<% multi_question_list.each do |pq| %>
<div id="poll_questions_<%= pq.id%>">
<div id="show_poll_questions_<%= pq.id %>">
<div>
<div class="testEditTitle"><%= l(:label_question_number,:question_number => pq.question_number) %><%= pq.question_title %>
</div>
<div class="cl"></div>
<% pq.poll_answers.each_with_index do |pa, i| %>
<div class="ml40 mb10">
<script>
function onblur_<%= pq.id %>(obj)
function onblur_<%= pa.id %>(obj)
{
$(window).unbind('beforeunload');
$.ajax({
type: "post",
url: "<%= commit_answer_poll_path(@poll) %>",
data: {
poll_question_id: <%= pq.id %> ,
vote_text: obj.innerHTML
poll_answer_id: <%= pa.id %>,
vote_text: obj.value
},
success: function (data) {
var dataObj = eval(data);
if(dataObj.text != 'failure')
{
var span = $('#percent');
span.html(dataObj.percent);
}
else
{
alert("error");
}
obj.value = dataObj.text;
var span = $('#percent');
span.html(dataObj.percent);
},
error: function () {
alert("网络异常,答题失败,请确认网络正常连接后再答题。");
}
});
}
</script>
<div contenteditable='<%= @can_edit_poll %>' class="ur_textbox" style="min-height: 150px;width: 100%;<%= @can_edit_poll?"":"background-color:#DCDCDC;" %>" onblur="onblur_<%= pq.id %>(this);"><%= get_anwser_vote_text(pq.id,User.current.id).html_safe %></div>
<p class="mb10"><%= i + 1 %>.<%= pa.answer_text%></p>
<input class="questionnaire-input" placeholder="在此填入答案" style="width: 93%" type="text" value="<%= get_anwser_vote_text(pq.id,User.current.id,pa.id).html_safe %>" onblur="onblur_<%= pa.id %>(this);" <%= @can_edit_poll?"":"disabled=disabled" %>>
</div>
</div>
</li><!--多行输入 end-->
<% else %>
<!-- 未知题型 -->
<% end %>
<% end %>
</ol>
<ul class="wlist">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
</ul>
<div class="cl"></div>
<div class="ur_buttons" style="width: 100px;">
<% if @poll.polls_status == 2 %>
<%= 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">
<%= l(:label_complete_question) %>
<strong class="ur_progress_number">
<span id="percent"><%= format "%.2f" ,@percent %></span>%
</strong>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
<div class="ur_buttons" style="width: 77px;">
<% if @poll.polls_status == 2 %>
<%= link_to l(:button_submit),commit_poll_poll_path(@poll), :method => :post,:class => "BlueCirBtn",:format => 'js',:remote=>true %>
<% end %>
</div>
<div class="cl"></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><!--问卷内容end-->
</div>

View File

@ -22,8 +22,10 @@
</div>
<% if poll_question.question_type == 1 || poll_question.question_type == 2 %>
<%= render :partial =>'choice_show', :locals =>{ :poll_question => poll_question } %>
<% else %>
<% elsif poll_question.question_type == 3 %>
<%= render :partial =>'quiz_answers', :locals =>{ :poll_question => poll_question } %>
<% else %>
<%= render :partial =>'multi_answers', :locals =>{ :poll_question => poll_question } %>
<% end %>
</li>
</ol>

View File

@ -1,7 +1,7 @@
@charset "utf-8";
/* CSS Document */
.ui-widget {
font-family: Verdana, sans-serif;
font-family: "微软雅黑","宋体",Verdana, sans-serif;
font-size: 1.1em;
}
.ui-widget-content {