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"; 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({ var vm = avalon.define({
$id: "admin", $id: "admin",
template_url: "template/" + hash + ".html", template_url: "template/" + hash + ".html",
groupId: -1, groupId: -1,
problemId: -1, problemId: -1,
adminNavList: [],
hide_loading: function () { hide_loading: function () {
$("#loading-gif").hide(); $("#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.groupId = groupId;
vm.template_url = "template/group/group_detail.html"; vm.template_url = "template/group/group_detail.html";
}); });
vm.$watch("showEditProblemPage", function(problemId){ vm.$watch("showEditProblemPage", function (problemId) {
vm.problemId = problemId; vm.problemId = problemId;
vm.template_url = "template/problem/edit_problem.html"; vm.template_url = "template/problem/edit_problem.html";
}); });
vm.$watch("showProblemListPage", function(){ vm.$watch("showProblemListPage", function () {
vm.template_url = "template/problem/problem_list.html"; vm.template_url = "template/problem/problem_list.html";
}); });
vm.$watch("showGroupListPage", function(){ vm.$watch("showGroupListPage", function () {
vm.template_url = "template/group/group.html"; vm.template_url = "template/group/group.html";
}); });
vm.$watch("showProblemSubmissionPage", function(problemId){ vm.$watch("showProblemSubmissionPage", function (problemId) {
vm.problemId = problemId; vm.problemId = problemId;
vm.template_url = "template/problem/submission_list.html"; vm.template_url = "template/problem/submission_list.html";
}); });
avalon.scan(); avalon.scan();
li_active("#li-" + hash.replace("/", "-"));
window.onhashchange = function () { window.onhashchange = function () {
var hash = window.location.hash.substring(1); var hash = window.location.hash.substring(1);
if (hash) { if (hash) {
@ -66,6 +133,7 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
show_template("template/" + hash + ".html"); show_template("template/" + hash + ".html");
} }
}; };
setTimeout(function(){li_active("#li-" + hash.replace("/", "-"));}, 500)
}); });

View File

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