From 2411968962096577dcde31b3208712ef19574a39 Mon Sep 17 00:00:00 2001 From: esp Date: Sun, 23 Aug 2015 17:44:52 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=E4=BF=AE=E6=94=B9=E6=AF=94?= =?UTF-8?q?=E8=B5=9B=E5=88=97=E8=A1=A8=E9=A1=B5=E9=9D=A2,=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E7=BC=96=E8=BE=91=E6=AF=94=E8=B5=9B,?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=AF=94=E8=B5=9B=E9=A2=98=E7=9B=AE[CI=20SKI?= =?UTF-8?q?P]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/js/app/admin/contest/contest_list.js | 363 ++++++++++++------ template/admin/contest/contest_list.html | 265 +++++++------ 2 files changed, 380 insertions(+), 248 deletions(-) diff --git a/static/src/js/app/admin/contest/contest_list.js b/static/src/js/app/admin/contest/contest_list.js index 0be9cfb..b6efbd7 100644 --- a/static/src/js/app/admin/contest/contest_list.js +++ b/static/src/js/app/admin/contest/contest_list.js @@ -1,93 +1,220 @@ -require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker"], function ($, avalon, csrfTokenHeader, bsAlert, editor) { +require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker", "validator"], function ($, avalon, csrfTokenHeader, bsAlert, editor) { avalon.ready(function () { - if(avalon.vmodels.contestList){ - vm = avalon.vmodels.contestList; - vm.editingContest = 0; - } - else { - var vm = avalon.define({ - $id: "contestList", - contestList: [], - previousPage: 0, - nextPage: 0, - page: 1, - totalPage: 1, - group: "-1", - groupList: [], - keyword: "", - editingContestId: 0, - editTitle: "", - editProblemList: [], - editPassword: "", - editStartTime: "", - editEndTime: "", - editMode: "", - editShowRank: false, - editShowSubmission: false, - editProblemList: [], - editingProblemId: 0, - editSamples: [], - editTestCaseList: [], - editChoseGroupList: [], - modelNameList: ["ACM", "AC总数", "分数"], - contestTypeNameList: ["小组赛", "公开赛", "有密码保护的公开赛"], - getNext: function () { - if (!vm.nextPage) - return; - getPageData(vm.page + 1); - }, - getPrevious: function () { - if (!vm.previousPage) - return; - getPageData(vm.page - 1); - }, - getBtnClass: function (btn) { - if (btn == "next") { - return vm.nextPage ? "btn btn-primary" : "btn btn-primary disabled"; - } - else { - return vm.previousPage ? "btn btn-primary" : "btn btn-primary disabled"; - } - }, - getPage: function (page_index) { - getPageData(page_index); - }, - showEditContestArea: function (contestId) { - if (contestId == vm.editingContestId) - vm.editingContestId = 0; - else { - vm.editingContestId = contestId; - vm.editTitle = vm.contestList[contestId-1].title; - vm.editEndTime = vm.contestList[contestId-1].end_time; - vm.editPassword = vm.contestList[contestId-1].password; - vm.editStartTime = vm.contestList[contestId-1].start_time; - vm.editMode = vm.contestList[contestId-1].mode; - vm.editChoseGroupList = []; - //= vm.contestList[contestId-1].group;// - /*for (var key in vm.contestList[contestId-1].groups){ - var id = parseInt(vm.contestList[contestId-1].groups); - for () - vm.editChoseGroupList.push({ - name:vm.groupList[vm.group].name, - index:index, - id:parseInt(vm.contestList[contestId-1].groups) - }); - }*/ - vm.editShowRank = vm.contestList[contestId-1].show_rank; - vm.editShowSubmission = vm.contestList[contestId-1].show_user_submission; - //vm.editProblemList = vm.contestList[contestId-1].problems - editor("#editor").setValue(vm.contestList[contestId-1].description); - vm.editingProblemList = vm.contestList[contestId-1].problemList; - } - } - }); - getPageData(1); - } + avalon.vmodels.contestList=null; + + $("#edit-contest-form").validator().on('submit', function (e) { + if (!e.isDefaultPrevented()){ + e.preventDefault(); + var ajaxData = { + id: vm.contestList[vm.editingContestId-1].id, + title: vm.editTitle, + description: vm.editDescription, + mode: vm.editMode, + contest_type: 0, + show_rank: vm.editShowRank, + show_user_submission: vm.editShowSubmission, + start_time: vm.editStartTime, + end_time: vm.editEndTime, + visible: vm.editVisible + }; + if (vm.choseGroupList.length == 0) { + bsAlert("你没有选择参赛用户!"); + return false; + } + if (vm.choseGroupList[0].id == 0) //everyone | public contest + if (vm.password == "") + ajaxData.contest_type = 1; + else{ + ajaxData.password = vm.password; + } + else { // Add groups info + ajaxData.groups = []; + for (var i = 0; vm.choseGroupList[i]; i++) + ajaxData.groups.push(parseInt(vm.choseGroupList[i].id)) + } + + console.log(ajaxData); + $.ajax({ // Add contest + beforeSend: csrfTokenHeader, + url: "/api/admin/contest/", + dataType: "json", + contentType: "application/json", + data: JSON.stringify(ajaxData), + method: "put", + contentType: "application/json", + success: function (data) { + if (!data.code) { + bsAlert("修改成功!"); + console.log(data); + vm.getPage(1); + } + else { + bsAlert(data.data); + console.log(data); + } + } + }); + console.log(JSON.stringify(ajaxData)); + } + return false; + }); + + var vm = avalon.define({ + $id: "contestList", + contestList: [], + previousPage: 0, + nextPage: 0, + page: 1, + totalPage: 1, + group: "-1", + groupList: [], + choseGroupList: [], + passwordUsable: false, + keyword: "", + editingContestId: 0, + editTitle: "", + editDescription: "", + editProblemList: [], + editPassword: "", + editStartTime: "", + editEndTime: "", + editMode: "", + editShowRank: false, + editShowSubmission: false, + editProblemList: [], + editVisible: false, + editChoseGroupList: [], + editingProblemContestIndex: 0, + getNext: function () { + if (!vm.nextPage) + return; + getPageData(vm.page + 1); + }, + getPrevious: function () { + if (!vm.previousPage) + return; + getPageData(vm.page - 1); + }, + getBtnClass: function (btn) { + if (btn == "next") { + return vm.nextPage ? "btn btn-primary" : "btn btn-primary disabled"; + } + else { + return vm.previousPage ? "btn btn-primary" : "btn btn-primary disabled"; + } + }, + getPage: function (page_index) { + getPageData(page_index); + }, + showEditContestArea: function (contestId) { + if (contestId == vm.editingContestId) + vm.editingContestId = 0; + else { + vm.editingContestId = contestId; + vm.editTitle = vm.contestList[contestId-1].title; + vm.editPassword = vm.contestList[contestId-1].password; + vm.editStartTime = vm.contestList[contestId-1].start_time.substring(0,16).replace("T"," "); + vm.editEndTime = vm.contestList[contestId-1].end_time.substring(0,16).replace("T"," "); + vm.editMode = vm.contestList[contestId-1].mode; + editVisible = vm.contestList[contestId-1].visible; + vm.editChoseGroupList = []; + for (var i = 0; i < vm.contestList[contestId-1].groups.length; i++){ + var id = parseInt(vm.contestList[contestId-1].groups[i]); + var index = 0; + for (; vm.groupList[index]; index++) { + if (vm.groupList[index].id == id) + break; + } + vm.groupList[index].chose = true; + vm.choseGroupList.push({ + name:vm.groupList[i].name, + index:index, + id:id + }); + } + vm.editShowRank = vm.contestList[contestId-1].show_rank; + vm.editShowSubmission = vm.contestList[contestId-1].show_user_submission; + editor("#editor").setValue(vm.contestList[contestId-1].description); + vm.editingProblemContestIndex = 0; + } + }, + showEditProblemArea: function(contestId) { + if (vm.editingProblemContestIndex == contestId) { + vm.editingProblemContestIndex = 0; + return; + } + if (vm.editingContestId&&!confirm("如果继续将丢失为保存的信息,是否继续?")){ + return; + } + $.ajax({ // Get the problem list of current contest + beforeSend: csrfTokenHeader, + url: "/api/admin/contest_problem/?contest_id=" + vm.contestList[contestId-1].id, + method: "get", + dataType: "json", + success: function (data) { + if (!data.code) { + vm.editProblemList = data.data; + } + else { + bsAlert(data.data); + } + } + }); + vm.editingContestId = 0; + vm.editingProblemContestIndex = contestId; + }, + addGroup: function() { + if (vm.group == -1) return; + if (vm.groupList[vm.group].id == 0){ + vm.passwordUsable = true; + vm.choseGroupList = []; + 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.group = -1; + }, + removeGroup: function(groupIndex){ + if (vm.groupList[vm.choseGroupList[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]); + }, + add_problem: function () { + vm.$fire("up!showContestProblemPage", 0, vm.contestList[vm.editingProblemContestIndex-1].id); + }, + showProblemEditor: function(el) { + console.log(el); + vm.$fire("up!showContestProblemPage", el.id, vm.contestList[vm.editingProblemContestIndex-1].id); + } + }); + getPageData(1); + vm.editingContestId = 0; + vm.editingProblemContestIndex = 0; + + //init time picker + $("#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" + }); function getPageData(page) { - var url = "/api/admin/contest/?paging=true&page=" + page + "&page_size=10"; if (vm.keyword != "") url += "&keyword=" + vm.keyword; @@ -109,52 +236,44 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker"] } }); } - - var isSuperAdmin = true; - - $.ajax({ //用于获取该用户创建的所有小组的ajax请求 - - url: "/api/admin/group/", + // Get group list + $.ajax({ // Get current user type + url: "/api/user/", method: "get", dataType: "json", success: function (data) { if (!data.code) { - if (!data.data.length) { - bsAlert("您的用户权限只能创建组内比赛,但是您还没有创建过小组"); - return; + if (data.data.admin_type == 2) { // Is super user + vm.isGlobal = true; + vm.groupList.push({id:0,name:"所有人",chose:false}); } - for (var i = 0; i < data.data.length; i++) { - var item = data.data[i]; - item["chose"] = false; - vm.groupList.push(item); + $.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); + } } - } - else { - bsAlert(data.data); - } + }); } + } + }); - beforeSend: csrfTokenHeader, - url: url, - 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); - } - } - }); }); avalon.scan(); }); diff --git a/template/admin/contest/contest_list.html b/template/admin/contest/contest_list.html index ab878ae..76daa48 100644 --- a/template/admin/contest/contest_list.html +++ b/template/admin/contest/contest_list.html @@ -15,22 +15,23 @@ ID 比赛 - 比赛类型 公开排名 - 开始时间 - 结束时间 + 可见 创建时间 创建者 + - + {{ el.id }} {{ el.title }} - {{ contestTypeNameList[el.contest_type] }} {{ el.show_rank }} - {{ el.start_time|date("yyyy-MM-dd HH:mm:ss")}} - {{ el.end_time|date("yyyy-MM-dd HH:mm:ss")}} + {{ el.visible }} {{ el.create_time|date("yyyy-MM-dd HH:mm:ss")}} {{ el.created_by.username }} + + 编辑 + 编辑问题 +
@@ -39,130 +40,142 @@
-
- -
-
-
- +
+
+ +
+
+
+ -
+
+
-
-
- -
-
-
- -
- 请填写比赛描述 +
+
-
-
- -
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
- -
-
- -
-
-
- -
-
-
-
- -
-
-
-
{{el.name}}
-
-
- -
-
- -
-
- -
-
-
- - - -
-
-
-
- -
-
-
-
- -
-
-
- - 添加 - - - - - - - - - - - - - -
编号题目测试数据
题目{{ $index+1 }}{{ el.title }}{{ el.testCaseList.length }}组 - 编辑 - 删除 -
+
+
+ -
+
+ 请填写比赛描述 +
+
+
+ + +
+ + +
+
+
+
+ + +
+ + +
+
+
+
+ + +
+ +
+
+
+ + +
+
+
{{el.name}}
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ + + +
+
+
+
+ +
+
+ + +
+ +
+
+
+ + +
+ +
+
+
+ +
+
+
+ + 添加 + + + + + + + + + + + + + +
编号题目创建时间
{{ el.sort_index }}{{ el.title }}{{ el.create_time|date("yyyy-MM-dd HH:mm:ss") }} + 编辑 +
+ +
+