admin 右侧导航栏修改为 js 生成,根据用户身份权限变化

This commit is contained in:
virusdefender 2015-08-20 20:51:06 +08:00
parent 4146719673
commit d0211c3d1b
2 changed files with 94 additions and 21 deletions

View File

@ -21,43 +21,110 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
hash = "index/index";
}
var superAdminNav = [
{ name: "首页",
children: [{name: "主页", hash: "#index/index"},
{name: "监控", hash: "#monitor/monitor"},
{name: "统计", hash: "#statistics/statistics"}]
},
{
name: "通用",
children: [{name: "公告管理", hash: "#announcement/announcement"},
{name: "用户管理", hash: "#user/user_list"}]
},
{
name: "题目管理",
children: [{name: "题目列表", hash: "#problem/problem_list"},
{name: "创建题目", hash: "#problem/add_problem"}]
},
{
name: "比赛管理",
children: [{name: "比赛列表", hash: "#contest/contest_list"},
{name: "创建比赛", hash: "#contest/add_contest"}]
},
{
name: "小组管理",
children: [{name: "小组列表", hash: "#group/group"},
{name: "加入小组请求", hash: "#group/join_group_request_list"}]
}
];
var adminNav = [
{ name: "首页",
children: [{name: "主页", hash: "#index/index"}]
},
{
name: "通用",
children: [{name: "公告管理", hash: "#announcement/announcement"}]
},
{
name: "比赛管理",
children: [{name: "比赛列表", hash: "#contest/contest_list"},
{name: "创建比赛", hash: "#contest/add_contest"}]
},
{
name: "小组管理",
children: [{name: "小组列表", hash: "#group/group"},
{name: "加入小组请求", hash: "#group/join_group_request_list"}]
}
];
var vm = avalon.define({
$id: "admin",
template_url: "template/" + hash + ".html",
groupId: -1,
problemId: -1,
adminNavList: [],
hide_loading: function () {
$("#loading-gif").hide();
},
getLiId: function(hash){
return hash.replace("#", "li-").replace("/", "-");
}
});
vm.$watch("showGroupDetailPage", function(groupId){
$.ajax({
url: "/api/user/",
method: "get",
dataType: "json",
success: function(data){
if(!data.code){
if (data.data.admin_type == 2){
vm.adminNavList = superAdminNav;
}
else{
vm.adminNavList = adminNav;
}
}
}
});
vm.$watch("showGroupDetailPage", function (groupId) {
vm.groupId = groupId;
vm.template_url = "template/group/group_detail.html";
});
vm.$watch("showEditProblemPage", function(problemId){
vm.$watch("showEditProblemPage", function (problemId) {
vm.problemId = problemId;
vm.template_url = "template/problem/edit_problem.html";
});
vm.$watch("showProblemListPage", function(){
vm.template_url = "template/problem/problem_list.html";
vm.$watch("showProblemListPage", function () {
vm.template_url = "template/problem/problem_list.html";
});
vm.$watch("showGroupListPage", function(){
vm.template_url = "template/group/group.html";
vm.$watch("showGroupListPage", function () {
vm.template_url = "template/group/group.html";
});
vm.$watch("showProblemSubmissionPage", function(problemId){
vm.$watch("showProblemSubmissionPage", function (problemId) {
vm.problemId = problemId;
vm.template_url = "template/problem/submission_list.html";
});
avalon.scan();
li_active("#li-" + hash.replace("/", "-"));
window.onhashchange = function () {
var hash = window.location.hash.substring(1);
if (hash) {
@ -66,6 +133,7 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
show_template("template/" + hash + ".html");
}
};
setTimeout(function(){li_active("#li-" + hash.replace("/", "-"));}, 500)
});

View File

@ -1,3 +1,4 @@
{% verbatim %}
<!DOCTYPE html>
<html>
<head>
@ -8,10 +9,6 @@
<title>在线评测系统 - 后台管理</title>
<!-- custom css begin -->
{% block css_block %}{% endblock %}
<!-- custom css end -->
<!-- global css begin -->
<link href="/static/css/admin.css" rel="stylesheet">
<!-- global css end -->
@ -70,7 +67,13 @@
<!-- admin left begin-->
<div class="col-md-2">
<ul class="list-group">
<li class="list-group-header">首页</li>
<div ms-repeat="adminNavList">
<li class="list-group-header">{{ el.name }}</li>
<li class="list-group-item" ms-attr-id="getLiId(item.hash)" ms-repeat-item="el.children">
<a ms-attr-href="el.hash">{{ item.name }}</a>
</li>
</div>
<!--<li class="list-group-header">首页</li>
<li class="list-group-item" id="li-index-index">
<a href="#index/index">主页</a>
</li>
@ -80,8 +83,12 @@
<li class="list-group-item" id="li-statistics-statistics">
<a href="#statistics/statistics">统计</a>
</li>
<li class="list-group-header">通用</li>
<li class="list-group-item" id="li-announcement-announcement">
<a href="#announcement/announcement">公告</a>
<a href="#announcement/announcement">公告管理</a>
</li>
<li class="list-group-item" id="li-user-user_list">
<a href="#user/user_list">用户管理</a>
</li>
<li class="list-group-header">题目管理</li>
<li class="list-group-item" id="li-problem-problem_list">
@ -97,17 +104,14 @@
<li class="list-group-item" id="li-contest-add_contest">
<a href="#contest/add_contest">创建比赛</a>
</li>
<li class="list-group-header">用户管理</li>
<li class="list-group-item" id="li-user-user_list">
<a href="#user/user_list">用户列表</a>
</li>
<li class="list-group-header">小组管理</li>
<li class="list-group-item" id="li-group-group">
<a href="#group/group">小组列表</a>
</li>
<li class="list-group-item" id="li-group-join_group_request_list">
<a href="#group/join_group_request_list">加入小组请求</a>
</li>
</li>-->
</ul>
</div>
<!-- admin left end -->
@ -133,4 +137,5 @@
</div>
<!-- footer end -->
</body>
</html>
</html>
{% endverbatim %}