aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/javascripts/coding-rules/views/coding-rules-detail-quality-profile-view.coffee
blob: 3b4dd7ae88879c36a62e3dbc34f6282b89fd6c52 (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
define [
  'backbone.marionette',
  'common/handlebars-extensions'
], (
  Marionette
) ->

  class CodingRulesDetailQualityProfilesView extends Marionette.ItemView
    className: 'coding-rules-detail-quality-profile'
    template: getTemplate '#coding-rules-detail-quality-profile-template'


    ui:
      severitySelect: '.coding-rules-detail-quality-profile-severity'


    onRender: ->
      format = (state) ->
        return state.text unless state.id
        "<i class='icon-severity-#{state.id.toLowerCase()}'></i> #{state.text}"

      @ui.severitySelect.val @model.get 'severity'
      @ui.severitySelect.select2
        width: '200px'
        minimumResultsForSearch: 999
        formatResult: format
        formatSelection: format
        escapeMarkup: (m) -> m


    getParent: ->
      return null unless @model.get 'inherits'
      @options.qualityProfiles.findWhere(key: @model.get('inherits')).toJSON()


    enhanceParameters: ->
      parent = @getParent()
      parameters = @model.get 'parameters'
      return parameters unless parent
      parameters.map (p) ->
        _.extend p, original: _.findWhere(parent.parameters, key: p.key).value


    serializeData: ->
      _.extend super,
        parent: @getParent()
        parameters: @enhanceParameters()
        severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO']