blob: 4182198ff251d6e2d8ec7347131815e475a7ddd7 (
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
|
define [
'backbone.marionette',
'templates/quality-gates'
], (
Marionette,
Templates
) ->
class QualityGateDetailConditionView extends Marionette.ItemView
tagName: 'tr'
template: Templates['quality-gate-detail-condition']
spinner: '<i class="spinner"></i>'
modelEvents:
'change:id': 'render'
ui:
periodSelect: '[name=period]'
operatorSelect: '[name=operator]'
warningInput: '[name=warning]'
errorInput: '[name=error]'
actionsBox: '.quality-gate-condition-actions'
updateButton: '.update-condition'
events:
'click @ui.updateButton': 'saveCondition'
'click .delete-condition': 'deleteCondition'
'click .add-condition': 'saveCondition'
'click .cancel-add-condition': 'cancelAddCondition'
'keyup :input': 'enableUpdate'
'change :input': 'enableUpdate'
initialize: ->
@populateMetric()
populateMetric: ->
metricKey = @model.get('metric')
metric = _.findWhere @options.app.metrics, key: metricKey
@model.set { metric: metric }, { silent: true }
@model.set { isDiffMetric: metric.key.indexOf('new_') == 0 }, { silent: true }
onRender: ->
@ui.periodSelect.val @model.get('period') || '0'
@ui.operatorSelect.val @model.get('op')
@ui.warningInput.val @model.get('warning')
@ui.errorInput.val @model.get('error')
@ui.periodSelect.select2
allowClear: false
minimumResultsForSearch: 999
width: '200px'
@ui.operatorSelect.select2
allowClear: false
minimumResultsForSearch: 999
width: '150px'
@ui.periodSelect.select2('open') if @model.isNew()
showSpinner: ->
jQuery(@spinner).prependTo @ui.actionsBox
@ui.actionsBox.find(':not(.spinner)').hide()
hideSpinner: ->
@ui.actionsBox.find('.spinner').remove()
@ui.actionsBox.find(':not(.spinner)').show()
saveCondition: ->
@showSpinner()
@model.set
period: @ui.periodSelect.val()
op: @ui.operatorSelect.val()
warning: @ui.warningInput.val()
error: @ui.errorInput.val()
@model.save()
.always =>
@ui.updateButton.prop 'disabled', true
@hideSpinner()
.done =>
@options.collectionView.updateConditions()
deleteCondition: ->
if confirm t('quality_gates.delete_condition.confirm.message')
@showSpinner()
@model.delete().done =>
@options.collectionView.collection.remove @model
@options.collectionView.updateConditions()
@close()
cancelAddCondition: ->
@close()
enableUpdate: ->
@ui.updateButton.prop 'disabled', false
serializeData: ->
period = _.findWhere(@options.app.periods, key: this.model.get('period'))
_.extend super,
canEdit: @options.app.canEdit
periods: @options.app.periods
periodText: period?.text
|