[前端]修改了添加比赛页的形式结构,仍有bug[CI SKIP]
This commit is contained in:
@@ -1,103 +1,8 @@
|
||||
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker",
|
||||
"formValidation",],
|
||||
"validator"],
|
||||
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
|
||||
avalon.vmodels.add_contest = null;
|
||||
$("#add-contest-form")
|
||||
.formValidation({
|
||||
framework: "bootstrap",
|
||||
fields: {
|
||||
name: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请填写比赛名称"
|
||||
},
|
||||
stringLength: {
|
||||
min: 1,
|
||||
max: 30,
|
||||
message: "名称不能超过30个字"
|
||||
}
|
||||
}
|
||||
},
|
||||
description: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入描述"
|
||||
}
|
||||
}
|
||||
},
|
||||
start_time: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请填写开始时间"
|
||||
|
||||
},
|
||||
date: {
|
||||
format: "YYYY-MM-DD h:m",
|
||||
message: "请输入一个正确的日期格式"
|
||||
}
|
||||
}
|
||||
},
|
||||
end_time: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请填写结束时间"
|
||||
},
|
||||
date: {
|
||||
format: "YYYY-MM-DD h:m",
|
||||
message: "请输入一个正确的日期格式"
|
||||
}
|
||||
}
|
||||
},
|
||||
password: {
|
||||
validators: {
|
||||
stringLength: {
|
||||
min: 0,
|
||||
max: 30,
|
||||
message: "密码不能超过10个字符"
|
||||
}
|
||||
}
|
||||
},
|
||||
"problem_name[]": {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入题目名称"
|
||||
},
|
||||
stringLength: {
|
||||
min: 1,
|
||||
max: 30,
|
||||
message: "题目不能超过30个字符"
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu[]": {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入时间限制"
|
||||
},
|
||||
integer: {
|
||||
message: "时间限制用整数表示"
|
||||
},
|
||||
between: {
|
||||
inclusive: true,
|
||||
min: 1,
|
||||
max: 5000,
|
||||
message: "只能在1-5000之间"
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory[]": {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入内存"
|
||||
},
|
||||
integer: {
|
||||
message: "请输入一个合法的数字"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.on("success.form.fv", function (e) {
|
||||
$("#add-contest-form").validator().on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
title: vm.title,
|
||||
@@ -127,7 +32,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
}
|
||||
});
|
||||
console.log(data);
|
||||
});
|
||||
})
|
||||
function make_id() {
|
||||
var text = "";
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
@@ -135,13 +40,11 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
return text;
|
||||
}
|
||||
var upLoaderInited = false;
|
||||
editor("#editor");
|
||||
|
||||
var vm = avalon.define({
|
||||
$id: "add_contest",
|
||||
title: "",
|
||||
problemCount: 0,
|
||||
description: "",
|
||||
startTime: "",
|
||||
endTime: "",
|
||||
@@ -149,45 +52,61 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
model: "",
|
||||
openRank: false,
|
||||
problems: [],
|
||||
problemNo: "-1",
|
||||
editingProblemId: 0,
|
||||
editSamples: [],
|
||||
editTestCaseList: [],
|
||||
showProblemEditArea: function (problemIndex) {
|
||||
if (vm.editingProblemId == problemIndex){
|
||||
vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
|
||||
vm.editingProblemId = 0;
|
||||
}
|
||||
else {
|
||||
vm.problems[problemIndex-1].samples = vm.editSamples;
|
||||
vm.problems[problemIndex-1].testCaseList = vm.editTestCaseList;
|
||||
vm.editingProblemId = problemIndex;
|
||||
editSamples = vm.problems[vm.editingProblemId-1].samples;
|
||||
editTestCaseList = vm.problems[vm.editingProblemId-1].testCaseList;
|
||||
}
|
||||
},
|
||||
add_problem: function () {
|
||||
var problem_id = make_id();
|
||||
var problem = {
|
||||
id: problem_id,
|
||||
title: "",
|
||||
cpu: 1000,
|
||||
memory: 256,
|
||||
timeLimit: 1000,
|
||||
memoryLimit: 256,
|
||||
description: "",
|
||||
samples: [],
|
||||
visible: true,
|
||||
test_case_id: "",
|
||||
testCaseList: [],
|
||||
hint: "",
|
||||
difficulty: 0,
|
||||
uploadSuccess: false
|
||||
score: 0,
|
||||
uploadSuccess: false,
|
||||
};
|
||||
vm.problems.push(problem);
|
||||
var id = vm.problems.length - 1;
|
||||
editor("#problem-" + problem_id + "-description");
|
||||
var hinteditor = editor("#problem-" + problem_id +"-hint");
|
||||
$("#add-contest-form").formValidation('addField', $('[name="problem_name[]"]'));
|
||||
$("#add-contest-form").formValidation('addField', $('[name="cpu[]"]'));
|
||||
$("#add-contest-form").formValidation('addField', $('[name="memory[]"]'));
|
||||
vm.showProblemEditArea(vm.problems.length);
|
||||
},
|
||||
del_problem: function (problem) {
|
||||
del_problem: function (problemIndex) {
|
||||
if (confirm("你确定要删除么?")) {
|
||||
vm.problems.remove(problem);
|
||||
vm.editingProblemId = 0;
|
||||
vm.problems.remove(vm.problems[problemIndex-1]);
|
||||
}
|
||||
},
|
||||
hidden: function () {
|
||||
vm.problems[vm.editingProblemId-1].samples = editSamples;
|
||||
vm.problems[vm.editingProblemId-1].testCaseList = editTestCaseList;
|
||||
vm.editingProblemId = 0;
|
||||
},
|
||||
toggle: function (item) {
|
||||
item.visible = !item.visible;
|
||||
},
|
||||
add_sample: function (problem) {
|
||||
problem.samples.push({id: make_id(), visible: true, input: "", output: ""});
|
||||
add_sample: function () {
|
||||
//vm.problems[vm.editingProblemId-1].samples.push({visible: true, input: "", output: ""});
|
||||
vm.editSamples.push({visible: true, input: "", output: ""});
|
||||
},
|
||||
del_sample: function (problem, sample) {
|
||||
del_sample: function (sample) {
|
||||
if (confirm("你确定要删除么?")) {
|
||||
problem.samples.remove(sample);
|
||||
editSamples.remove(sample);
|
||||
}
|
||||
},
|
||||
getBtnContent: function (item) {
|
||||
@@ -201,29 +120,28 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
if (respond.code)
|
||||
bsAlert(respond.data);
|
||||
else {
|
||||
var index = parseInt(vm.problemNo)-1;
|
||||
vm.problems[index].test_case_id = respond.data.test_case_id;
|
||||
vm.problems[index].uploadSuccess = true;
|
||||
vm.problems[index].testCaseList = [];
|
||||
vm.problems[vm.editingProblemId-1].test_case_id = respond.data.test_case_id;
|
||||
vm.problems[vm.editingProblemId-1].uploadSuccess = true;
|
||||
vm.editTestCaseList = [];
|
||||
for (var i = 0; i < respond.data.file_list.input.length; i++) {
|
||||
vm.problems[index].testCaseList.push({
|
||||
vm.editTestCaseList.push({
|
||||
input: respond.data.file_list.input[i],
|
||||
output: respond.data.file_list.output[i]
|
||||
});
|
||||
}
|
||||
bsAlert("测试数据添加成功!共添加"+vm.problems[index].testCaseList.length +"组测试数据");
|
||||
vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
|
||||
bsAlert("测试数据添加成功!共添加"+editTestCaseList.length +"组测试数据");
|
||||
}
|
||||
},
|
||||
function(){
|
||||
console.log(vm.problemNo);
|
||||
if (vm.problemNo == "-1")
|
||||
if (vm.editingProblemId == 0)
|
||||
{
|
||||
bsAlert("你还未指定一道题目!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
isUploaderInited = true;
|
||||
|
||||
avalon.scan();
|
||||
|
||||
@@ -249,4 +167,4 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
$("#add-contest-form")
|
||||
.formValidation("revalidateField", "end_time");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user