socialforge/public/javascripts/homework.js

137 lines
3.8 KiB
JavaScript
Raw Normal View History

2015-08-28 12:04:49 +08:00
$(function(){
2015-08-29 18:21:01 +08:00
//提交作业
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-09-02 21:38:13 +08:00
var is_test = $('input[name=is_test]').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',
2015-09-02 21:38:13 +08:00
{homework: homework_id, student_work_id: student_work_id, src: src, title: title, is_test: is_test},
2015-08-28 12:04:49 +08:00
function(data,status){
2015-08-29 11:59:52 +08:00
tested = true;
console.log(data);
2015-09-02 22:09:23 +08:00
if(data.index <=0){
data.index = $('.ProResultTop').length+1;
}
2015-08-29 11:59:52 +08:00
2015-09-01 16:18:03 +08:00
if (typeof cb == 'function') {cb(); return;}
2015-08-29 11:59:52 +08:00
2015-08-29 18:21:01 +08:00
2015-08-29 11:59:52 +08:00
var html=bt('t:result-list',data);
$('.ProResult').prepend(html);
2015-08-29 18:21:01 +08:00
2015-09-02 22:09:23 +08:00
if (data.status==0 && is_test != 'true') {
2015-08-29 11:59:52 +08:00
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-29 18:21:01 +08:00
});
//发布作业
2015-09-01 16:18:03 +08:00
var isProgramHomework = function(){
return !$(".advanced_option").is(":hidden");
}
2015-08-29 18:21:01 +08:00
2015-09-01 16:18:03 +08:00
var submit_comm_homework = function(id){
var valid = true;
if (isProgramHomework()) {
$.each($('.advanced_option textarea.InputBox'), function(i, val){
if ($(val).val().length<=0) {
$(val).focus();
valid = false;
return false;
}
});
if (valid) {
$('input[name=homework_type]').val(2);
};
}
if (valid) {
submit_homework(id);
}
}
window.submit_comm_homework = submit_comm_homework;
2015-08-29 18:21:01 +08:00
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();
2015-08-29 11:59:52 +08:00
})
2015-08-29 18:21:01 +08:00
$('a.DropBtn').on('click', function(){
2015-09-01 16:18:03 +08:00
$(".advanced_option").toggle();
2015-08-29 18:21:01 +08:00
});
$(".HomeWork").on('click', 'a.icon_add', function(){
var html = bt('t:test-answer-list', null);
$(this).parent('.mt10').after(html);
});
$(".HomeWork").on('click', 'a.icon_remove', function(){
$(this).parent('.mt10').remove();
});
2015-08-28 12:04:49 +08:00
});