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

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

Fixes

File size: 1.2 KB
RevLine 
[245]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 ApplyTabPermissions ();
24
25 if (HasPermission ("web.map")) {
26 StartMapModule ();
27 }
28
29 if (HasPermission ("webapi.getstats")) {
30 StartStatsModule ();
31 }
32
33 })
34 .fail(function(jqxhr, textStatus, error) {
35 console.log("Error fetching user data");
36 })
37 .always(function () {
38 $("#nopermissionwarning").attr ("style", "display: block");
39 })
40}
41
42function HasPermission (modulename) {
43 for (var i = 0; i < userdata.permissions.length; i++) {
44 if (userdata.permissions [i].module == modulename) {
45 return userdata.permissions [i].allowed;
46 }
47 }
48 return false;
49}
50
Note: See TracBrowser for help on using the repository browser.