$(function(){
//提交作业
var bt=baidu.template;
bt.LEFT_DELIMITER='';
var tested = false;
var valid_form = function() {
var src = $('#program-src').val();
var title = $('#program-title').val();
if (!src) {
var htmlvalue = "
请输入正确的代码!
";
pop_up_box(htmlvalue,580,30,50);
return false;
}
if (!title) {
var htmlvalue = "请输入标题!
";
pop_up_box(htmlvalue,580,30,50);
return false;
}
return true;
};
var test_program = function(cb){
$('#test-program-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 title = $('#program-title').val();
var is_test = $('input[name=is_test]').val();
if(!valid_form()){
$('#test-program-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, title: title, 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"
var htmlvalue = "您的程序引发了不知名异常,请在公共贴吧提交您的代码进行意见反馈,我们处理后会立即联系您,谢谢!
";
pop_up_box(htmlvalue,580,30,50);
$('#test-program-btn').show();
return;
}
else if (data.status==-3){
var htmlvalue = "对不起,服务器繁忙请稍后再试!
";
pop_up_box(htmlvalue,580,30,50);
$('#test-program-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 = $('.ProResultTop').length+1;
}
var html=bt('t:result-list',data);
$('.ProResult').prepend(html);
if (data.status==0 && is_test != 'true') {
if (typeof cb == 'function') {cb(data);$('#test-program-btn').show(); return;}
var htmlvalue = "答题正确,是否立刻提交?
";
pop_up_box(htmlvalue,580,30,50);
$('#test-program-btn').show();
return;
}
//2 超时 -2 编译错误 测试结束
if (data.status == 2 || data.status == -2 || tSeq >= tCount ){
if (typeof cb == 'function') {cb(data);$('#test-program-btn').show(); return;}
$('#test-program-btn').show();
return;
}
test_post(i+1, data.testid);
}
).fail(function(xhr, status){
if(status == 'timeout'){
var htmlvalue = "您的答案超时了, 请检查代码是否存在死循环的错误!
";
pop_up_box(htmlvalue,580,30,50);
} else {
var htmlvalue = "对不起,服务器繁忙请稍后再试!
";
pop_up_box(htmlvalue,580,30,50);
}
$('#test-program-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;
}
if($('.ProResult .ProResultTop').length<=0){
var htmlvalue = "测试后才能提交,是否立刻测试?
";
pop_up_box(htmlvalue,580,30,50);
$("#code-test-button").on('click',function(){
test_program();
hideModal();
});
return;
}
if (!tested) {
test_program(function(data){
if (data.status!=0) {
var htmlvalue = "测试不通过,是否强制提交?
";
pop_up_box(htmlvalue,580,30,50);
return;
};
$(".HomeWorkCon form").submit();
});
return;
}
$(".HomeWorkCon form").submit();
});
$('form.edit_student_work').on('keydown', '#program-src', function(){
tested = false;
});
//发布作业
$('#program-src').focus(function(){
$(this).css('height', '100px');
});
var datepickerOptions={dateFormat:'yy-mm-dd',firstDay:0,showWeek:true,showOtherMonths:true,selectOtherMonths:true};
$('input.date-input').datepicker(datepickerOptions);
$('a.pic_date').on('click', function(){
$(this).parent().prev().first().focus();
})
$("#NoticePopupBox").dialog({
modal: true,
autoOpen: false,
dialogClass: 'BluePopupBox',
minWidth: 500
});
$('#NoticePopupBox').parent().resizable("disable");
$('#NoticePopupBox').parent().removeClass("ui-state-disabled");
$('#NoticePopupBox').parent().css("border","3px solid #269ac9").css("padding","10px");
$('a#switch_type').live('click', function(){
if($("input[name=homework_type]").val() == "3"){
$("#NoticePopupBox" ).dialog("close");
$("input[name=homework_type]").val(1);
$('span.group_detail_info').text('');
$("#group_setting a").removeClass("fontBlue2");
$("#BluePopupBox").dialog("open");
$(".ui-dialog-titlebar").hide();
$("a.CloseBtn").on('click', function(){
$("#BluePopupBox" ).dialog("close");
});
var inputs = document.getElementsByName("program[input][]");
var outputs = document.getElementsByName("program[output][]");
if (inputs.length == outputs.length) {
for (var i=0; i