From 9e4342f6490107f94a195e4dde64103ef03a39e9 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sat, 7 Nov 2015 13:05:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20vm=20=E4=B8=AD=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=B8=85=E9=99=A4=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B=E6=9B=BF=E6=8D=A2=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E4=B8=8A=E4=BC=A0=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/js/app/admin/contest/editProblem.js | 70 +++++-------------- 1 file changed, 16 insertions(+), 54 deletions(-) diff --git a/static/src/js/app/admin/contest/editProblem.js b/static/src/js/app/admin/contest/editProblem.js index 05aff438..c19a26b1 100644 --- a/static/src/js/app/admin/contest/editProblem.js +++ b/static/src/js/app/admin/contest/editProblem.js @@ -8,7 +8,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", .on('submit', function (e) { if (!e.isDefaultPrevented()) { e.preventDefault(); - if (vm.testCaseId == "") { + if (!avalon.vmodels.testCaseUploader.uploaded) { bsAlert("你还没有上传测试数据!"); return false; } @@ -36,7 +36,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", time_limit: vm.timeLimit, memory_limit: vm.memoryLimit, samples: [], - test_case_id: vm.testCaseId, + test_case_id: avalon.vmodels.testCaseUploader.testCaseId, hint: avalon.vmodels.contestProblemHintEditor.content, visible: vm.visible, contest_id: avalon.vmodels.admin.contestId, @@ -72,6 +72,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", success: function (data) { if (!data.code) { bsAlert(alertContent); + avalon.vmodels.admin.template_url = "template/contest/problem_list.html"; } else { bsAlert(data.data); @@ -98,7 +99,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", outputDescription: "", testCaseId: "", testCaseList: [], - uploadSuccess: false, contestProblemDescriptionEditor: { editorId: "contest-problem-description-editor", @@ -135,38 +135,20 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", }); else { var vm = avalon.vmodels.editProblem; - title = ""; - description = ""; - timeLimit = 1000; - memoryLimit = 128; - samples = []; - hint = ""; - sortIndex = ""; - visible = true; - inputDescription = ""; - outputDescription = ""; - testCaseId = ""; - testCaseList = []; - uploadSuccess = false; + vm.title = ""; + vm.description = ""; + vm.timeLimit = 1000; + vm.memoryLimit = 128; + vm.samples = []; + vm.hint = ""; + vm.sortIndex = ""; + vm.visible = true; + vm.inputDescription = ""; + vm.outputDescription = ""; + vm.testCaseId = ""; + vm.testCaseList = []; } - var testCaseUploader = uploader("#testCaseFile", "/api/admin/test_case_upload/", function (file, response) { - if (response.code) - bsAlert(response.data); - else { - vm.testCaseId = response.data.test_case_id; - vm.testCaseList = []; - for (var key in response.data.file_list) { - vm.testCaseList.push({ - input: response.data.file_list[key].input_name, - output: response.data.file_list[key].output_name - }) - } - vm.uploadSuccess = true; - bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据"); - } - }); - if (avalon.vmodels.admin.contestProblemStatus == "edit") { $.ajax({ url: "/api/admin/contest_problem/?contest_problem_id=" + avalon.vmodels.admin.problemId, @@ -189,7 +171,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", vm.inputDescription = problem.input_description; vm.outputDescription = problem.output_description; vm.score = problem.score; - vm.testCaseId = problem.test_case_id; + avalon.vmodels.testCaseUploader.setTestCase(problem.test_case_id); vm.samples = []; for (var i = 0; i < problem.samples.length; i++) { vm.samples.push({ @@ -199,26 +181,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", }) } avalon.vmodels.contestProblemHintEditor.content = problem.hint; - $.ajax({ - url: "/api/admin/test_case_upload/?test_case_id=" + vm.testCaseId, - method: "get", - dataType: "json", - success: function (response) { - if (response.code) { - bsAlert(response.data); - } - else { - vm.testCaseList = []; - for (var key in response.data.file_list) { - vm.testCaseList.push({ - input: response.data.file_list[key].input_name, - output: response.data.file_list[key].output_name - }) - } - vm.uploadSuccess = true; - } - } - }) } } });