1 | var userdata = false;
|
---|
2 |
|
---|
3 | function InitPermissions () {
|
---|
4 | $.getJSON( "../userstatus")
|
---|
5 | .done(function(data) {
|
---|
6 | userdata = data.data;
|
---|
7 |
|
---|
8 | var userdataDiv = $("#userstate");
|
---|
9 | if (userdata.loggedIn == true) {
|
---|
10 | var data = userdataDiv.children ("#userstate_loggedin");
|
---|
11 | data.attr ("style", "display: block");
|
---|
12 | data.children ("#username").attr ("href", "http://steamcommunity.com/profiles/" + userdata.username);
|
---|
13 | data.children ("#username").html (userdata.username);
|
---|
14 | } else {
|
---|
15 | var data = userdataDiv.children ("#userstate_loggedout");
|
---|
16 | data.attr ("style", "display: block");
|
---|
17 | }
|
---|
18 |
|
---|
19 | if (HasPermission ("webapi.getstats")) {
|
---|
20 | $("#serverstats").attr ("style", "display: block");
|
---|
21 | }
|
---|
22 |
|
---|
23 | if (HasPermission ("web.map")) {
|
---|
24 | StartMapModule ();
|
---|
25 | }
|
---|
26 | if (HasPermission ("webapi.getlog")) {
|
---|
27 | StartLogModule ();
|
---|
28 | }
|
---|
29 | if (HasPermission ("webapi.getplayerlist")) {
|
---|
30 | StartPlayersModule ();
|
---|
31 | }
|
---|
32 |
|
---|
33 | if (HasPermission ("webapi.getwebuiupdates")) {
|
---|
34 | StartUIUpdatesModule ();
|
---|
35 | } else if (HasPermission ("webapi.getstats")) {
|
---|
36 | StartStatsModule ();
|
---|
37 | }
|
---|
38 |
|
---|
39 | tabs.tabbedContent ("applyPermissions");
|
---|
40 |
|
---|
41 | })
|
---|
42 | .fail(function(jqxhr, textStatus, error) {
|
---|
43 | console.log("Error fetching user data");
|
---|
44 | })
|
---|
45 | .always(function () {
|
---|
46 | if (PermissionCount () == 0) {
|
---|
47 | $("#nopermissionwarning").attr ("style", "display: block");
|
---|
48 | }
|
---|
49 | })
|
---|
50 | }
|
---|
51 |
|
---|
52 | function HasPermission (modulename) {
|
---|
53 | for (var i = 0; i < userdata.permissions.length; i++) {
|
---|
54 | if (userdata.permissions [i].module.toUpperCase() == modulename.toUpperCase()) {
|
---|
55 | return userdata.permissions [i].allowed.GET;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 |
|
---|
61 | function PermissionCount () {
|
---|
62 | var cnt = 0;
|
---|
63 | for (var i = 0; i < userdata.permissions.length; i++) {
|
---|
64 | if (userdata.permissions [i].allowed) cnt++;
|
---|
65 | }
|
---|
66 | return cnt;
|
---|
67 | }
|
---|
68 |
|
---|