|
29 | 29 | -%} |
30 | 30 |
|
31 | 31 | <script type="text/javascript">//<![CDATA[ |
32 | | - var stxhr = new XHR(); |
33 | | - |
34 | 32 | function command_run(ev, id) |
35 | 33 | { |
36 | | - var args; |
37 | 34 | var field = document.getElementById(id); |
38 | | - if (field) |
39 | | - args = encodeURIComponent(field.value); |
40 | | - |
41 | 35 | var legend = document.getElementById('command-rc-legend'); |
42 | 36 | var output = document.getElementById('command-rc-output'); |
43 | 37 |
|
|
51 | 45 | legend.parentNode.style.display = 'block'; |
52 | 46 | legend.style.display = 'inline'; |
53 | 47 |
|
54 | | - stxhr.get(L.url('admin/system/commands/run', id) + (args ? '?args=' + args : ''), null, |
55 | | - function(x, st) |
56 | | - { |
57 | | - if (st) |
58 | | - { |
59 | | - if (st.binary) |
60 | | - st.stdout = '[' + _('Binary data not displayed, download instead.') + ']'; |
61 | | - |
62 | | - legend.style.display = 'none'; |
63 | | - output.innerHTML = String.format( |
64 | | - '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' + |
65 | | - '<div class="alert-message warning">%h (%h %d)</div>', |
66 | | - st.command, st.stdout, st.stderr, |
67 | | - (st.exitcode == 0) ? _('Command successful') : _('Command failed'), |
68 | | - _('Code:'), st.exitcode); |
69 | | - } |
70 | | - else |
71 | | - { |
72 | | - legend.style.display = 'none'; |
73 | | - output.innerHTML = '<span class="error">%h</span>'.format(_('Failed to execute command!')); |
74 | | - } |
75 | | - |
76 | | - location.hash = '#output'; |
77 | | - } |
78 | | - ); |
| 48 | + L.Request.get(L.url('admin/system/commands/run', id), field ? { args: field.value } : null).then(function(reply) { |
| 49 | + var st = reply.json(); |
| 50 | + |
| 51 | + if (st.binary) |
| 52 | + st.stdout = '[' + _('Binary data not displayed, download instead.') + ']'; |
| 53 | + |
| 54 | + output.innerHTML = String.format( |
| 55 | + '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' + |
| 56 | + '<div class="alert-message warning">%h (%h %d)</div>', |
| 57 | + st.command, st.stdout, st.stderr, |
| 58 | + (st.exitcode == 0) ? _('Command successful') : _('Command failed'), |
| 59 | + _('Code:'), st.exitcode); |
| 60 | + }).catch(function() { |
| 61 | + output.innerHTML = '<span class="error">%h</span>'.format(_('Failed to execute command!')); |
| 62 | + }).finally(function() { |
| 63 | + legend.style.display = 'none'; |
| 64 | + location.hash = '#output'; |
| 65 | + }); |
79 | 66 | } |
80 | 67 |
|
81 | 68 | ev.preventDefault(); |
|
0 commit comments