统一创建比赛,编辑比赛的时候小组可见的交互逻辑和界面[CI SKIP]

This commit is contained in:
sxw@401
2015-09-12 11:33:47 +08:00
parent 74f122b472
commit d06096b19b
4 changed files with 315 additions and 331 deletions

View File

@@ -16,25 +16,32 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
end_time: vm.endTime, end_time: vm.endTime,
visible: false visible: false
}; };
if (vm.choseGroupList.length == 0) {
bsAlert("你没有选择参赛用户!"); var selectedGroups = [];
return false; if (!vm.isGlobal) {
for (var i = 0; i < vm.allGroups.length; i++) {
if (vm.allGroups[i].isSelected) {
selectedGroups.push(vm.allGroups[i].id);
} }
if (vm.choseGroupList[0].id == 0) { //everyone | public contest }
ajaxData.groups = selectedGroups;
}
else {
if (vm.password) { if (vm.password) {
ajaxData.password = vm.password; ajaxData.password = vm.password;
ajaxData.contest_type = 2; ajaxData.contest_type = 2;
} }
else{ else
ajaxData.contest_type = 1; ajaxData.contest_type = 1;
} }
if (!vm.isGlobal && !selectedGroups.length) {
bsAlert("你没有选择参赛用户!");
return false;
} }
else { // Add groups info if (vm.editDescription == "") {
ajaxData.groups = []; bsAlert("比赛描述不能为空!");
for (var i = 0; vm.choseGroupList[i]; i++) return false;
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
} }
$.ajax({ // Add contest $.ajax({ // Add contest
beforeSend: csrfTokenHeader, beforeSend: csrfTokenHeader,
url: "/api/admin/contest/", url: "/api/admin/contest/",
@@ -53,11 +60,10 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
vm.mode = ""; vm.mode = "";
vm.hideRank = 0; vm.hideRank = 0;
vm.showSubmission = false; vm.showSubmission = false;
vm.group = "-1";
vm.groupList = [];
vm.choseGroupList = [];
vm.passwordUsable = false;
location.hash = "#contest/contest_list"; location.hash = "#contest/contest_list";
vm.isGlobal = true;
vm.allGroups = [];
vm.showGlobalViewRadio = true;
} }
else { else {
bsAlert(data.data); bsAlert(data.data);
@@ -82,59 +88,39 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
mode: "", mode: "",
hideRank: 0, hideRank: 0,
showSubmission: false, showSubmission: false,
group: "-1", isGlobal: true,
groupList: [], allGroups: [],
choseGroupList: [], showGlobalViewRadio: true
passwordUsable: false,
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]);
}
}); });
$.ajax({ // Get current user type $.ajax({
url: "/api/user/", url: "/api/user/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (data.data.admin_type == 2) { // Is super user var admin_type = data.data.admin_type;
vm.isGlobal = true; if (data.data.admin_type == 1) {
vm.groupList.push({id:0,name:"所有人",chose:false}); vm.isGlobal = false;
vm.showGlobalViewRadio = false;
} }
$.ajax({ // Get the group list of current user }
beforeSend: csrfTokenHeader, $.ajax({
url: "/api/admin/group/", url: "/api/admin/group/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (!data.data.length) { if (!data.data.length) {
if (admin_type != 2)
bsAlert("您的用户权限只能创建小组内比赛,但是您还没有创建过小组");
return; return;
} }
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.data.length; i++) {
var item = data.data[i]; var item = data.data[i];
item["chose"] = false; item["isSelected"] = false;
vm.groupList.push(item); vm.allGroups.push(item);
} }
} }
else { else {
@@ -143,7 +129,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
} }
}); });
} }
}
}); });
avalon.scan(); avalon.scan();

View File

