socialforge/app/views/exercise/_exercise_form.html.erb

300 lines
13 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%= stylesheet_link_tag 'polls', :media => 'all' %>
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#homework_page_right").css("min-height",$("#courseLSide").height()-33);
$("#Container").css("width","1000px");
});
//编辑问卷描述之后
var popWindow ; //弹出框的引用
var importPollPopWindow; //选择导入的弹出框引用
function edit_head(){
$("#exercise_description").val($("#exercise_description_div").html());
}
$(function(){
//点击空白处
$(document).bind('click',function(e){
//弹出框非空 不是a标签 点击的不是弹出框 ,那么弹出框就会隐藏
if(popWindow && e.target.nodeName != 'A' && !popWindow.is(e.target) && popWindow.has(e.target).length === 0){ // Mark 1
popWindow.css('display', 'none');
}
if(importPollPopWindow && e.target.nodeName != 'A' && !importPollPopWindow.is(e.target) && importPollPopWindow.has(e.target).length === 0){
importPollPopWindow.css('display', 'none');
}
});
})
function dismiss(quest_type,quest_id){
popWindow = $("#div_"+quest_type+"_"+quest_id);
if(popWindow){
popWindow.css('display', 'none');
}
}
function chooseQuestionType(quest_type,quest_id){
//quest_type 分为 mc mcq single multi
//quest_id 是quetion的id 下同
if(popWindow){
popWindow.css('display', 'none');
}
popWindow = $("#div_"+quest_type+"_"+quest_id);
$("#div_"+quest_type+"_"+quest_id).click(function(e){
e.stopPropagation(); //组织冒泡到document.body中去
});
$("#div_"+quest_type+"_"+quest_id).css("position", "absolute");
$("#div_"+quest_type+"_"+quest_id).css("top", $("#add_"+quest_type+"_"+quest_id).offset().top+30);
$("#div_"+quest_type+"_"+quest_id).css("left", $("#add_"+quest_type+"_"+quest_id).offset().left-10);
if( $("#div_"+quest_type+"_"+quest_id).css('display') == 'block') {
$("#div_"+quest_type+"_"+quest_id).css('display', 'none');
}
else{
$("#div_"+quest_type+"_"+quest_id).css('display', 'block');
}
}
//选择导入调查问卷
function importPoll(){
importPollPopWindow = $("#import_poll");
$("#import_poll").css("position", "absolute");
$("#import_poll").css("top", $("#import_btn").offset().top+30);
$("#import_poll").css("left", $("#import_btn").offset().left-65);
$("#import_poll").css("display","block")
}
function remote_import(){
importPollPopWindow.css('display', 'none');
if($("#import_poll").val() === 0){
return;
}else{
if(confirm("确认导入问卷"+$("#import_poll").find("option:selected").text()+"?")){
$("#import_form").submit();
}else{
return;
}
}
}
//添加标题时确定按钮
function add_poll_question(doc,quest_type)
{
var title = $.trim($("#poll_questions_title").val());
var score = $.trim($("#question_score").val());
var standard_ans = $.trim($("#exercise_choice_" + quest_type).val());
if(title.length == 0 || score.length == 0){
notice_box("题目标题/分数不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else if(!/^[1-9][0-9]*$/.test(score)) {
notice_box("分数必须是非零开头的数字");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else if(quest_type !=3 && quest_type !=4 && standard_ans.length == 0) {
notice_box("标准答案不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
}else{
doc.parent().parent().parent().submit();}
}
//修改标题时确定按钮
function edit_poll_question(doc,id,quest_type)
{
var title = $.trim($("#poll_questions_title_" + id).val());
var score = $.trim($("#poll_question_score_"+ id).val());
var standard_ans = $.trim($("#exercise_choice_" + id).val());
if(title.length == 0 || score.length == 0){
notice_box("题目标题/分数不能为空");
}else if(!/^[1-9][0-9]*$/.test(score)) {
notice_box("分数必须是非零开头的数字");
}else if(quest_type !=3 && quest_type !=4 && standard_ans.length == 0) {
notice_box("标准答案不能为空");
}else if(quest_type ==3) {
var div = $("#poll_answers_" + id);
var candiate_answer = $(".candiate_answer",div);
if(candiate_answer.length > 0) {
for(i=0;i<candiate_answer.length;i++) {
if(i<candiate_answer.length-1 && $.trim($(candiate_answer[i]).val()) == "") {
continue;
} else if(i == (candiate_answer.length-1) && $.trim($(candiate_answer[i]).val()) == "") {
notice_box("参考答案不能为空");
} else if($.trim($(candiate_answer[i]).val()) != ""){
doc.parent().parent().parent().submit();
break;
}
}
} else{
notice_box("参考答案不能为空");
}
}else{
doc.parent().parent().parent().submit();}
}
//问卷头
function pollsCancel(){$("#polls_head_edit").hide();$("#polls_head_show").show();}
function pollsSubmit(doc){
var title = $.trim($("#exercise_name").val());
if(title.length == 0){
notice_box("测验标题不能为空");
} else if($.trim($("#exercise_end_time").val()) =="") {
notice_box("截止时间不能为空");
} else if((Date.parse($("#exercise_end_time").val())+(24*60*60-1)*1000) <= Date.now()) {
notice_box("截止时间不能早于当前时间");
} else if($.trim($("#exercise_time").val()) !="" && !/^[1-9][0-9]*$/.test($.trim($("#exercise_time").val()))) {
notice_box("测验时长必须为非零开头的数字");
} else if($.trim($("#exercise_publish_time").val()) !="" && ((Date.parse($("#exercise_publish_time").val())+(24*60*60-1)*1000) < Date.now())) {
notice_box("发布时间不能小于当前时间");
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_end_time").val()) < Date.parse($("#exercise_publish_time").val())) {
notice_box("截止时间不能小于发布时间");
} else {
doc.parent().parent().parent().submit();
}
}
function pollsEdit(){$("#polls_head_edit").show();$("#polls_head_show").hide();}
//
function pollQuestionCancel(question_id){
$("#show_poll_questions_"+question_id).show();
$("#edit_poll_questions_"+question_id).hide();
}
function pollQuestionEdit(question_id){
$("#show_poll_questions_"+question_id).hide();
$("#edit_poll_questions_"+question_id).show();
$("#poll_questions_title_"+question_id).focus();
}
// 选项的选择
function toggle_select(doc, type, id){
if(doc.hasClass("question_choice_blue")){
doc.removeClass("question_choice_blue").addClass("question_choice_white");
if(type == "1"){
$("#question_standard_answer_" + id).html("请点击选项");
$("#exercise_choice_" + id).val("");
}else{
var eles = doc.parent().parent().find("a.question_choice_blue");
var str = "";
if(eles.length > 0){
for(var i=0; i<eles.length; i++){
str += $(eles[i]).html();
}
$("#question_standard_answer_" + id).html(str);
$("#exercise_choice_" + id).val(str);
} else{
$("#question_standard_answer_" + id).html("请点击选项");
$("#exercise_choice_" + id).val("");
}
}
}else{
if(type == "1"){
doc.parent().parent().find("a.question_choice_blue").removeClass("question_choice_blue").addClass("question_choice_white");
doc.removeClass("question_choice_white").addClass("question_choice_blue");
$("#question_standard_answer_" + id).html(doc.html());
$("#exercise_choice_" + id).val(doc.html());
} else{
doc.removeClass("question_choice_white").addClass("question_choice_blue");
var eles = doc.parent().parent().find("a.question_choice_blue");
var str = "";
for(var i=0; i<eles.length; i++){
str += $(eles[i]).html();
}
$("#question_standard_answer_" + id).html(str);
$("#exercise_choice_" + id).val(str);
}
}
}
//单选题
function add_single_answer(doc, type)
{
var li = doc.parent().before("<li class='ur_item new_answer'><a class='question_choice_white fl mr10 choice_btn' title='设为答案' href='javascript:void(0)' onclick='toggle_select($(this), "+ type +", "+ type +");'></a><input maxlength='200' class='w600' type='text' name='question_answer["+new Date().getTime()+"]' placeholder='输入选项内容'/>" +
"<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>"+
"</li><div class='cl'></div>");
var select_items =$("li.new_answer",li.parent());
li.prev().prev().find("a.question_choice_white").html(String.fromCharCode(64 + select_items.length));
doc.prev("a.question_choice_dash").html(String.fromCharCode(64 + select_items.length + 1));
}
function add_candidate_answer(doc)
{
var select_items =$("li.new_answer",doc.parent().parent());
var li = doc.parent().before("<li class='ur_item new_answer'><label name='candiate_items'>参考答案"+ revert_to_chinese_num(select_items.length + 1) +"<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;</label><input maxlength='200' class='candiate_answer w560' type='text' name='exercise_choice["+new Date().getTime()+"]' placeholder='请输入参考答案(选填)'/>" +
"<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>"+
"</li><div class='cl'></div>");
}
function revert_to_chinese_num(num){
var s_num = "";
switch (num) {
case 1: s_num = '一'; break;
case 2: s_num = '二'; break;
case 3: s_num = '三'; break;
case 4: s_num = '四'; break;
case 5: s_num = '五'; break;
case 6: s_num = '六'; break;
case 7: s_num = '七'; break;
case 8: s_num = '八'; break;
case 9: s_num = '九'; break;
}
return s_num;
}
function remove_single_answer(doc)
{
if(doc.parent().siblings("li").length == 0)
{
notice_box("至少有一个选项或一个参考答案");
}
else
{
var parent = doc.parent().parent();
doc.parent().remove();
var select_items =$("li.ur_item",parent);
var candiate_items =$("label[name='candiate_items']",parent);
for(var i=0; i<select_items.length; i++){
$(select_items[i]).find("a.choice_btn").html(String.fromCharCode(64 + parseInt(i+1)));
}
for(var i=0; i<candiate_items.length; i++){
$(candiate_items[i]).html("参考答案"+revert_to_chinese_num(i + 1)+"<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;");
}
}
}
</script>
<div class="homepageRight mt0 ml10">
<div class="resources">
<!-- 头部 -->
<div id="polls_head_show" style="display: none;">
<%= render :partial => 'show_head', :locals => {:exercise => @exercise} %>
</div>
<div id="polls_head_edit">
<%= render :partial => 'edit_head', :locals => {:exercise => @exercise} %>
</div>
<!-- 问题 -->
<div id="poll_content">
<%= render :partial => 'exercise_content', :locals => {:exercise => @exercise} %>
</div>
<div class="testQuestion" id="new_exercise_question">
<%= render :partial => 'new_question', :locals => {:exercise => @exercise} %>
</div>
<!--选项 end-->
<!-- 新增问题 -->
<div id="new_poll_question">
</div>
<% current_score = get_current_score @exercise %>
<div id="total_questions_score" style="display: <%= @exercise.exercise_questions.count != 0 ? '' : 'none' %>">
<%= render :partial => 'exercise/total_questions_score', :locals => {:exercise => @exercise, :current_score => current_score} %>
</div>
<div id="exercise_submit">
<%= render :partial => 'exercise_submit', :locals => {:exercise => @exercise} %>
</div>
<div class="cl"></div>
<!--contentbox end-->
</div>
</div><!--编辑end-->