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