将 admin 模块化拆分
This commit is contained in:
@@ -1,181 +1 @@
|
|||||||
require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
|
require(["contest"]);
|
||||||
"validation"
|
|
||||||
],
|
|
||||||
function ($, avalon, editor, uploader) {
|
|
||||||
$("#add-contest-form")
|
|
||||||
.formValidation({
|
|
||||||
framework: "bootstrap",
|
|
||||||
fields: {
|
|
||||||
name: {
|
|
||||||
validators: {
|
|
||||||
notEmpty: {
|
|
||||||
message: "请填写比赛名称"
|
|
||||||
},
|
|
||||||
stringLength: {
|
|
||||||
min: 1,
|
|
||||||
max: 30,
|
|
||||||
message: "名称不能超过30个字"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
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: "请输入cpu时间"
|
|
||||||
},
|
|
||||||
integer: {
|
|
||||||
message: "请输入一个合法的数字"
|
|
||||||
},
|
|
||||||
between: {
|
|
||||||
inclusive: true,
|
|
||||||
min: 1,
|
|
||||||
max: 5000,
|
|
||||||
message: "只能在1-5000之间"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"memory[]": {
|
|
||||||
validators: {
|
|
||||||
notEmpty: {
|
|
||||||
message: "请输入内存"
|
|
||||||
},
|
|
||||||
integer: {
|
|
||||||
message: "请输入一个合法的数字"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on("success.form.fv", function (e) {
|
|
||||||
e.preventDefault();
|
|
||||||
alert("1111");
|
|
||||||
});
|
|
||||||
|
|
||||||
function make_id() {
|
|
||||||
var text = "";
|
|
||||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
||||||
for (var i = 0; i < 5; i++)
|
|
||||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
var editor1 = editor("#editor");
|
|
||||||
|
|
||||||
var vm = avalon.define({
|
|
||||||
$id: "add_contest",
|
|
||||||
problems: [],
|
|
||||||
add_problem: function () {
|
|
||||||
var problem = {};
|
|
||||||
var problem_id = make_id();
|
|
||||||
problem["id"] = problem_id;
|
|
||||||
problem["samples"] = [];
|
|
||||||
problem["webuploader"] = {};
|
|
||||||
problem["toggle_string"] = "折叠";
|
|
||||||
vm.problems.push(problem);
|
|
||||||
uploader("#problem-" + problem_id + "-uploader");
|
|
||||||
console.log(vm.problems);
|
|
||||||
$("#add-contest-form").formValidation('addField', $('[name="problem_name[]"]'));
|
|
||||||
$("#add-contest-form").formValidation('addField', $('[name="cpu[]"]'));
|
|
||||||
$("#add-contest-form").formValidation('addField', $('[name="memory[]"]'));
|
|
||||||
},
|
|
||||||
del_problem: function (problem) {
|
|
||||||
if (confirm("你确定要删除么?")) {
|
|
||||||
vm.problems.remove(problem);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toggle_problem: function (problem) {
|
|
||||||
$("#" + "problem-" + problem.id + "-body").toggle();
|
|
||||||
if (problem["toggle_string"] == "展开") {
|
|
||||||
problem["toggle_string"] = "折叠";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
problem["toggle_string"] = "展开";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
add_sample: function (problem) {
|
|
||||||
problem["samples"].push({"id": make_id(), "toggle_string": "折叠"});
|
|
||||||
},
|
|
||||||
del_sample: function (problem, sample) {
|
|
||||||
if (confirm("你确定要删除么?")) {
|
|
||||||
problem["samples"].remove(sample);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
toggle_sample: function (problem, sample) {
|
|
||||||
$("#" + "problem-" + problem.id + "-sampleio-" + sample.id + "-body").toggle();
|
|
||||||
if (sample["toggle_string"] == "展开") {
|
|
||||||
sample["toggle_string"] = "折叠";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sample["toggle_string"] = "展开";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
avalon.scan();
|
|
||||||
|
|
||||||
$("#contest_start_time").datetimepicker({
|
|
||||||
format: "yyyy-mm-dd hh:ii",
|
|
||||||
minuteStep: 5,
|
|
||||||
weekStart: 1,
|
|
||||||
language: "zh-CN"
|
|
||||||
});
|
|
||||||
$("#contest_end_time").datetimepicker({
|
|
||||||
format: "yyyy-mm-dd hh:ii",
|
|
||||||
minuteStep: 5,
|
|
||||||
weekStart: 1,
|
|
||||||
language: "zh-CN"
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#contest_start_time").datetimepicker()
|
|
||||||
.on("hide", function (ev) {
|
|
||||||
$("#add-contest-form")
|
|
||||||
.formValidation("revalidateField", "start_time");
|
|
||||||
});
|
|
||||||
$("#contest_end_time").datetimepicker()
|
|
||||||
.on("hide", function (ev) {
|
|
||||||
$("#add-contest-form")
|
|
||||||
.formValidation("revalidateField", "end_time");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
181
static/src/js/app/admin/contest/contest.js
Normal file
181
static/src/js/app/admin/contest/contest.js
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
define("contest", ["jquery", "avalon", "editor", "uploader", "datetimepicker",
|
||||||
|
"validation"
|
||||||
|
],
|
||||||
|
function ($, avalon, editor, uploader) {
|
||||||
|
$("#add-contest-form")
|
||||||
|
.formValidation({
|
||||||
|
framework: "bootstrap",
|
||||||
|
fields: {
|
||||||
|
name: {
|
||||||
|
validators: {
|
||||||
|
notEmpty: {
|
||||||
|
message: "请填写比赛名称"
|
||||||
|
},
|
||||||
|
stringLength: {
|
||||||
|
min: 1,
|
||||||
|
max: 30,
|
||||||
|
message: "名称不能超过30个字"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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: "请输入cpu时间"
|
||||||
|
},
|
||||||
|
integer: {
|
||||||
|
message: "请输入一个合法的数字"
|
||||||
|
},
|
||||||
|
between: {
|
||||||
|
inclusive: true,
|
||||||
|
min: 1,
|
||||||
|
max: 5000,
|
||||||
|
message: "只能在1-5000之间"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"memory[]": {
|
||||||
|
validators: {
|
||||||
|
notEmpty: {
|
||||||
|
message: "请输入内存"
|
||||||
|
},
|
||||||
|
integer: {
|
||||||
|
message: "请输入一个合法的数字"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("success.form.fv", function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
alert("1111");
|
||||||
|
});
|
||||||
|
|
||||||
|
function make_id() {
|
||||||
|
var text = "";
|
||||||
|
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
for (var i = 0; i < 5; i++)
|
||||||
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
var editor1 = editor("#editor");
|
||||||
|
|
||||||
|
var vm = avalon.define({
|
||||||
|
$id: "add_contest",
|
||||||
|
problems: [],
|
||||||
|
add_problem: function () {
|
||||||
|
var problem = {};
|
||||||
|
var problem_id = make_id();
|
||||||
|
problem["id"] = problem_id;
|
||||||
|
problem["samples"] = [];
|
||||||
|
problem["webuploader"] = {};
|
||||||
|
problem["toggle_string"] = "折叠";
|
||||||
|
vm.problems.push(problem);
|
||||||
|
uploader("#problem-" + problem_id + "-uploader");
|
||||||
|
console.log(vm.problems);
|
||||||
|
$("#add-contest-form").formValidation('addField', $('[name="problem_name[]"]'));
|
||||||
|
$("#add-contest-form").formValidation('addField', $('[name="cpu[]"]'));
|
||||||
|
$("#add-contest-form").formValidation('addField', $('[name="memory[]"]'));
|
||||||
|
},
|
||||||
|
del_problem: function (problem) {
|
||||||
|
if (confirm("你确定要删除么?")) {
|
||||||
|
vm.problems.remove(problem);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggle_problem: function (problem) {
|
||||||
|
$("#" + "problem-" + problem.id + "-body").toggle();
|
||||||
|
if (problem["toggle_string"] == "展开") {
|
||||||
|
problem["toggle_string"] = "折叠";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
problem["toggle_string"] = "展开";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
add_sample: function (problem) {
|
||||||
|
problem["samples"].push({"id": make_id(), "toggle_string": "折叠"});
|
||||||
|
},
|
||||||
|
del_sample: function (problem, sample) {
|
||||||
|
if (confirm("你确定要删除么?")) {
|
||||||
|
problem["samples"].remove(sample);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggle_sample: function (problem, sample) {
|
||||||
|
$("#" + "problem-" + problem.id + "-sampleio-" + sample.id + "-body").toggle();
|
||||||
|
if (sample["toggle_string"] == "展开") {
|
||||||
|
sample["toggle_string"] = "折叠";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sample["toggle_string"] = "展开";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
avalon.scan();
|
||||||
|
|
||||||
|
$("#contest_start_time").datetimepicker({
|
||||||
|
format: "yyyy-mm-dd hh:ii",
|
||||||
|
minuteStep: 5,
|
||||||
|
weekStart: 1,
|
||||||
|
language: "zh-CN"
|
||||||
|
});
|
||||||
|
$("#contest_end_time").datetimepicker({
|
||||||
|
format: "yyyy-mm-dd hh:ii",
|
||||||
|
minuteStep: 5,
|
||||||
|
weekStart: 1,
|
||||||
|
language: "zh-CN"
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#contest_start_time").datetimepicker()
|
||||||
|
.on("hide", function (ev) {
|
||||||
|
$("#add-contest-form")
|
||||||
|
.formValidation("revalidateField", "start_time");
|
||||||
|
});
|
||||||
|
$("#contest_end_time").datetimepicker()
|
||||||
|
.on("hide", function (ev) {
|
||||||
|
$("#add-contest-form")
|
||||||
|
.formValidation("revalidateField", "end_time");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,3 +1 @@
|
|||||||
|
|
||||||
|
|
||||||
require(["bootstrap", "login", "submit_code"]);
|
require(["bootstrap", "login", "submit_code"]);
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ var require = {
|
|||||||
uploader: "utils/uploader",
|
uploader: "utils/uploader",
|
||||||
validation: "utils/validation",
|
validation: "utils/validation",
|
||||||
code_mirror: "utils/code_mirror",
|
code_mirror: "utils/code_mirror",
|
||||||
login: "app/account/login",
|
login: "app/oj/account/login",
|
||||||
oj: "app/oj",
|
oj: "app/oj/oj",
|
||||||
"bs_alert": "utils/bs_alert",
|
"bs_alert": "utils/bs_alert",
|
||||||
submit_code: "app/problem/submit_code",
|
submit_code: "app/oj/problem/submit_code",
|
||||||
|
contest: "app/admin/contest/contest",
|
||||||
|
|
||||||
//formValidation 不要在代码中单独使用,而是使用和修改utils/validation
|
//formValidation 不要在代码中单独使用,而是使用和修改utils/validation
|
||||||
base: "lib/formValidation/base",
|
base: "lib/formValidation/base",
|
||||||
|
|||||||
Reference in New Issue
Block a user