]> source.dussan.org Git - sonarqube.git/blob
169984ba6b5134ae32fd78bd21abdef089b62398
[sonarqube.git] /
1 define [
2   'backbone.marionette',
3   'templates/coding-rules'
4 ], (
5   Marionette,
6   Templates
7 ) ->
8
9   class CodingRulesDetailQualityProfilesView extends Marionette.ItemView
10     className: 'coding-rules-detail-quality-profile'
11     template: Templates['coding-rules-detail-quality-profile']
12
13
14     ui:
15       update: '.coding-rules-detail-quality-profile-update'
16       severitySelect: '.coding-rules-detail-quality-profile-severity'
17
18       note: '.coding-rules-detail-quality-profile-note'
19       noteForm: '.coding-rules-detail-quality-profile-note-form'
20       noteText: '.coding-rules-detail-quality-profile-note-text'
21       noteAdd: '.coding-rules-detail-quality-profile-note-add'
22       noteEdit: '.coding-rules-detail-quality-profile-note-edit'
23       noteDelete: '.coding-rules-detail-quality-profile-note-delete'
24       noteCancel: '.coding-rules-detail-quality-profile-note-cancel'
25       noteSubmit: '.coding-rules-detail-quality-profile-note-submit'
26
27
28     events:
29       'click @ui.noteAdd': 'editNote'
30       'click @ui.noteEdit': 'editNote'
31       'click @ui.noteDelete': 'deleteNote'
32       'click @ui.noteCancel': 'cancelNote'
33       'click @ui.noteSubmit': 'submitNote'
34
35       'change .coding-rules-detail-parameters select': 'enableUpdate'
36       'keyup .coding-rules-detail-parameters input': 'enableUpdate'
37
38
39     editNote: ->
40       @ui.note.hide()
41       @ui.noteForm.show()
42       @ui.noteText.focus()
43
44
45     deleteNote: ->
46       @ui.noteText.val ''
47       @submitNote().done =>
48         @model.unset 'note'
49         @render()
50
51
52     cancelNote: ->
53       @ui.note.show()
54       @ui.noteForm.hide()
55
56
57     submitNote: ->
58       @ui.note.html '<i class="spinner"></i>'
59       @ui.noteForm.html '<i class="spinner"></i>'
60       jQuery.ajax
61         type: 'POST'
62         url: "#{baseUrl}/api/codingrules/note"
63         dataType: 'json'
64         data: text: @ui.noteText.val()
65       .done (r) =>
66         @model.set 'note', r.note
67         @render()
68
69
70     enableUpdate: ->
71       @ui.update.prop 'disabled', false
72
73
74     onRender: ->
75       @ui.noteForm.hide()
76
77       format = (state) ->
78         return state.text unless state.id
79         "<i class='icon-severity-#{state.id.toLowerCase()}'></i> #{state.text}"
80
81       @ui.severitySelect.val @model.get 'severity'
82       @ui.severitySelect.select2
83         width: '200px'
84         minimumResultsForSearch: 999
85         formatResult: format
86         formatSelection: format
87         escapeMarkup: (m) -> m
88
89
90     getParent: ->
91       return null unless @model.get 'inherits'
92       @options.qualityProfiles.findWhere(key: @model.get('inherits')).toJSON()
93
94
95     enhanceParameters: ->
96       parent = @getParent()
97       parameters = @model.get 'parameters'
98       return parameters unless parent
99       parameters.map (p) ->
100         _.extend p, original: _.findWhere(parent.parameters, key: p.key).value
101
102
103     serializeData: ->
104       _.extend super,
105         parent: @getParent()
106         parameters: @enhanceParameters()
107         severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO']