2015-08-28 12:04:49 +08:00
|
|
|
$(function(){
|
|
|
|
|
2015-08-29 11:59:52 +08:00
|
|
|
var bt=baidu.template;
|
|
|
|
bt.LEFT_DELIMITER='<!';
|
|
|
|
bt.RIGHT_DELIMITER='!>';
|
|
|
|
|
|
|
|
var tested = false;
|
2015-08-28 15:08:07 +08:00
|
|
|
var valid_form = function() {
|
|
|
|
var src = $('#program-src').val();
|
|
|
|
var title = $('#program-title').val();
|
|
|
|
|
|
|
|
if (!src) {
|
|
|
|
alert('请输入正确的代码');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!title) {
|
|
|
|
alert('请输入标题');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-29 11:59:52 +08:00
|
|
|
var test_program = function(cb){
|
|
|
|
var homework_id = $('#test-program-btn').attr('data-homework-id');
|
|
|
|
var student_work_id = $('#test-program-btn').attr('data-student-work-id');
|
2015-08-28 12:04:49 +08:00
|
|
|
var src = $('#program-src').val();
|
2015-08-28 15:08:07 +08:00
|
|
|
var title = $('#program-title').val();
|
2015-08-28 12:04:49 +08:00
|
|
|
|
2015-08-28 15:08:07 +08:00
|
|
|
if(!valid_form()){
|
2015-08-28 12:04:49 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
'/student_work/program_test',
|
|
|
|
{homework: homework_id, student_work_id: student_work_id, src: src, title: title},
|
|
|
|
function(data,status){
|
2015-08-29 11:59:52 +08:00
|
|
|
tested = true;
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
if (cb) {cb(); return;}
|
|
|
|
|
|
|
|
var html=bt('t:result-list',data);
|
|
|
|
$('.ProResult').prepend(html);
|
|
|
|
if (data.status==0) {
|
|
|
|
var r=confirm("答题正确,是否立刻提交?");
|
|
|
|
if (r) {
|
|
|
|
$(".HomeWorkCon form").submit();
|
|
|
|
}
|
2015-08-28 12:04:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-08-29 11:59:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$('#test-program-btn').on('click', test_program);
|
2015-08-28 15:08:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
$('#commit-program-work-btn').on('click', function(){
|
|
|
|
if(!valid_form()){
|
|
|
|
return;
|
|
|
|
}
|
2015-08-29 11:59:52 +08:00
|
|
|
if($('.ProResult .ProResultTop').length<=0){
|
|
|
|
var r=confirm("测试后才能提交,是否立刻测试?");
|
|
|
|
if (r) {
|
|
|
|
test_program();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tested) {
|
|
|
|
test_program(function(){
|
|
|
|
$(".HomeWorkCon form").submit();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:08:07 +08:00
|
|
|
$(".HomeWorkCon form").submit();
|
|
|
|
});
|
|
|
|
|
2015-08-29 11:59:52 +08:00
|
|
|
$('form.edit_student_work').on('keydown', '#program-src', function(){
|
|
|
|
tested = false;
|
|
|
|
})
|
2015-08-28 12:04:49 +08:00
|
|
|
});
|