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