aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/coding-rules/facets/language-facet.js
blob: f36935865fb34fcbe60a9bb3ec0be8daae86c0e4 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import _ from 'underscore';
import CustomValuesFacet from './custom-values-facet';

export default CustomValuesFacet.extend({

  getUrl: function () {
    return baseUrl + '/api/languages/list';
  },

  prepareAjaxSearch: function () {
    return {
      quietMillis: 300,
      url: this.getUrl(),
      data: function (term) {
        return { q: term, ps: 10000 };
      },
      results: function (data) {
        return {
          more: false,
          results: data.languages.map(function (lang) {
            return { id: lang.key, text: lang.name };
          })
        };
      }
    };
  },

  getLabelsSource: function () {
    return this.options.app.languages;
  },

  getValues: function () {
    var that = this,
        labels = that.getLabelsSource();
    return this.model.getValues().map(function (item) {
      return _.extend(item, {
        label: labels[item.val]
      });
    });
  },

  serializeData: function () {
    return _.extend(CustomValuesFacet.prototype.serializeData.apply(this, arguments), {
      values: this.getValues()
    });
  }

});