352 lines
16 KiB
JavaScript
352 lines
16 KiB
JavaScript
$(function(){
|
||
var bt=baidu.template;
|
||
bt.LEFT_DELIMITER='<!';
|
||
bt.RIGHT_DELIMITER='!>';
|
||
|
||
var tested = false;
|
||
var valid_form = function() {
|
||
var src = $('#program-src').val();
|
||
|
||
if (!src) {
|
||
long_notice_box("请输入正确的代码!");
|
||
return false;
|
||
}
|
||
// if ($("textarea[name='late_reason']").length > 0 && $("textarea[name='late_reason']").val().trim() == "") {
|
||
// var htmlvalue = "</br><div style='width:550px;text-align:center'>请输入标题!</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
|
||
// long_notice_box("迟交原因不能为空");
|
||
// return false;
|
||
// }
|
||
return true;
|
||
};
|
||
|
||
var test_program = function(cb){
|
||
$('#test-program-btn').hide();
|
||
$('#commit-program-work-btn').hide();
|
||
var homework_id = $('#test-program-btn').attr('data-homework-id');
|
||
var student_work_id = $('#test-program-btn').attr('data-student-work-id');
|
||
var src = $('#program-src').val();
|
||
var is_test = $('input[name=is_test]').val();
|
||
|
||
if(!valid_form()){
|
||
$('#test-program-btn').show();
|
||
$('#commit-program-work-btn').show();
|
||
return;
|
||
}
|
||
//先测试一次并返回测试集个数及结果再判断是否需要继续进行测试
|
||
var test_post = function(i, testid){
|
||
$.post(
|
||
'/student_work/program_test_ex',
|
||
{homework: homework_id, student_work_id: student_work_id,
|
||
src: src, is_test: is_test,tIndex:i,
|
||
testid: testid},
|
||
function(data,status){
|
||
if (data.status==-4 || data.status==-5 ){
|
||
//弹框
|
||
var root_path = getRootPath();
|
||
var forums_1_path = root_path + "/forums/1";
|
||
long_notice_box("由于目前大量用户正在测试,系统繁忙,请稍后再试。<br/>我们将尽快提升平台的处理能力,谢谢您的支持!");
|
||
|
||
$('#test-program-btn').show();
|
||
$('#commit-program-work-btn').show();
|
||
return;
|
||
}
|
||
else if (data.status==-3){
|
||
long_notice_box("由于目前大量用户正在测试,系统繁忙,请稍后再试。<br/>我们将尽快提升平台的处理能力,谢谢您的支持!");
|
||
|
||
$('#test-program-btn').show();
|
||
$('#commit-program-work-btn').show();
|
||
return;
|
||
}
|
||
var tSeq = data.tseq;
|
||
var tCount = data.tcount;
|
||
console.log("tSeq="+tSeq);
|
||
console.log("tCount="+tCount);
|
||
tested = true;
|
||
console.log(data);
|
||
if(data.index <=0){
|
||
data.index = $('.ProResultList').length+1;
|
||
}
|
||
|
||
var html=bt('t:result-list',data);
|
||
$("#new_student_work_tests").show();
|
||
if(i==1){
|
||
$('.edu-tab-con-box').prepend('<div class="mb10 ProResultList"><span class="font-bd mb5">第'+($('.ProResultList').length+1)+'次</span><div class="edu-ces-box"></div></div>');
|
||
}
|
||
$('.ProResultList:first-child').find(".edu-ces-box").prepend(html);
|
||
|
||
if (data.status==0 && is_test != 'true') {
|
||
if (typeof cb == 'function') {cb(data);return;}
|
||
$('#test-program-btn').show();
|
||
$('#commit-program-work-btn').show();
|
||
return;
|
||
}
|
||
|
||
//2 超时 -2 编译错误 测试结束
|
||
if (data.status == 2 || data.status == -2 || tSeq >= tCount ){
|
||
if (typeof cb == 'function') {cb(data);$('#test-program-btn').show();$('#commit-program-work-btn').show(); return;}
|
||
$('#test-program-btn').show();
|
||
$('#commit-program-work-btn').show();
|
||
return;
|
||
}
|
||
|
||
test_post(i+1, data.testid);
|
||
}
|
||
).fail(function(xhr, status){
|
||
if(status == 'timeout'){
|
||
long_notice_box("您的答案超时了, 请检查代码是否存在死循环的错误!");
|
||
} else {
|
||
long_notice_box("由于目前大量用户正在测试,系统繁忙,请稍后再试。<br/>我们将尽快提升平台的处理能力,谢谢您的支持!");
|
||
}
|
||
$('#test-program-btn').show();
|
||
$('#commit-program-work-btn').show();
|
||
return;
|
||
});
|
||
};
|
||
|
||
test_post(1, 0);
|
||
};
|
||
|
||
$('#test-program-btn').on('click', test_program);
|
||
|
||
|
||
$('#commit-program-work-btn').on('click', function(){
|
||
if(!valid_form()){
|
||
return;
|
||
} else{
|
||
if ($("textarea[name='late_reason']").length > 0 && $("textarea[name='late_reason']").val().trim() == "") {
|
||
var htmlvalue = "</br><div style='width:550px;text-align:center'>请输入标题!</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
|
||
long_notice_box("迟交原因不能为空");
|
||
return false;
|
||
}
|
||
}
|
||
$('#commit-program-work-btn').hide();
|
||
if($('.edu-tab-con-box .ProResultList').length<=0){
|
||
var htmlvalue = '<div class="task-popup" style="width:575px;"><div class="task-popup-title clearfix"><h3 class="fl color-grey">提示</h3><a href="javascript:void(0);" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a></div>'+
|
||
'<div class="task-popup-content"><p class="task-popup-text-center font-16">测试后才能提交,是否立刻测试?</p></div><div class="task-popup-submit clearfix"><a href="javascript:void(0);" onclick="hideModal();" class="task-btn fl">取消</a>'+
|
||
'<a href="javascript:void(0);" class="task-btn task-btn-orange fr" id="code-test-button">确定</a></div></div>';
|
||
pop_box_new(htmlvalue,575,140);
|
||
$("#code-test-button").on('click',function(){
|
||
test_program();
|
||
hideModal();
|
||
});
|
||
return;
|
||
}
|
||
console.log(tested);
|
||
if (!tested) {
|
||
test_program(function(data){
|
||
if (data.status!=0) {
|
||
tested = false;
|
||
console.log(tested);
|
||
var htmlvalue = '<div class="task-popup" style="width:575px;"><div class="task-popup-title clearfix"><h3 class="fl color-grey">提示</h3><a href="javascript:void(0);" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a></div>'+
|
||
'<div class="task-popup-content"><p class="task-popup-text-center font-16">测试不通过,是否强制提交?</p></div><div class="task-popup-submit clearfix"><a href="javascript:void(0);" onclick="hideModal();" class="task-btn fl">取消</a>'+
|
||
'<a href="javascript:void(0);" class="task-btn task-btn-orange fr" onclick="submit_code();">确定</a></div></div><script>function submit_code(){$("#commit-program-work-btn").hide();$("#student_work_form").submit();hideModal();}</script>';
|
||
pop_box_new(htmlvalue,575,140);
|
||
$('#commit-program-work-btn').show();
|
||
return;
|
||
|
||
};
|
||
$('#commit-program-work-btn').hide();
|
||
$('#test-program-btn').hide();
|
||
$("#student_work_form").submit();
|
||
});
|
||
return;
|
||
}
|
||
$('#commit-program-work-btn').hide();
|
||
$('#test-program-btn').hide();
|
||
$("#student_work_form").submit();
|
||
});
|
||
|
||
//代码编辑器
|
||
if (typeof CodeMirror != "undefined") {
|
||
var program_name = "text/x-csrc";
|
||
var language = $('#data-language').attr('data-language');
|
||
if (language == 1) {
|
||
program_name = 'text/x-csrc';
|
||
} else if(language==2){
|
||
program_name = 'text/x-c++src';
|
||
}else if(language==3){
|
||
program_name = 'text/x-cython';
|
||
} else if(language==4){
|
||
program_name = 'text/x-java';
|
||
}
|
||
|
||
if ($('#program-src').val().length<=0) {
|
||
var src = '';
|
||
if(language==4){
|
||
src = '\
|
||
//注意\n\
|
||
//1:该程序每次运行的时间必须小于200毫秒,否则会超时,程序超时将不会测试剩余的测试集\n\
|
||
//2:该程序每次运行使用的内存不能超过1M,否则会返回错误\n\
|
||
//3:该程序每次运行输出的结果最多显示1000个字符(多余的不显示),每行末尾的所有空格用□表示\n\
|
||
import java.io.*;\n\
|
||
import java.util.*;\n\
|
||
\n\
|
||
//请一定不要修改类名\n\
|
||
class Main\n\
|
||
{\n\
|
||
public static void main (String args[])\n\
|
||
{\n\
|
||
//获取参数方式\n\
|
||
//Scanner in = new Scanner(System.in);\n\
|
||
//int a = in.nextInt();\n\
|
||
//int b = in.nextInt();\n\
|
||
\n\
|
||
//您的代码\n\
|
||
}\n\
|
||
}\n\
|
||
';
|
||
}
|
||
else if(language==1){
|
||
src = '\
|
||
//注意\n\
|
||
//1:该程序每次运行的时间必须小于200毫秒,否则会超时,程序超时将不会测试剩余的测试集\n\
|
||
//2:该程序每次运行使用的内存不能超过1M,否则会返回错误\n\
|
||
//3:该程序每次运行输出的结果最多显示1000个字符(多余的不显示),每行末尾的所有空格用□表示\n\
|
||
#include <stdio.h>\n\
|
||
int main()\n\
|
||
{\n\
|
||
//获取参数方式 scanf\n\
|
||
//int x =0;\n\
|
||
//int y = 0;\n\
|
||
//scanf("%d", &x);\n\
|
||
\n\
|
||
//结果输出使用prinf\n\
|
||
//printf("%d",x);\n\
|
||
\n\
|
||
return 0;\n\
|
||
}\n\
|
||
';
|
||
} else if(language==2){
|
||
src = '\
|
||
//注意\n\
|
||
//1:该程序每次运行的时间必须小于200毫秒,否则会超时,程序超时将不会测试剩余的测试集\n\
|
||
//2:该程序每次运行使用的内存不能超过1M,否则会返回错误\n\
|
||
//3:该程序每次运行输出的结果最多显示1000个字符(多余的不显示),每行末尾的所有空格用□表示\n\
|
||
#include <iostream>\n\
|
||
using namespace std;\n\
|
||
\n\
|
||
int main()\n\
|
||
{\n\
|
||
//获取参数方式 cin\n\
|
||
//int x =0;\n\
|
||
//cin >> x;\n\
|
||
\n\
|
||
//结果输出使用 cout\n\
|
||
//cout<<"1";\n\
|
||
\n\
|
||
return 0;\n\
|
||
}\n\
|
||
';
|
||
} else if(language==3){
|
||
src = '\
|
||
#-*-coding:utf-8-*-\n\
|
||
#注意\n\
|
||
#1:该程序每次运行的时间必须小于200毫秒,否则会超时,程序超时将不会测试剩余的测试集\n\
|
||
#2:该程序每次运行使用的内存不能超过1M,否则会返回错误\n\
|
||
#3:该程序每次运行输出的结果最多显示1000个字符(多余的不显示),空格用□表示\n\
|
||
import sys \n\
|
||
\n\
|
||
#获取参数方式,使用raw_input\n\
|
||
#input = raw_input()\n\
|
||
#a, b = input.split()\n\
|
||
\n\
|
||
#结果输出使用 print \n\
|
||
#print (str(int(a)+int(b)))\n\
|
||
';
|
||
}
|
||
|
||
$('#program-src').val(src);
|
||
};
|
||
|
||
var editor = CodeMirror.fromTextArea(document.getElementById("program-src"), {
|
||
mode: {name: program_name,
|
||
version: 2,
|
||
singleLineStringErrors: false},
|
||
lineNumbers: true,
|
||
indentUnit: 2,
|
||
matchBrackets: true
|
||
});
|
||
|
||
editor.on('change',function(cMirror){
|
||
// get value right from instance
|
||
$('#program-src').val(cMirror.getValue());
|
||
});
|
||
}
|
||
});
|
||
function alert_choose_homework_type(id){
|
||
var htmlvalue = '<div class="task-popup" style="width:300px;">' +
|
||
'<div class="task-popup-title clearfix task-popup-bggrey">' +
|
||
'<h3 class="fl">选择作业类别</h3>' +
|
||
'<a href="javascript:void(0);" class="pop_close"><i class="fa fa-times-circle font-18 link-color-grey fr mt5"></i></a>' +
|
||
'</div>' +
|
||
'<div class="task_popup_con">' +
|
||
'<div class="newupload_conbox">' +
|
||
'<div class="clearfix mb15">' +
|
||
'<span class="fl mt5">作业类别:</span>' +
|
||
'<ul class="fl">' +
|
||
'<li class="clearfix">' +
|
||
'<input type="radio" name="homework_type" value="1" id="homework_type_1" class="fl magic-radio">' +
|
||
'<label for="homework_type_1" class="fl ml5 edu-class-pop-label edu-color-grey">' +
|
||
'普通作业' +
|
||
'</label>' +
|
||
'</li>' +
|
||
'<li class="clearfix">' +
|
||
'<input type="radio" name="homework_type" value="3" id="homework_type_2" class="fl magic-radio">' +
|
||
'<label for="homework_type_2" class="fl ml5 edu-class-pop-label edu-color-grey">' +
|
||
'分组作业' +
|
||
'</label>' +
|
||
'</li>' +
|
||
'<li class="clearfix">' +
|
||
'<input type="radio" name="homework_type" value="2" id="homework_type_3" class="fl magic-radio edu-color-grey">' +
|
||
'<label for="homework_type_3" class="fl ml5 edu-class-pop-label">' +
|
||
'编程作业' +
|
||
'</label>' +
|
||
'</li>' +
|
||
'<li class="clearfix">' +
|
||
'<input type="radio" name="homework_type" value="4" id="homework_type_4" class="fl magic-radio edu-color-grey">' +
|
||
'<label for="homework_type_4" class="fl ml5 edu-class-pop-label">' +
|
||
'实训作业' +
|
||
'</label>' +
|
||
'</li>' +
|
||
'</ul>' +
|
||
'</div>' +
|
||
'<div class="cl"></div>' +
|
||
'<div id="homework_type_notice" class="clearfix color-red none mt-10 ml75">请先选择作业类型</div>' +
|
||
'<div class="task-popup-submit clearfix">' +
|
||
'<a href="javascript:void(0);" class="task-btn fl pop_close">取消</a>' +
|
||
'<a href="javascript:void(0);" onclick="new_homework_type('+id+')" class="task-btn task-btn-orange fr">确定</a>' +
|
||
'</div>' +
|
||
'</div>' +
|
||
'</div>' +
|
||
'</div>';
|
||
pop_box_new(htmlvalue, 300, 308);
|
||
}
|
||
|
||
function new_homework_type(id){
|
||
if($("input[name='homework_type']:checked").length == 0){
|
||
$("#homework_type_notice").show();
|
||
} else{
|
||
var type=$("input[name='homework_type']:checked").val();
|
||
console.log(type == 4);
|
||
if(type == 4){
|
||
$.ajax({
|
||
url: '/homework_common/shixuns?course='+id,
|
||
dataType: "script"
|
||
});
|
||
}else{
|
||
window.location.href = '/homework_common/new?course='+id+'&homework_type=' + $("input[name='homework_type']:checked").val();
|
||
}
|
||
}
|
||
}
|
||
|
||
function new_shixun_homework(id){
|
||
if($("input[name='shixun_homework']:checked").length == 0){
|
||
$("#homework_type_notice").show();
|
||
} else{
|
||
var type=$("input[name='shixun_homework']:checked").val();
|
||
console.log(type);
|
||
$("#shixun_homework_common_new").submit();
|
||
hideModal();
|
||
}
|
||
}
|