[前端-添加题目,添加比赛 ]:

1.新增添加题目页面。
2.修改添加比赛页面,统一了avalon的用法,新增富文本编辑框的非空验证
3.收集新增比赛和新增题目页面输入,提交表单后可以在console中看到提交的值

[CI SKIP]
This commit is contained in:
sxw
2015-08-09 20:50:04 +08:00
parent 2ce38a6fc0
commit da62522279
6 changed files with 268 additions and 64 deletions

View File

@@ -19,6 +19,13 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
}
}
},
description:{
validators: {
notEmpty: {
message: "请输入描述"
}
}
},
start_time: {
validators: {
notEmpty: {
@@ -93,9 +100,18 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
})
.on("success.form.fv", function (e) {
e.preventDefault();
alert("1111");
var data = {title: vm.title, description: vm.description, start_time: vm.startTime, end_time: vm.endTime,
password: vm.password, model: vm.model, open_rank: vm.openRank, problems:[]};
for (var i = 0; i < vm.problems.length; i++) {
var problem = {title: vm.problems[i].title, description:vm.problems[i].description,
cpu:vm.problems[i].cpu, memory:vm.problems[i].memory,samples:[]};
for (var j = 0; j < vm.problems[i].samples.length; j++) {
problem.samples.push({input:vm.problems[i].samples[j].input, output:vm.problems[i].samples[j].output})
}
data.problems.push(problem);
}
console.log(data);
});
function make_id() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -107,17 +123,20 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
var vm = avalon.define({
$id: "add_contest",
title : "",
description: "",
startTime: "",
endTime: "",
password: "",
model: "",
openRank: false,
problems: [],
add_problem: function () {
var problem = {};
var problem_id = make_id();
problem["id"] = problem_id;
problem["samples"] = [];
problem["webuploader"] = {};
problem["toggle_string"] = "折叠";
var problem={id: problem_id, title: "", cpu: "", memory: "", description: "",samples: [], webuploader: {}, visible: true};
vm.problems.push(problem);
uploader("#problem-" + problem_id + "-uploader");
console.log(vm.problems);
uploader("#problem-" + problem_id + "-uploader","");
editor("#problem-" + problem_id + "-description")
$("#add-contest-form").formValidation('addField', $('[name="problem_name[]"]'));
$("#add-contest-form").formValidation('addField', $('[name="cpu[]"]'));
$("#add-contest-form").formValidation('addField', $('[name="memory[]"]'));
@@ -127,31 +146,21 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
vm.problems.remove(problem);
}
},
toggle_problem: function (problem) {
$("#" + "problem-" + problem.id + "-body").toggle();
if (problem["toggle_string"] == "展开") {
problem["toggle_string"] = "折叠";
}
else {
problem["toggle_string"] = "展开";
}
toggle: function (item) {
item.visible = !item.visible;
},
add_sample: function (problem) {
problem["samples"].push({"id": make_id(), "toggle_string": "折叠"});
problem.samples.push({id: make_id(), visible: true, input: "", output: ""});
},
del_sample: function (problem, sample) {
if (confirm("你确定要删除么?")) {
problem["samples"].remove(sample);
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"] = "展开";
}
getBtnContent: function (item) {
if (item.visible)
return "折叠";
return "展开";
}
});
avalon.scan();
@@ -168,7 +177,6 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
weekStart: 1,
language: "zh-CN"
});
$("#contest_start_time").datetimepicker()
.on("hide", function (ev) {
$("#add-contest-form")

View File

@@ -0,0 +1,108 @@
require(["jquery", "avalon", "editor", "uploader", "validation"],
function ($, avalon, editor, uploader) {
avalon.vmodels.add_problem = null;
$("#add-problem-form")
.formValidation({
framework: "bootstrap",
fields: {
title: {
validators: {
notEmpty: {
message: "请填写题目名称"
},
stringLength: {
min: 1,
max: 30,
message: "名称不能超过30个字"
}
}
},
description:{
validators: {
notEmpty: {
message: "请输入描述"
}
}
},
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();
var ajaxData = {
title: vm.title,
description: vm.description,
cpu: vm.cpu,
memory: vm.memory,
samples: []
};
for (var i = 0; i < vm.samples.length; i++) {
ajaxData.samples.push({input: vm.samples[i].input, output: vm.samples[i].output});
}
console.log(ajaxData);
});
var problemDiscription = editor("#problemDescription");
var testCaseUploader = uploader("#testCaseFile", "/admin/api/testCase");//{
/*auto: true,
swf: '/static/js/lib/webuploader/Uploader.swf',
server: 'http://webuploader.duapp.com/server/fileupload.php',
multiple:false,
accept: {
title: 'Zip',
extensions: 'zip',
mimeTypes: 'zip/*'
}*/
// });
var vm = avalon.define({
$id: "add_problem",
title: "",
description: "",
cpu: 0,
memory: 0,
samples: [],
add_sample: function () {
vm.samples.push({input: "", output: "", "visible": true});
},
del_sample: function (sample) {
if (confirm("你确定要删除么?")) {
vm.samples.remove(sample);
}
},
toggle_sample: function (sample) {
sample.visible = !sample.visible;
},
getBtnContent: function (item) {
if (item.visible)
return "折叠";
return "展开";
}
});
avalon.scan();
});

Binary file not shown.

View File

@@ -1,12 +1,12 @@
define("uploader", ["webuploader"], function(webuploader){
function uploader(selector) {
function uploader(selector, server) {
return webuploader.create({
// swf文件路径
swf: "/js/Uploader.swf",
// 文件接收服务端。
server: "http://webuploader.duapp.com/server/fileupload.php",
server: server,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建可能是input元素也可能是flash.