aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/coffee/issues/views/set-severity-form-view.coffee
blob: 96d756db7b4e978368982c941503715e21829429 (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
define [
  'backbone.marionette'
  'templates/issues'
], (
  Marionette
  Templates
) ->

  $ = jQuery
  

  class SetSeverityFormView extends Marionette.ItemView
    template: Templates['set-severity-form']


    ui:
      select: '#issue-set-severity-select'


    events:
      'click #issue-set-severity-cancel': 'cancel'
      'click #issue-set-severity-submit': 'submit'


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

     @ui.select.select2
       minimumResultsForSearch: 100
       formatResult: format
       formatSelection: format
       escapeMarkup: (m) -> m


    cancel: ->
      @options.detailView.updateAfterAction false


    submit: ->
      @options.detailView.showActionSpinner()
      $.ajax
        type: 'POST'
        url: baseUrl + '/api/issues/set_severity'
        data:
          issue: @options.issue.get('key')
          severity: @ui.select.val()
      .done => @options.detailView.updateAfterAction true
      .fail (r) =>
        alert _.pluck(r.responseJSON.errors, 'msg').join(' ')
        @options.detailView.hideActionSpinner()