@@ -17,7 +17,25 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
end_time: vm.editEndTime, end_time: vm.editEndTime,
visible: vm.editVisible visible: vm.editVisible
}; };
if (vm.choseGroupList.length == 0) {
var selectedGroups = [];
if (!vm.isGlobal) {
for (var i = 0; i < vm.allGroups.length; i++) {
if (vm.allGroups[i].isSelected) {
selectedGroups.push(vm.allGroups[i].id);
}
}
ajaxData.groups = selectedGroups;
}
else {
if (vm.password) {
ajaxData.password = vm.editPassword;
ajaxData.contest_type = 2;
}
else
ajaxData.contest_type = 1;
}
if (!vm.isGlobal && !selectedGroups.length) {
bsAlert("你没有选择参赛用户!"); bsAlert("你没有选择参赛用户!");
return false; return false;
} }
@@ -25,22 +43,8 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
bsAlert("比赛描述不能为空!"); bsAlert("比赛描述不能为空!");
return false; return false;
} }
if (vm.choseGroupList[0].id == 0) { //everyone | public contest
if (vm.editPassword) {
ajaxData.password = vm.editPassword;
ajaxData.contest_type = 2;
}
else{
ajaxData.contest_type = 1;
}
}
else { // Add groups info
ajaxData.groups = [];
for (var i = 0; vm.choseGroupList[i]; i++)
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
}
$.ajax({ // Add contest $.ajax({ // modify contest info
beforeSend: csrfTokenHeader, beforeSend: csrfTokenHeader,
url: "/api/admin/contest/", url: "/api/admin/contest/",
dataType: "json", dataType: "json",
@@ -71,10 +75,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.nextPage = 0; vm.nextPage = 0;
vm.page = 1; vm.page = 1;
vm.totalPage = 1; vm.totalPage = 1;
vm.group= "-1";
vm.groupList= [];
vm.choseGroupList= [];
vm.passwordUsable= false;
vm.keyword = ""; vm.keyword = "";
vm.editingContestId = 0; vm.editingContestId = 0;
vm.editTitle = ""; vm.editTitle = "";
@@ -86,9 +86,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.editMode = ""; vm.editMode = "";
vm.editHideRank = 0; vm.editHideRank = 0;
vm.editShowSubmission = false; vm.editShowSubmission = false;
vm.editProblemList= [];
vm.editVisible = false; vm.editVisible = false;
vm.editChoseGroupList= [];
vm.editingProblemContestIndex = 0; vm.editingProblemContestIndex = 0;
} }
else { else {
@@ -100,10 +98,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
page: 1, page: 1,
totalPage: 1, totalPage: 1,
showVisibleOnly: false, showVisibleOnly: false,
group: "-1",
groupList: [],
choseGroupList: [],
passwordUsable: false,
keyword: "", keyword: "",
editingContestId: 0, editingContestId: 0,
editTitle: "", editTitle: "",
@@ -115,10 +109,12 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
editMode: "", editMode: "",
editHideRank: false, editHideRank: false,
editShowSubmission: false, editShowSubmission: false,
editProblemList: [],
editVisible: false, editVisible: false,
editChoseGroupList: [],
editingProblemContestIndex: 0, editingProblemContestIndex: 0,
isGlobal: true,
allGroups: [],
showGlobalViewRadio: true,
getNext: function () { getNext: function () {
if (!vm.nextPage) if (!vm.nextPage)
return; return;
@@ -154,29 +150,23 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.editMode = vm.contestList[contestId - 1].mode; vm.editMode = vm.contestList[contestId - 1].mode;
vm.editVisible = vm.contestList[contestId - 1].visible; vm.editVisible = vm.contestList[contestId - 1].visible;
if (vm.contestList[contestId - 1].contest_type == 0) { //contest type == 0, contest in group if (vm.contestList[contestId - 1].contest_type == 0) { //contest type == 0, contest in group
//Clear the choseGroupList vm.isGlobal = false;
while (vm.choseGroupList.length) { for (var i = 0; i < vm.allGroups.length; i++) {
vm.removeGroup(0); vm.allGroups[i].isSelected = false;
} }
for (var i = 0; i < vm.contestList[contestId - 1].groups.length; i++) { for (var i = 0; i < vm.contestList[contestId - 1].groups.length; i++) {
var id = parseInt(vm.contestList[contestId - 1].groups[i]); var id = parseInt(vm.contestList[contestId - 1].groups[i]);
var index = 0;
for (; vm.groupList[index]; index++) { for (var index = 0; vm.allGroups[index]; index++) {
if (vm.groupList[index].id == id) if (vm.allGroups[index].id == id) {
vm.allGroups[index].isSelected = true;
break; break;
} }
vm.groupList[index].chose = true; }
vm.choseGroupList.push({
name:vm.groupList[index].name,
index:index,
id:id
});
} }
} }
else { else {
vm.group = "0"; vm.isGlobal = true;
vm.addGroup()//vm.editChoseGroupList = [0]; id 0 is for the group of everyone~
} }
vm.editHideRank = vm.contestList[contestId - 1].Hide_rank; vm.editHideRank = vm.contestList[contestId - 1].Hide_rank;
vm.editShowSubmission = vm.contestList[contestId - 1].show_user_submission; vm.editShowSubmission = vm.contestList[contestId - 1].show_user_submission;
@@ -210,30 +200,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
vm.editingProblemContestIndex = contestId; vm.editingProblemContestIndex = contestId;
vm.editMode = vm.contestList[contestId - 1].mode; vm.editMode = vm.contestList[contestId - 1].mode;
}, },
addGroup: function() {
if (vm.group == -1) return;
if (vm.groupList[vm.group].id == 0){
vm.passwordUsable = true;
vm.choseGroupList = [];
for (var i = 0; i < vm.groupList.length; i++) {
vm.groupList[i].chose = true;
}
}
vm.groupList[vm.group]. chose = true;
// index of the group is relative. It is related to user
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 (var i = 0; i < vm.groupList.length; i++) {
vm.groupList[i].chose = false;
}
}
vm.groupList[vm.choseGroupList[groupIndex].index].chose = false;
vm.choseGroupList.remove(vm.choseGroupList[groupIndex]);
},
addProblem: function () { addProblem: function () {
vm.$fire("up!showContestProblemPage", 0, vm.contestList[vm.editingProblemContestIndex - 1].id, vm.editMode); vm.$fire("up!showContestProblemPage", 0, vm.contestList[vm.editingProblemContestIndex - 1].id, vm.editMode);
}, },
@@ -293,31 +259,33 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
} }
// Get group list // Get group list
$.ajax({ // Get current user type $.ajax({
url: "/api/user/", url: "/api/user/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (data.data.admin_type == 2) { // Is super user var admin_type = data.data.admin_type;
vm.isGlobal = true; if (data.data.admin_type == 1) {
vm.groupList.push({id:0,name:"所有人",chose:false}); vm.isGlobal = false;
vm.showGlobalViewRadio = false;
} }
$.ajax({ // Get the group list of current user }
beforeSend: csrfTokenHeader, $.ajax({
url: "/api/admin/group/", url: "/api/admin/group/",
method: "get", method: "get",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
if (!data.data.length) { if (!data.data.length) {
//this user have no group can use if (admin_type != 2)
bsAlert("您的用户权限只能创建小组内比赛,但是您还没有创建过小组");
return; return;
} }
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.data.length; i++) {
var item = data.data[i]; var item = data.data[i];
item["chose"] = false; item["isSelected"] = false;
vm.groupList.push(item); vm.allGroups.push(item);
} }
} }
else { else {
@@ -326,7 +294,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
} }
}); });
} }
}
}); });
}); });

