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

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

@@ -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();
});