aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-view.js
blob: a62422642b71525b02611150b0c5fa147215074f (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Generated by CoffeeScript 1.6.3
(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  define(['backbone', 'backbone.marionette', 'coding-rules/views/coding-rules-detail-quality-profiles-view', 'common/handlebars-extensions'], function(Backbone, Marionette, CodingRulesDetailQualityProfilesView) {
    var CodingRulesDetailView, _ref;
    return CodingRulesDetailView = (function(_super) {
      __extends(CodingRulesDetailView, _super);

      function CodingRulesDetailView() {
        _ref = CodingRulesDetailView.__super__.constructor.apply(this, arguments);
        return _ref;
      }

      CodingRulesDetailView.prototype.template = getTemplate('#coding-rules-detail-template');

      CodingRulesDetailView.prototype.regions = {
        qualityProfilesRegion: '#coding-rules-detail-quality-profiles'
      };

      CodingRulesDetailView.prototype.ui = {
        tagsChange: '.coding-rules-detail-tags-change',
        tagInput: '.coding-rules-detail-tag-input',
        tagsEdit: '.coding-rules-detail-tag-edit',
        tagsEditDone: '.coding-rules-detail-tag-edit-done',
        tagsList: '.coding-rules-detail-tag-list',
        descriptionExtra: '#coding-rules-detail-description-extra',
        extendDescriptionLink: '#coding-rules-detail-extend-description',
        extendDescriptionForm: '#coding-rules-detail-extend-description-form',
        extendDescriptionSubmit: '#coding-rules-detail-extend-description-submit',
        extendDescriptionText: '#coding-rules-detail-extend-description-text',
        extendDescriptionSpinner: '#coding-rules-detail-extend-description-spinner',
        cancelExtendDescription: '#coding-rules-detail-extend-description-cancel'
      };

      CodingRulesDetailView.prototype.events = {
        'click @ui.tagsChange': 'changeTags',
        'click @ui.tagsEditDone': 'editDone',
        'click @ui.extendDescriptionLink': 'showExtendDescriptionForm',
        'click @ui.cancelExtendDescription': 'hideExtendDescriptionForm',
        'click @ui.extendDescriptionSubmit': 'submitExtendDescription'
      };

      CodingRulesDetailView.prototype.initialize = function(options) {
        return this.qualityProfilesView = new CodingRulesDetailQualityProfilesView({
          collection: new Backbone.Collection(options.model.get('qualityProfiles'))
        });
      };

      CodingRulesDetailView.prototype.onRender = function() {
        var qp;
        this.qualityProfilesRegion.show(this.qualityProfilesView);
        this.ui.tagInput.select2({
          tags: _.difference(this.options.app.tags, this.model.get('tags')),
          width: '500px'
        });
        this.ui.tagsEdit.hide();
        this.ui.extendDescriptionForm.hide();
        this.ui.extendDescriptionSpinner.hide();
        qp = this.options.app.getActiveQualityProfile();
        if (qp != null) {
          return this.$('.coding-rules-detail-quality-profile').first().addClass('active');
        }
      };

      CodingRulesDetailView.prototype.changeTags = function() {
        this.ui.tagsEdit.show();
        return this.ui.tagsList.hide();
      };

      CodingRulesDetailView.prototype.editDone = function() {
        var tags,
          _this = this;
        this.ui.tagsEdit.html('<i class="spinner"></i>');
        tags = this.ui.tagInput.val();
        return jQuery.ajax({
          type: 'POST',
          url: "" + baseUrl + "/api/codingrules/set_tags",
          data: {
            tags: tags
          }
        }).done(function() {
          _this.model.set('tags', tags.split(','));
          return _this.render();
        });
      };

      CodingRulesDetailView.prototype.showExtendDescriptionForm = function() {
        this.ui.descriptionExtra.hide();
        return this.ui.extendDescriptionForm.show();
      };

      CodingRulesDetailView.prototype.hideExtendDescriptionForm = function() {
        this.ui.descriptionExtra.show();
        return this.ui.extendDescriptionForm.hide();
      };

      CodingRulesDetailView.prototype.submitExtendDescription = function() {
        var _this = this;
        this.ui.extendDescriptionForm.hide();
        this.ui.extendDescriptionSpinner.show();
        return jQuery.ajax({
          type: 'POST',
          url: "" + baseUrl + "/api/codingrules/extend_description",
          dataType: 'json',
          data: {
            text: this.ui.extendDescriptionText.val()
          }
        }).done(function(r) {
          _this.model.set({
            extra: r.extra,
            extraRaw: r.extraRaw
          });
          return _this.render();
        });
      };

      return CodingRulesDetailView;

    })(Marionette.Layout);
  });

}).call(this);