From 9a8c15ab806e8e5d09f231cca497976070423ec6 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 2 Aug 2015 09:54:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20admin=20=E6=A8=A1=E5=9D=97=E5=8C=96?= =?UTF-8?q?=E6=8B=86=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/admin.js | 182 +----------------- static/src/js/app/admin/contest/contest.js | 181 +++++++++++++++++ static/src/js/app/oj.js | 2 - static/src/js/app/{ => oj}/account/login.js | 0 .../js/app/{ => oj}/problem/submit_code.js | 0 static/src/js/config.js | 7 +- 6 files changed, 186 insertions(+), 186 deletions(-) create mode 100644 static/src/js/app/admin/contest/contest.js rename static/src/js/app/{ => oj}/account/login.js (100%) rename static/src/js/app/{ => oj}/problem/submit_code.js (100%) diff --git a/static/src/js/app/admin.js b/static/src/js/app/admin.js index bc13d9d3..e7ececa8 100644 --- a/static/src/js/app/admin.js +++ b/static/src/js/app/admin.js @@ -1,181 +1 @@ -require(["jquery", "avalon", "editor", "uploader", "datetimepicker", - "validation" - ], - function ($, avalon, editor, uploader) { - $("#add-contest-form") - .formValidation({ - framework: "bootstrap", - fields: { - name: { - validators: { - notEmpty: { - message: "请填写比赛名称" - }, - stringLength: { - min: 1, - max: 30, - message: "名称不能超过30个字" - } - } - }, - 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: "请输入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(); - alert("1111"); - }); - - 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 editor1 = editor("#editor"); - - var vm = avalon.define({ - $id: "add_contest", - problems: [], - add_problem: function () { - var problem = {}; - var problem_id = make_id(); - problem["id"] = problem_id; - problem["samples"] = []; - problem["webuploader"] = {}; - problem["toggle_string"] = "折叠"; - vm.problems.push(problem); - uploader("#problem-" + problem_id + "-uploader"); - console.log(vm.problems); - $("#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_problem: function (problem) { - $("#" + "problem-" + problem.id + "-body").toggle(); - if (problem["toggle_string"] == "展开") { - problem["toggle_string"] = "折叠"; - } - else { - problem["toggle_string"] = "展开"; - } - }, - add_sample: function (problem) { - problem["samples"].push({"id": make_id(), "toggle_string": "折叠"}); - }, - del_sample: function (problem, sample) { - if (confirm("你确定要删除么?")) { - 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"] = "展开"; - } - } - }); - 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 +require(["contest"]); \ No newline at end of file diff --git a/static/src/js/app/admin/contest/contest.js b/static/src/js/app/admin/contest/contest.js new file mode 100644 index 00000000..75ba1850 --- /dev/null +++ b/static/src/js/app/admin/contest/contest.js @@ -0,0 +1,181 @@ +define("contest", ["jquery", "avalon", "editor", "uploader", "datetimepicker", + "validation" + ], + function ($, avalon, editor, uploader) { + $("#add-contest-form") + .formValidation({ + framework: "bootstrap", + fields: { + name: { + validators: { + notEmpty: { + message: "请填写比赛名称" + }, + stringLength: { + min: 1, + max: 30, + message: "名称不能超过30个字" + } + } + }, + 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: "请输入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(); + alert("1111"); + }); + + 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 editor1 = editor("#editor"); + + var vm = avalon.define({ + $id: "add_contest", + problems: [], + add_problem: function () { + var problem = {}; + var problem_id = make_id(); + problem["id"] = problem_id; + problem["samples"] = []; + problem["webuploader"] = {}; + problem["toggle_string"] = "折叠"; + vm.problems.push(problem); + uploader("#problem-" + problem_id + "-uploader"); + console.log(vm.problems); + $("#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_problem: function (problem) { + $("#" + "problem-" + problem.id + "-body").toggle(); + if (problem["toggle_string"] == "展开") { + problem["toggle_string"] = "折叠"; + } + else { + problem["toggle_string"] = "展开"; + } + }, + add_sample: function (problem) { + problem["samples"].push({"id": make_id(), "toggle_string": "折叠"}); + }, + del_sample: function (problem, sample) { + if (confirm("你确定要删除么?")) { + 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"] = "展开"; + } + } + }); + 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/static/src/js/app/oj.js b/static/src/js/app/oj.js index 49fcafc2..c3162bf2 100644 --- a/static/src/js/app/oj.js +++ b/static/src/js/app/oj.js @@ -1,3 +1 @@ - - require(["bootstrap", "login", "submit_code"]); diff --git a/static/src/js/app/account/login.js b/static/src/js/app/oj/account/login.js similarity index 100% rename from static/src/js/app/account/login.js rename to static/src/js/app/oj/account/login.js diff --git a/static/src/js/app/problem/submit_code.js b/static/src/js/app/oj/problem/submit_code.js similarity index 100% rename from static/src/js/app/problem/submit_code.js rename to static/src/js/app/oj/problem/submit_code.js diff --git a/static/src/js/config.js b/static/src/js/config.js index 487d4ba1..b79d026c 100644 --- a/static/src/js/config.js +++ b/static/src/js/config.js @@ -11,10 +11,11 @@ var require = { uploader: "utils/uploader", validation: "utils/validation", code_mirror: "utils/code_mirror", - login: "app/account/login", - oj: "app/oj", + login: "app/oj/account/login", + oj: "app/oj/oj", "bs_alert": "utils/bs_alert", - submit_code: "app/problem/submit_code", + submit_code: "app/oj/problem/submit_code", + contest: "app/admin/contest/contest", //formValidation 不要在代码中单独使用,而是使用和修改utils/validation base: "lib/formValidation/base",