mirror of
https://github.com/openwrt/luci.git
synced 2025-12-22 16:54:36 +04:00
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 <jo@mein.io>
This commit is contained in:
@@ -29,15 +29,9 @@
|
|||||||
-%}
|
-%}
|
||||||
|
|
||||||
<script type="text/javascript">//<![CDATA[
|
<script type="text/javascript">//<![CDATA[
|
||||||
var stxhr = new XHR();
|
|
||||||
|
|
||||||
function command_run(ev, id)
|
function command_run(ev, id)
|
||||||
{
|
{
|
||||||
var args;
|
|
||||||
var field = document.getElementById(id);
|
var field = document.getElementById(id);
|
||||||
if (field)
|
|
||||||
args = encodeURIComponent(field.value);
|
|
||||||
|
|
||||||
var legend = document.getElementById('command-rc-legend');
|
var legend = document.getElementById('command-rc-legend');
|
||||||
var output = document.getElementById('command-rc-output');
|
var output = document.getElementById('command-rc-output');
|
||||||
|
|
||||||
@@ -51,31 +45,24 @@
|
|||||||
legend.parentNode.style.display = 'block';
|
legend.parentNode.style.display = 'block';
|
||||||
legend.style.display = 'inline';
|
legend.style.display = 'inline';
|
||||||
|
|
||||||
stxhr.get(L.url('admin/system/commands/run', id) + (args ? '?args=' + args : ''), null,
|
L.Request.get(L.url('admin/system/commands/run', id), field ? { args: field.value } : null).then(function(reply) {
|
||||||
function(x, st)
|
var st = reply.json();
|
||||||
{
|
|
||||||
if (st)
|
|
||||||
{
|
|
||||||
if (st.binary)
|
if (st.binary)
|
||||||
st.stdout = '[' + _('Binary data not displayed, download instead.') + ']';
|
st.stdout = '[' + _('Binary data not displayed, download instead.') + ']';
|
||||||
|
|
||||||
legend.style.display = 'none';
|
|
||||||
output.innerHTML = String.format(
|
output.innerHTML = String.format(
|
||||||
'<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' +
|
'<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' +
|
||||||
'<div class="alert-message warning">%h (%h %d)</div>',
|
'<div class="alert-message warning">%h (%h %d)</div>',
|
||||||
st.command, st.stdout, st.stderr,
|
st.command, st.stdout, st.stderr,
|
||||||
(st.exitcode == 0) ? _('Command successful') : _('Command failed'),
|
(st.exitcode == 0) ? _('Command successful') : _('Command failed'),
|
||||||
_('Code:'), st.exitcode);
|
_('Code:'), st.exitcode);
|
||||||
}
|
}).catch(function() {
|
||||||
else
|
|
||||||
{
|
|
||||||
legend.style.display = 'none';
|
|
||||||
output.innerHTML = '<span class="error">%h</span>'.format(_('Failed to execute command!'));
|
output.innerHTML = '<span class="error">%h</span>'.format(_('Failed to execute command!'));
|
||||||
}
|
}).finally(function() {
|
||||||
|
legend.style.display = 'none';
|
||||||
location.hash = '#output';
|
location.hash = '#output';
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user