Skip to content

Commit 702c007

Browse files
committed
luci-app-commands: avoid deprecated XHR() usage
Replace direct usage of deprecated XHR() wrapper with L.request class calls. Signed-off-by: Jo-Philipp Wich <[email protected]>
1 parent 0f9c168 commit 702c007

File tree

1 file changed

+18
-31
lines changed
  • applications/luci-app-commands/ucode/template

1 file changed

+18
-31
lines changed

applications/luci-app-commands/ucode/template/commands.ut

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@
2929
-%}
3030

3131
<script type="text/javascript">//<![CDATA[
32-
var stxhr = new XHR();
33-
3432
function command_run(ev, id)
3533
{
36-
var args;
3734
var field = document.getElementById(id);
38-
if (field)
39-
args = encodeURIComponent(field.value);
40-
4135
var legend = document.getElementById('command-rc-legend');
4236
var output = document.getElementById('command-rc-output');
4337

@@ -51,31 +45,24 @@
5145
legend.parentNode.style.display = 'block';
5246
legend.style.display = 'inline';
5347

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+
});
7966
}
8067

8168
ev.preventDefault();

0 commit comments

Comments
 (0)