From 71f3aaf822485f8630faf3e322d257f9eccf6009 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Mon, 10 Aug 2015 22:57:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=20js=20=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=20bug=20=E4=BF=AE=E5=A4=8D=EF=BC=8C=E8=BF=98=E6=B2=A1?= =?UTF-8?q?=E6=94=B9=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/css/admin.css | 1 + .../src/js/app/admin/problem/add_problem.js | 36 ++-- template/admin/problem/add_problem.html | 180 +++++++++--------- template/oj/problem/problem.html | 39 ++-- 4 files changed, 125 insertions(+), 131 deletions(-) diff --git a/static/src/css/admin.css b/static/src/css/admin.css index c8daf65..b9fc4cb 100644 --- a/static/src/css/admin.css +++ b/static/src/css/admin.css @@ -5,6 +5,7 @@ @import url("simditor/simditor.css"); @import url("webuploader/webuploader.css"); @import url("datetime_picker/bootstrap-datetimepicker.css"); +@import url("tagEditor/jquery.tag-editor.css"); #loading-gif{ width: 40px; diff --git a/static/src/js/app/admin/problem/add_problem.js b/static/src/js/app/admin/problem/add_problem.js index 8213ad5..8de48cd 100644 --- a/static/src/js/app/admin/problem/add_problem.js +++ b/static/src/js/app/admin/problem/add_problem.js @@ -64,18 +64,15 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito }) .on("success.form.fv", function (e) { e.preventDefault(); - if (vm.test_case_id == '') - { + if (vm.test_case_id == '') { bs_alert("你还没有上传测试数据!"); return; } - if (vm.description == '') - { + if (vm.description == '') { bs_alert("题目描述不能为空!"); return; } - if (vm.hint == '') - { + if (vm.hint == '') { bs_alert("提示不能为空!"); return; } @@ -88,33 +85,30 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito test_case_id: vm.test_case_id, hint: vm.hint, source: vm.source, - tags: [], + tags: $("#tags").tagEditor("getTags")[0].tags, difficulty: vm.difficulty }; - if (vm.samples.length == 0) - { + if (vm.samples.length == 0) { bs_alert("请至少添加一组样例!"); return; } - var tags = $("#tags").tagEditor("getTags")[0].tags; - if (tags.length == 0) - { + + if (tags.length == 0) { bs_alert("请至少添加一个标签,这将有利于用户发现你的题目!"); return; } - for (key in vm.samples.length) { - ajaxData.samples.push({input: vm.samples[key].input, output: vm.samples[key].output}); + + for (var i = 0; i < vm.samples.$model.length; i++) { + ajaxData.samples.push({input: vm.samples.$model[i].input, output: vm.samples.$model[i].output}); } - for (key in tags) { - ajaxData.tags.push(tags[key].tag); - } - console.log(ajaxData); + $.ajax({ beforeSend: csrfHeader, url: "/api/admin/problem/", dataType: "json", - data:ajaxData, + data: JSON.stringify(ajaxData), method: "post", + contentType: "application/json", success: function (data) { if (!data.code) { bs_alert("successful!"); @@ -188,8 +182,8 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito if (!data.code) { tagList = data.data; completeList = []; - for (key in tagList) { - completeList.push(tagList[key].name); + for (var i = 0; i < tagList.length; i++) { + completeList.push(tagList[i].name); } $("#tags").tagEditor({ autocomplete: { diff --git a/template/admin/problem/add_problem.html b/template/admin/problem/add_problem.html index d039302..0b952c9 100644 --- a/template/admin/problem/add_problem.html +++ b/template/admin/problem/add_problem.html @@ -1,103 +1,113 @@