aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/javascripts/quality-gate/views/quality-gate-detail-header-view.coffee
blob: b5be79800a118a0722b17aae4936d432083b94aa (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
define [
  'backbone.marionette',
  'handlebars',
  'quality-gate/models/quality-gate'
], (
  Marionette,
  Handlebars,
  QualityGate
) ->

  class QualityGateDetailHeaderView extends Marionette.ItemView
    template: Handlebars.compile jQuery('#quality-gate-detail-header-template').html()
    spinner: '<i class="spinner"></i>'


    modelEvents:
      'change': 'render'


    events:
      'click #quality-gate-rename': 'renameQualityGate'
      'click #quality-gate-copy': 'copyQualityGate'
      'click #quality-gate-delete': 'deleteQualityGate'
      'click #quality-gate-set-as-default': 'setAsDefault'
      'click #quality-gate-unset-as-default': 'unsetAsDefault'


    renameQualityGate: ->
      @options.app.qualityGateEditView.method = 'rename'
      @options.app.qualityGateEditView.model = @model
      @options.app.qualityGateEditView.show()


    copyQualityGate: ->
      copiedModel = new QualityGate @model.toJSON()
      @options.app.qualityGateEditView.method = 'copy'
      @options.app.qualityGateEditView.model = copiedModel
      @options.app.qualityGateEditView.show()


    deleteQualityGate: ->
      if confirm window.SS.phrases.areYouSure
        @showSpinner()
        jQuery.ajax
          type: 'POST'
          url: "#{baseUrl}/api/qualitygates/destroy"
          data: id: @model.id
        .always =>
          @hideSpinner()
        .done =>
          @options.app.deleteQualityGate @model.id


    changeDefault: (set) ->
      @showSpinner()
      data = if set then { id: @model.id } else {}
      method = if set then 'set_as_default' else 'unset_default'
      jQuery.ajax
        type: 'POST'
        url: "#{baseUrl}/api/qualitygates/#{method}"
        data: data
      .always =>
        @hideSpinner()
      .done =>
        @options.app.unsetDefaults @model.id
        @model.set 'default', !@model.get('default')


    setAsDefault: ->
      @changeDefault true


    unsetAsDefault: ->
      @changeDefault false


    showSpinner: ->
      @$el.hide()
      jQuery(@spinner).insertBefore @$el


    hideSpinner: ->
      @$el.prev().remove()
      @$el.show()


    serializeData: ->
      _.extend super, canEdit: @options.app.canEdit