summaryrefslogtreecommitdiff
path: root/web-ui/app/js/features/features.js
blob: 7d0eb0c6ffa1b9d278a13df9aa32ade015414786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
define([], function() {
  var cachedDisabledFeatures;

  function getFeatures() {
    cachedDisabledFeatures = cachedDisabledFeatures || fetchDisabledFeatures();
    return cachedDisabledFeatures;
  }

  function fetchDisabledFeatures() {
    var disabledFeatures;
    $.ajax('/disabled_features', {
      async: false,
      success: function (results){
        disabledFeatures = results;
      },
      error: function () {
        console.error('Could not load feature toggles');
      }
    });
    return disabledFeatures;
  }

  return {
    isEnabled: function(featureName) {
      return ! _.contains(getFeatures(), featureName);
    }
  };
});