aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/coding-rules/show-app.js
blob: 1505c23ec51e38ce5b69f38c10a860572410b461 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
requirejs.config({
  baseUrl: baseUrl + '/js'
});


requirejs([
  'coding-rules/models/rule',
  'coding-rules/rule-details-view'
],
    function (Rule,
              RuleDetailsView) {

      var $ = jQuery,
          App = new Marionette.Application(),
          p = window.process.addBackgroundProcess();

      App.addInitializer(function () {
        var url = baseUrl + '/api/rules/show',
            key = decodeURIComponent(window.location.search.substr(5)),
            options = {
              key: key,
              actives: true
            };
        $.get(url, options).done(function (data) {
          this.ruleDetailsView = new RuleDetailsView({
            app: App,
            model: new Rule(data.rule),
            actives: data.actives
          });
          this.ruleDetailsView.render().$el.appendTo($('.page'));
          window.process.finishBackgroundProcess(p);
        }).fail(function () {
          window.process.failBackgroundProcess(p);
        });
      });

      App.manualRepository = function () {
        return {
          key: 'manual',
          name: t('coding_rules.manual_rules'),
          language: 'none'
        };
      };

      App.getSubCharacteristicName = function (key) {
        if (key != null) {
          var ch = _.findWhere(App.characteristics, { key: key }),
              parent = _.findWhere(App.characteristics, { key: ch.parent });
          return [parent.name, ch.name].join(' > ');
        } else {
          return null;
        }
      };

      var appXHR = $.get(baseUrl + '/api/rules/app').done(function(r) {
        App.canWrite = r.canWrite;
        App.qualityProfiles = _.sortBy(r.qualityprofiles, ['name', 'lang']);
        App.languages = _.extend(r.languages, {
          none: 'None'
        });
        _.map(App.qualityProfiles, function(profile) {
          profile.language = App.languages[profile.lang];
        });
        App.repositories = r.repositories;
        App.repositories.push(App.manualRepository());
        App.statuses = r.statuses;
        App.characteristics = r.characteristics;
      });

      $.when(window.requestMessages(), appXHR).done(function () {
        App.start();
      });

    });