View File

@@ -45,22 +45,37 @@
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>允许参加的用户</label>
<div class="form-group"> <div class="form-group">
<select class="form-control" ms-duplex="group" ms-change="addGroup" value="-1"> <label>可见范围</label>
<option value="-1">请选择</option>
<option ms-repeat="groupList" ms-attr-value="$index" ms-visible="!el.chose">{{el.name}}</option> <div>
</select> <span ms-if="showGlobalViewRadio">
<label>
<small><input type="radio" value="true" name="isGlobal" ms-duplex-boolean="isGlobal">全局可见
</small>
</label>
</span>
<span>
<label>
<small><input type="radio" value="false" name="isGlobal" ms-duplex-boolean="isGlobal">小组内可见
</small>
</label>
</span>
</div>
</div> </div>
</div> </div>
<div class="col-md-6" ms-visible="passwordUsable"> <div class="col-md-6" ms-visible="isGlobal">
<label>密码保护</label> <label>密码保护</label>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="password"> <input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="password">
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="form-group col-md-12" ms-visible="!isGlobal">
<div ms-repeat="choseGroupList" class="group-tag" ms-click="removeGroup($index)">{{el.name}}</div> <!-- radio 的value 没有用 但是没有的话,表单验证会出错-->
<div ms-repeat="allGroups" class="col-md-4">
<input type="checkbox" value="group_id" ms-duplex-checked="el.isSelected">&nbsp;&nbsp;{{ el.name }}
</div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label>排名方式</label> <label>排名方式</label>

View File

@@ -88,29 +88,46 @@
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<label>封榜时间(结束前/min)</label> <label>封榜时间(结束前/min)</label>
<div class="form-group"> <div class="form-group">
<input class="form-control" ms-duplex="editHideRank" type="number" data-error="请填写封榜时间" required> <input class="form-control" ms-duplex="editHideRank" type="number" data-error="请填写封榜时间" required>
<div class="help-block with-errors"></div> <div class="help-block with-errors"></div>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>允许参加的用户</label>
<div class="form-group"> <div class="form-group">
<select class="form-control" ms-duplex="group" ms-change="addGroup" value="-1"> <label>可见范围</label>
<option value="-1">请选择</option>
<option ms-repeat="groupList" ms-attr-value="$index" ms-visible="!el.chose">{{el.name}}</option> <div>
</select> <span ms-if="showGlobalViewRadio">
<label>
<small><input type="radio" value="true" name="isGlobal" ms-duplex-boolean="isGlobal">全局可见
</small>
</label>
</span>
<span>
<label>
<small><input type="radio" value="false" name="isGlobal" ms-duplex-boolean="isGlobal">小组内可见
</small>
</label>
</span>
</div> </div>
</div> </div>
<div class="col-md-6" ms-visible="passwordUsable">
</div>
<div class="col-md-6" ms-visible="isGlobal">
<label>密码保护</label> <label>密码保护</label>
<input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="editPassword"> <input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="editPassword">
</div> </div>
<div class="col-md-12"> <div class="form-group col-md-12" ms-visible="!isGlobal">
<div ms-repeat="choseGroupList" class="group-tag" ms-click="removeGroup($index)">{{el.name}}</div> <!-- radio 的value 没有用 但是没有的话,表单验证会出错-->
<div ms-repeat="allGroups" class="col-md-4">
<input type="checkbox" value="group_id" ms-duplex-checked="el.isSelected">&nbsp;&nbsp;{{ el.name }}
</div> </div>
<div class="col-md-3"> </div>
<div class="col-md-7">
<label>排名方式</label> <label>排名方式</label>
<div class="form-group"> <div class="form-group">