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

300 lines
13 KiB
Plaintext
Raw Permalink Normal View History

2015-11-26 10:56:24 +08:00
<%= stylesheet_link_tag 'polls', :media => 'all' %>
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
2016-07-22 15:32:37 +08:00
$("#homework_page_right").css("min-height",$("#courseLSide").height()-33);
2015-11-26 10:56:24 +08:00
$("#Container").css("width","1000px");
});
//编辑问卷描述之后
var popWindow ; //弹出框的引用
var importPollPopWindow; //选择导入的弹出框引用
function edit_head(){
2015-11-27 15:19:13 +08:00
$("#exercise_description").val($("#exercise_description_div").html());
2015-11-26 10:56:24 +08:00
}
$(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());
2017-02-17 09:03:43 +08:00
var standard_ans = $.trim($("#exercise_choice_" + quest_type).val());
2015-11-26 10:56:24 +08:00
if(title.length == 0 || score.length == 0){
2017-02-17 09:03:43 +08:00
notice_box("题目标题/分数不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
2015-11-26 10:56:24 +08:00
}else if(!/^[1-9][0-9]*$/.test(score)) {
2017-02-17 09:03:43 +08:00
notice_box("分数必须是非零开头的数字");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
2017-02-17 09:03:43 +08:00
}else if(quest_type !=3 && quest_type !=4 && standard_ans.length == 0) {
notice_box("标准答案不能为空");
doc.one('click', function(){
add_poll_question($(this),quest_type);
});
2015-11-26 10:56:24 +08:00
}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());
2017-02-17 09:03:43 +08:00
var standard_ans = $.trim($("#exercise_choice_" + id).val());
2015-11-26 10:56:24 +08:00
if(title.length == 0 || score.length == 0){
2017-02-17 09:03:43 +08:00
notice_box("题目标题/分数不能为空");
2015-11-26 10:56:24 +08:00
}else if(!/^[1-9][0-9]*$/.test(score)) {
2017-02-17 09:03:43 +08:00
notice_box("分数必须是非零开头的数字");
}else if(quest_type !=3 && quest_type !=4 && standard_ans.length == 0) {
notice_box("标准答案不能为空");
2015-11-26 10:56:24 +08:00
}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()) == "") {
2017-02-17 09:03:43 +08:00
notice_box("参考答案不能为空");
2015-11-26 10:56:24 +08:00
} else if($.trim($(candiate_answer[i]).val()) != ""){
doc.parent().parent().parent().submit();
break;
}
}
} else{
2017-02-17 09:03:43 +08:00
notice_box("参考答案不能为空");
2015-11-26 10:56:24 +08:00
}
}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){
2017-02-17 09:03:43 +08:00
notice_box("测验标题不能为空");
2015-11-26 10:56:24 +08:00
} else if($.trim($("#exercise_end_time").val()) =="") {
2017-02-17 09:03:43 +08:00
notice_box("截止时间不能为空");
2016-07-05 10:06:46 +08:00
} else if((Date.parse($("#exercise_end_time").val())+(24*60*60-1)*1000) <= Date.now()) {
2017-02-17 09:03:43 +08:00
notice_box("截止时间不能早于当前时间");
2015-11-26 10:56:24 +08:00
} else if($.trim($("#exercise_time").val()) !="" && !/^[1-9][0-9]*$/.test($.trim($("#exercise_time").val()))) {
2017-02-17 09:03:43 +08:00
notice_box("测验时长必须为非零开头的数字");
2016-07-05 10:06:46 +08:00
} else if($.trim($("#exercise_publish_time").val()) !="" && ((Date.parse($("#exercise_publish_time").val())+(24*60*60-1)*1000) < Date.now())) {
2017-02-17 09:03:43 +08:00
notice_box("发布时间不能小于当前时间");
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_end_time").val()) < Date.parse($("#exercise_publish_time").val())) {
2017-02-17 09:03:43 +08:00
notice_box("截止时间不能小于发布时间");
2015-11-26 10:56:24 +08:00
} 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();
}
// 选项的选择
2017-02-17 09:03:43 +08:00
function toggle_select(doc, type, id){
if(doc.hasClass("question_choice_blue")){
doc.removeClass("question_choice_blue").addClass("question_choice_white");
if(type == "1"){
2017-02-17 09:03:43 +08:00
$("#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();
}
2017-02-17 09:03:43 +08:00
$("#question_standard_answer_" + id).html(str);
$("#exercise_choice_" + id).val(str);
} else{
2017-02-17 09:03:43 +08:00
$("#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");
2017-02-17 09:03:43 +08:00
$("#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();
}
2017-02-17 09:03:43 +08:00
$("#question_standard_answer_" + id).html(str);
$("#exercise_choice_" + id).val(str);
}
}
}
2015-11-26 10:56:24 +08:00
//单选题
function add_single_answer(doc, type)
2015-11-26 10:56:24 +08:00
{
2017-02-17 09:03:43 +08:00
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>"+
2015-11-26 10:56:24 +08:00
"</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));
2015-11-26 10:56:24 +08:00
}
function add_candidate_answer(doc)
{
2017-02-17 09:03:43 +08:00
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>"+
2015-11-26 10:56:24 +08:00
"</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;
2015-11-26 10:56:24 +08:00
}
function remove_single_answer(doc)
{
if(doc.parent().siblings("li").length == 0)
{
2017-02-17 09:03:43 +08:00
notice_box("至少有一个选项或一个参考答案");
2015-11-26 10:56:24 +08:00
}
else
{
var parent = doc.parent().parent();
2015-11-26 10:56:24 +08:00
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++){
2017-02-17 09:03:43 +08:00
$(candiate_items[i]).html("参考答案"+revert_to_chinese_num(i + 1)+"<span class='ur_index'></span>&nbsp;&nbsp;&nbsp;");
}
2015-11-26 10:56:24 +08:00
}
}
</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>
2017-02-17 09:03:43 +08:00
2015-11-26 10:56:24 +08:00
<!-- 问题 -->
<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>
2017-02-17 09:03:43 +08:00
<% current_score = get_current_score @exercise %>
2017-03-03 14:43:51 +08:00
<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} %>
2017-02-17 09:03:43 +08:00
</div>
2015-11-26 10:56:24 +08:00
<div id="exercise_submit">
<%= render :partial => 'exercise_submit', :locals => {:exercise => @exercise} %>
</div>
<div class="cl"></div>
<!--contentbox end-->
</div>
</div><!--编辑end-->