diff --git a/static/src/js/app/admin/contest/add_contest.js b/static/src/js/app/admin/contest/add_contest.js
index dfa8d603..f15d50aa 100644
--- a/static/src/js/app/admin/contest/add_contest.js
+++ b/static/src/js/app/admin/contest/add_contest.js
@@ -1,6 +1,8 @@
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker",
"validator"],
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
+
+
avalon.vmodels.add_contest = null;
$("#add-contest-form").validator().on('submit', function (e) {
if (!e.isDefaultPrevented()){
@@ -12,12 +14,15 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
contest_type: 0,
show_rank: vm.showRank,
show_user_submission: vm.showSubmission,
- //password: vm.password,
start_time: vm.startTime,
end_time: vm.endTime,
- visible: true
+ visible: false
};
- if (vm.choseGroupList[0].id == 0) //everyone | public contest
+ if (vm.choseGroupsList.length == 0) {
+ bsAlert("你没有选择参赛用户!");
+ return false;
+ }
+ if (vm.choseGroupsList[0].id == 0) //everyone | public contest
if (vm.password == "")
ajaxData.contest_type = 1;
else{
@@ -25,13 +30,12 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
}
else { // Add groups info
ajaxData.groups = [];
- for (var i = 0; vm.choseGroupList[i]; i++)
- ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
+ for (var i = 0; vm.choseGroupsList[i]; i++)
+ ajaxData.groups.push(parseInt(vm.choseGroupsList[i].id))
}
-
console.log(ajaxData);
- $.ajax({
+ $.ajax({ // Add contest
beforeSend: csrfTokenHeader,
url: "/api/admin/contest/",
dataType: "json",
@@ -41,7 +45,8 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
contentType: "application/json",
success: function (data) {
if (!data.code) {
- bsAlert("添加成功!");
+ bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)");
+ location.hash = "#contest/contest_list";
console.log(data);
}
else {
@@ -56,8 +61,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
});
editor("#editor");
- editor("#problemDescriptionEditor");
- editor("#problemHintEditor");
var vm = avalon.define({
$id: "add_contest",
@@ -69,151 +72,71 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
mode: "",
showRank: false,
showSubmission: false,
- problems: [],
- editingProblemId: 0,
- editSamples: [],
- editTestCaseList: [],
group: "-1",
groupList: [],
- choseGroupList: [],
- showProblemEditArea: function (problemIndex) {
- if (vm.editingProblemId == problemIndex){
- vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
- vm.editingProblemId = 0;
- }
- else {
- if (vm.editingProblemId)
- {
- vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
- vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
- }
- vm.editingProblemId = problemIndex;
- vm.editSamples = [];
- vm.editSamples = vm.problems[vm.editingProblemId-1].samples;
- vm.editTestCaseList = [];
- vm.editTestCaseList = vm.problems[vm.editingProblemId-1].testCaseList;
- }
- },
+ choseGroupsList: [],
passwordUsable: false,
- add_problem: function () {
- var problem = {
- title: "",
- timeLimit: 1000,
- memoryLimit: 256,
- description: "",
- samples: [],
- visible: true,
- test_case_id: "",
- testCaseList: [],
- hint: "",
- score: 0,
- uploadSuccess: false,
- };
- vm.problems.push(problem);
- vm.showProblemEditArea(vm.problems.length);
- },
- del_problem: function (problemIndex) {
- if (confirm("你确定要删除么?")) {
- vm.editingProblemId = 0;
- vm.problems.remove(vm.problems[problemIndex-1]);
- }
- },
- hidden: function () {
- vm.problems[vm.editingProblemId-1].samples = editSamples;
- vm.problems[vm.editingProblemId-1].testCaseList = editTestCaseList;
- vm.editingProblemId = 0;
- },
- toggle: function (item) {
- item.visible = !item.visible;
- },
- add_sample: function () {
- vm.editSamples.push({visible: true, input: "", output: ""});
- },
- del_sample: function (sample) {
- if (confirm("你确定要删除么?")) {
- editSamples.remove(sample);
- }
- },
- getBtnContent: function (item) {
- if (item.visible)
- return "折叠";
- return "展开";
- },
addGroup: function() {
if (vm.group == -1) return;
if (vm.groupList[vm.group].id == 0){
vm.passwordUsable = true;
- vm.choseGroupList = [];
+ vm.choseGroupsList = [];
for (var key in vm.groupList){
vm.groupList[key].chose = true;
}
}
vm.groupList[vm.group]. chose = true;
- vm.choseGroupList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
+ vm.choseGroupsList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
+ vm.group = -1;
},
- unchose: function(groupIndex){
- if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){
+ removeGroup: function(groupIndex){
+ if (vm.groupList[vm.choseGroupsList[groupIndex].index].id == 0){
vm.passwordUsable = false;
for (key in vm.groupList){
vm.groupList[key].chose = false;
}
}
- vm.groupList[vm.choseGroupList[groupIndex].index].chose = false;
- vm.choseGroupList.remove(vm.choseGroupList[groupIndex]);
+ vm.groupList[vm.choseGroupsList[groupIndex].index].chose = false;
+ vm.choseGroupsList.remove(vm.choseGroupsList[groupIndex]);
}
});
- var isSuperAdmin = true;
- $.ajax({ //用于获取该用户创建的所有小组的ajax请求
- beforeSend: csrfTokenHeader,
- url: "/api/admin/group/?my_group=true",
- dataType: "json",
- method: "get",
- contentType: "application/json",
- success: function (data) {
- if (!data.code) {
- if (isSuperAdmin)
- vm.groupList.push({id:0, name:"所有人", chose: false});
- for (var key in data.data) {
- data.data[key].chose = false;
- vm.groupList.push(data.data[key]);
- }
- }
- else {
- bsAlert(data.data);
- console.log(data);
- }
- }
- });
+ $.ajax({ // Get current user type
+ url: "/api/user/",
+ method: "get",
+ dataType: "json",
+ success: function (data) {
+ if (!data.code) {
+ if (data.data.admin_type == 2) { // Is super user
+ vm.isGlobal = true;
+ vm.groupList.push({id:0,name:"所有人",chose:false});
+ }
+ $.ajax({ // Get the group list of current user
+ beforeSend: csrfTokenHeader,
+ url: "/api/admin/group/",
+ method: "get",
+ dataType: "json",
+ success: function (data) {
+ if (!data.code) {
+ if (!data.data.length) {
+ bsAlert("您的用户权限只能创建组内比赛,但是您还没有创建过小组");
+ return;
+ }
+ for (var i = 0; i < data.data.length; i++) {
+ var item = data.data[i];
+ item["chose"] = false;
+ vm.groupList.push(item);
+ }
+ }
+ else {
+ bsAlert(data.data);
+ }
+ }
+ });
+ }
+ }
+ });
-
-
- uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) {
- if (respond.code)
- bsAlert(respond.data);
- else {
- vm.problems[vm.editingProblemId-1].test_case_id = respond.data.test_case_id;
- vm.problems[vm.editingProblemId-1].uploadSuccess = true;
- vm.editTestCaseList = [];
- for (var i = 0; i < respond.data.file_list.input.length; i++) {
- vm.editTestCaseList.push({
- input: respond.data.file_list.input[i],
- output: respond.data.file_list.output[i]
- });
- }
- vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
- bsAlert("测试数据添加成功!共添加"+vm.editTestCaseList.length +"组测试数据");
- }
- },
- function(){
- if (vm.editingProblemId == 0)
- {
- bsAlert("你还未指定一道题目!");
- return false;
- }
- }
- );
-
avalon.scan();
$("#contest_start_time").datetimepicker({
diff --git a/template/admin/contest/add_contest.html b/template/admin/contest/add_contest.html
index 44ae98ac..de33f23a 100644
--- a/template/admin/contest/add_contest.html
+++ b/template/admin/contest/add_contest.html
@@ -6,8 +6,9 @@
@@ -17,51 +18,46 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
+
-
{{el.name}}
+
{{el.name}}
@@ -94,135 +90,12 @@
-
-
添加
-
-
- 编号 |
- 题目 |
- 测试数据 |
- |
-
-
- 题目{{ $index+1 }} |
- {{ el.title }} |
- {{ el.testCaseList.length }}组 |
-
- 编辑
- 删除
- |
-
-
-
-
-
-
-
-
-
-
题目{{editingProblemId}}
-
隐藏
-
删除
-
-
-
-
-
-
- 请填写题目描述
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 编号 |
- 输入文件名 |
- 输出文件名 |
-
-
- {{$index}} |
- {{ el.input }} |
- {{ el.output }} |
-
-
-
-
-
-
-
-
-
-
-
请将所有测试用例打包在一个文件中上传,所有文件要在压缩包的根目录,且输入输出文件名要以从1开始连续数字标识要对应例如:
- 1.in 1.out 2.in 2.out
-
-