blob: 6f417be31b5f0f1b72bc3b2dc277ec471fad1a33 (
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
|
define [
'backbone.marionette',
'handlebars'
], (
Marionette,
Handlebars
) ->
class QualityGateDetailConditionView extends Marionette.ItemView
tagName: 'tr'
template: Handlebars.compile jQuery('#quality-gate-detail-condition-template').html()
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 = @options.app.metrics.findWhere key: metricKey
@model.set { metric: metric.toJSON() }, { silent: true }
onRender: ->
@ui.periodSelect.val @model.get('period') || '0'
@ui.operatorSelect.val @model.get('op')
@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.children().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 window.SS.phrases.areYouSure
@showSpinner()
@model.delete().done =>
@options.collectionView.updateConditions()
@close()
cancelAddCondition: ->
@close()
enableUpdate: ->
@ui.updateButton.prop 'disabled', false
serializeData: ->
period = _.findWhere(window.SS.metricPeriods, key: '' + this.model.get('period'))
_.extend super,
canEdit: @options.app.canEdit
periods: window.SS.metricPeriods
periodText: period?.text
|