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
|
define [
'backbone.marionette',
'templates/quality-gates'
], (
Marionette,
Templates
) ->
class QualityGateEditView extends Marionette.ItemView
className: 'modal'
template: Templates['quality-gate-edit']
ui:
nameInput: '#quality-gate-edit-name'
events:
'submit form': 'onSubmit'
'click #quality-gate-cancel-create': 'hide'
onRender: ->
@$el.dialog
dialogClass: 'no-close',
width: '600px',
draggable: false,
autoOpen: false,
modal: true,
minHeight: 50,
resizable: false,
title: null
show: ->
@render()
@$el.dialog 'open'
@ui.nameInput.focus()
hide: ->
@$el.dialog 'close'
saveRequest: (data) ->
jQuery.ajax
type: 'POST'
url: "#{baseUrl}/api/qualitygates/#{@method}"
data: data
.done => @hide()
onSubmit: (e) ->
e.preventDefault()
switch @method
when 'create' then @createQualityGate()
when 'copy' then @copyQualityGate()
when 'rename' then @saveQualityGate()
else
createQualityGate: ->
data = name: @ui.nameInput.val()
@saveRequest(data).done (r) =>
@model.set id: r.id, name: r.name
@options.app.qualityGates.add @model
@options.app.router.navigate "show/#{r.id}", trigger: true
saveQualityGate: ->
data = id: @model.id, name: @ui.nameInput.val()
@saveRequest(data).done (r) =>
@model.set name: r.name
copyQualityGate: ->
data = id: @model.id, name: @ui.nameInput.val()
@saveRequest(data).done (r) =>
@model.set id: r.id, name: r.name
@options.app.qualityGates.add @model
@options.app.router.navigate "show/#{r.id}", trigger: true
serializeData: ->
if @model
_.extend @model.toJSON(), method: @method
|