[245] | 1 | var userdata = false;
|
---|
| 2 |
|
---|
| 3 | function 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 | }
|
---|
[250] | 26 | if (HasPermission ("webapi.getlog")) {
|
---|
| 27 | StartLogModule ();
|
---|
| 28 | }
|
---|
[283] | 29 | if (HasPermission ("webapi.getplayerlist")) {
|
---|
| 30 | StartPlayersModule ();
|
---|
| 31 | }
|
---|
[245] | 32 |
|
---|
[250] | 33 | if (HasPermission ("webapi.getwebuiupdates")) {
|
---|
| 34 | StartUIUpdatesModule ();
|
---|
| 35 | } else if (HasPermission ("webapi.getstats")) {
|
---|
[245] | 36 | StartStatsModule ();
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[250] | 39 | tabs.tabbedContent ("applyPermissions");
|
---|
| 40 |
|
---|
[245] | 41 | })
|
---|
| 42 | .fail(function(jqxhr, textStatus, error) {
|
---|
| 43 | console.log("Error fetching user data");
|
---|
| 44 | })
|
---|
| 45 | .always(function () {
|
---|
[249] | 46 | if (PermissionCount () == 0) {
|
---|
| 47 | $("#nopermissionwarning").attr ("style", "display: block");
|
---|
| 48 | }
|
---|
[245] | 49 | })
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | function HasPermission (modulename) {
|
---|
| 53 | for (var i = 0; i < userdata.permissions.length; i++) {
|
---|
| 54 | if (userdata.permissions [i].module == modulename) {
|
---|
| 55 | return userdata.permissions [i].allowed;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | return false;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[249] | 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 |
|
---|