|
|
@@ -36,8 +36,60 @@ class @Utils
|
36
|
36
|
|
37
|
37
|
@handleDryRunButton: (button, data = if button.form then $(':input[name!="_method"]', button.form).serialize() else '') ->
|
38
|
38
|
$(button).prop('disabled', true)
|
|
39
|
+ cleanup = -> $(button).prop('disabled', false)
|
|
40
|
+
|
|
41
|
+ url = $(button).data('action-url')
|
|
42
|
+ with_event_mode = $(button).data('with-event-mode')
|
|
43
|
+
|
|
44
|
+ if with_event_mode is 'no'
|
|
45
|
+ return @invokeDryRun(url, data, cleanup)
|
|
46
|
+
|
|
47
|
+ Utils.showDynamicModal """
|
|
48
|
+ <h5>Event to send#{if with_event_mode is 'maybe' then ' (Optional)' else ''}</h5>
|
|
49
|
+ <form class="dry-run-form" method="post">
|
|
50
|
+ <div class="form-group">
|
|
51
|
+ <textarea rows="10" name="event" class="payload-editor" data-height="200">
|
|
52
|
+ {}
|
|
53
|
+ </textarea>
|
|
54
|
+ </div>
|
|
55
|
+ <div class="form-group">
|
|
56
|
+ <input value="Dry Run" class="btn btn-primary" type="submit" />
|
|
57
|
+ </div>
|
|
58
|
+ </form>
|
|
59
|
+ """,
|
|
60
|
+ body: (body) =>
|
|
61
|
+ form = $(body).find('.dry-run-form')
|
|
62
|
+ window.setupJsonEditor(form.find('.payload-editor'))
|
|
63
|
+ form.submit (e) =>
|
|
64
|
+ e.preventDefault()
|
|
65
|
+ json = $(e.target).find('.payload-editor').val()
|
|
66
|
+ json = '{}' if json == ''
|
|
67
|
+ try
|
|
68
|
+ payload = JSON.parse(json)
|
|
69
|
+ throw true unless payload.constructor is Object
|
|
70
|
+ if Object.keys(payload).length == 0
|
|
71
|
+ json = ''
|
|
72
|
+ else
|
|
73
|
+ json = JSON.stringify(payload)
|
|
74
|
+ catch
|
|
75
|
+ alert 'Invalid JSON object.'
|
|
76
|
+ return
|
|
77
|
+ if json == ''
|
|
78
|
+ if with_event_mode is 'yes'
|
|
79
|
+ alert 'Event is required for this agent to run.'
|
|
80
|
+ return
|
|
81
|
+ dry_run_data = data
|
|
82
|
+ else
|
|
83
|
+ dry_run_data = "event=#{encodeURIComponent(json)}&#{data}"
|
|
84
|
+ $(body).closest('[role=dialog]').on 'hidden.bs.modal', =>
|
|
85
|
+ @invokeDryRun(url, dry_run_data, cleanup)
|
|
86
|
+ .modal('hide')
|
|
87
|
+ title: 'Dry Run'
|
|
88
|
+ onHide: cleanup
|
|
89
|
+
|
|
90
|
+ @invokeDryRun: (url, data, callback) ->
|
39
|
91
|
$('body').css(cursor: 'progress')
|
40
|
|
- $.ajax type: 'POST', url: $(button).data('action-url'), dataType: 'json', data: data
|
|
92
|
+ $.ajax type: 'POST', url: url, dataType: 'json', data: data
|
41
|
93
|
.always =>
|
42
|
94
|
$('body').css(cursor: 'auto')
|
43
|
95
|
.done (json) =>
|
|
|
@@ -55,7 +107,7 @@ class @Utils
|
55
|
107
|
find('.agent-dry-run-events').text(json.events).end().
|
56
|
108
|
find('.agent-dry-run-memory').text(json.memory)
|
57
|
109
|
title: 'Dry Run Results',
|
58
|
|
- onHide: -> $(button).prop('disabled', false)
|
|
110
|
+ onHide: callback
|
59
|
111
|
.fail (xhr, status, error) ->
|
60
|
112
|
alert('Error: ' + error)
|
61
|
|
- $(button).prop('disabled', false)
|
|
113
|
+ callback()
|