source: binary-improvements/webserver/js/permissions.js@ 269

Last change on this file since 269 was 250, checked in by alloc, 9 years ago

Fixes 5_7_9

File size: 1.6 KB
Line 
1var userdata = false;
2
3function InitPermissions () {
4 $.getJSON( "../userstatus")
5 .done(function(data) {
6 userdata = 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
30 if (HasPermission ("webapi.getwebuiupdates")) {
31 StartUIUpdatesModule ();
32 } else if (HasPermission ("webapi.getstats")) {
33 StartStatsModule ();
34 }
35
36 tabs.tabbedContent ("applyPermissions");
37
38 })
39 .fail(function(jqxhr, textStatus, error) {
40 console.log("Error fetching user data");
41 })
42 .always(function () {
43 if (PermissionCount () == 0) {
44 $("#nopermissionwarning").attr ("style", "display: block");
45 }
46 })
47}
48
49function HasPermission (modulename) {
50 for (var i = 0; i < userdata.permissions.length; i++) {
51 if (userdata.permissions [i].module == modulename) {
52 return userdata.permissions [i].allowed;
53 }
54 }
55 return false;
56}
57
58function PermissionCount () {
59 var cnt = 0;
60 for (var i = 0; i < userdata.permissions.length; i++) {
61 if (userdata.permissions [i].allowed) cnt++;
62 }
63 return cnt;
64}
65
Note: See TracBrowser for help on using the repository browser.