aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/coffee/coding-rules/views/coding-rules-detail-view.coffee
blob: 4cf361c7a5cfe46b7ed92c5e02cdc33dbd95f246 (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
125
126
127
128
129
130
131
define [
  'backbone',
  'backbone.marionette',
  'coding-rules/views/coding-rules-detail-quality-profiles-view'
  'templates/coding-rules'
], (
  Backbone,
  Marionette,
  CodingRulesDetailQualityProfilesView,
  Templates
) ->

  class CodingRulesDetailView extends Marionette.Layout
    template: Templates['coding-rules-detail']


    regions:
      qualityProfilesRegion: '#coding-rules-detail-quality-profiles'


    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'

      activateQualityProfile: '#coding-rules-quality-profile-activate'
      changeQualityProfile: '.coding-rules-detail-quality-profile-update'


    events:
      'click @ui.tagsChange': 'changeTags'
      'click @ui.tagsEditDone': 'editDone'

      'click @ui.extendDescriptionLink': 'showExtendDescriptionForm'
      'click @ui.cancelExtendDescription': 'hideExtendDescriptionForm'
      'click @ui.extendDescriptionSubmit': 'submitExtendDescription'

      'click @ui.activateQualityProfile': 'activateQualityProfile'
      'click @ui.changeQualityProfile': 'changeQualityProfile'


    initialize: (options) ->
      @qualityProfilesView = new CodingRulesDetailQualityProfilesView
        app: @options.app
        collection: new Backbone.Collection options.model.get 'qualityProfiles'


    onRender: ->
      @qualityProfilesRegion.show @qualityProfilesView

      @ui.tagInput.select2
        tags: _.difference @options.app.tags, @model.get 'tags'
        width: '300px'
      @ui.tagsEdit.hide()

      @ui.extendDescriptionForm.hide()
      @ui.extendDescriptionSpinner.hide()


    changeTags: ->
      @ui.tagsEdit.show()
      @ui.tagsList.hide()


    editDone: ->
      @ui.tagsEdit.html '<i class="spinner"></i>'
      tags = @ui.tagInput.val()
      jQuery.ajax
        type: 'POST'
        url: "#{baseUrl}/api/codingrules/set_tags"
        data: tags: tags
      .done =>
          @model.set 'tags', tags.split ','
          @render()


    showExtendDescriptionForm: ->
      @ui.descriptionExtra.hide()
      @ui.extendDescriptionForm.show()


    hideExtendDescriptionForm: ->
      @ui.descriptionExtra.show()
      @ui.extendDescriptionForm.hide()


    submitExtendDescription: ->
      @ui.extendDescriptionForm.hide()
      @ui.extendDescriptionSpinner.show()
      jQuery.ajax
        type: 'POST'
        url: "#{baseUrl}/api/codingrules/extend_description"
        dataType: 'json'
        data: text: @ui.extendDescriptionText.val()
      .done (r) =>
        @model.set extra: r.extra, extraRaw: r.extraRaw
        @render()


    getContextQualilyProfile: ->
      contextQualityProfile = @options.app.getQualityProfile()
      _.findWhere @model.get('qualityProfiles'), key: contextQualityProfile


    activateQualityProfile: ->
      @options.app.codingRulesQualityProfileActivationView.model = null
      @options.app.codingRulesQualityProfileActivationView.show()


    changeQualityProfile: ->
      @options.app.codingRulesQualityProfileActivationView.model = new Backbone.Model @getContextQualilyProfile()
      @options.app.codingRulesQualityProfileActivationView.show()


    serializeData: ->
      contextQualityProfile = @options.app.getQualityProfile()

      _.extend super,
        contextQualityProfile: contextQualityProfile
        contextQualityProfileName: @options.app.qualityProfileFilter.view.renderValue()
        qualityProfile: @getContextQualilyProfile()