From 0eb5b0f62ac100e2b2f0ac793b6d790aab06a677 Mon Sep 17 00:00:00 2001 From: esp Date: Tue, 18 Aug 2015 13:21:33 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=E7=BB=9F=E4=B8=80=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E9=87,=E6=AF=94=E8=B5=9B=E5=88=97=E8=A1=A8js=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=5Flist.js.=20=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E6=AF=94=E8=B5=9B=E5=88=97=E8=A1=A8=E5=92=8C=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=AF=94=E8=B5=9B=E7=9A=84=E9=A1=B5=E9=9D=A2(?= =?UTF-8?q?=E5=A4=A7=E4=BD=93=E5=A4=E6=A0=B7=E5=BC=8F)[CI=20SKIP]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/admin/contest/contest.js | 242 --------------------- template/admin/contest/add_contest.html | 4 +- 2 files changed, 2 insertions(+), 244 deletions(-) delete mode 100644 static/src/js/app/admin/contest/contest.js diff --git a/static/src/js/app/admin/contest/contest.js b/static/src/js/app/admin/contest/contest.js deleted file mode 100644 index 736ce58..0000000 --- a/static/src/js/app/admin/contest/contest.js +++ /dev/null @@ -1,242 +0,0 @@ -require(["jquery", "avalon", "editor", "uploader", "bs_alert", "datetimepicker", - "validation",], - function ($, avalon, editor, uploader, bs_alert) { - 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) { - e.preventDefault(); - 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"; - for (var i = 0; i < 5; i++) - 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: "", - password: "", - model: "", - openRank: false, - problems: [], - problemNo: "-1", - add_problem: function () { - var problem_id = make_id(); - var problem = { - id: problem_id, - title: "", - cpu: 1000, - memory: 256, - description: "", - samples: [], - visible: true, - test_case_id: "", - testCaseList: [], - hint: "", - difficulty: 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[]"]')); - }, - del_problem: function (problem) { - if (confirm("你确定要删除么?")) { - vm.problems.remove(problem); - } - }, - toggle: function (item) { - item.visible = !item.visible; - }, - add_sample: function (problem) { - problem.samples.push({id: make_id(), visible: true, input: "", output: ""}); - }, - del_sample: function (problem, sample) { - if (confirm("你确定要删除么?")) { - problem.samples.remove(sample); - } - }, - getBtnContent: function (item) { - if (item.visible) - return "折叠"; - return "展开"; - } - }); - - uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) { - if (respond.code) - bs_alert(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 = []; - for (var i = 0; i < respond.data.file_list.input.length; i++) { - vm.problems[index].testCaseList.push({ - input: respond.data.file_list.input[i], - output: respond.data.file_list.output[i] - }); - } - bs_alert("测试数据添加成功!共添加"+vm.problems[index].testCaseList.length +"组测试数据"); - } - }, - function(){ - console.log(vm.problemNo); - if (vm.problemNo == "-1") - { - bs_alert("你还未指定一道题目!"); - return false; - } - } - ); - isUploaderInited = true; - - 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"); - }); - }); \ No newline at end of file diff --git a/template/admin/contest/add_contest.html b/template/admin/contest/add_contest.html index 1d27710..f3481cb 100644 --- a/template/admin/contest/add_contest.html +++ b/template/admin/contest/add_contest.html @@ -196,5 +196,5 @@ - - \ No newline at end of file + +