diff --git a/static/src/js/app/admin/contest/contest.js b/static/src/js/app/admin/contest/contest.js index 6cd531d..e9b44ba 100644 --- a/static/src/js/app/admin/contest/contest.js +++ b/static/src/js/app/admin/contest/contest.js @@ -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") diff --git a/static/src/js/app/admin/problem/add_problem.js b/static/src/js/app/admin/problem/add_problem.js new file mode 100644 index 0000000..c60fd23 --- /dev/null +++ b/static/src/js/app/admin/problem/add_problem.js @@ -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(); + }); \ No newline at end of file diff --git a/static/src/img/Uploader.swf b/static/src/js/lib/webuploader/Uploader.swf similarity index 100% rename from static/src/img/Uploader.swf rename to static/src/js/lib/webuploader/Uploader.swf diff --git a/static/src/js/utils/uploader.js b/static/src/js/utils/uploader.js index 76e5447..ec418c5 100644 --- a/static/src/js/utils/uploader.js +++ b/static/src/js/utils/uploader.js @@ -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. diff --git a/template/admin/contest/add_contest.html b/template/admin/contest/add_contest.html index 4ac0be8..6349814 100644 --- a/template/admin/contest/add_contest.html +++ b/template/admin/contest/add_contest.html @@ -2,11 +2,11 @@