summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2024-07-28 01:21:27 +0200
committerJo-Philipp Wich <jo@mein.io>2024-07-28 01:36:22 +0200
commit702c0073657017a4bed10b18d0d92bd5464d2046 (patch)
tree5f1c3e423f08e4c24b217e0b5eede4cb9b7d0a27
parent0f9c168fa643089abd073b59ffbfcc6abe220dea (diff)
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>
-rw-r--r--applications/luci-app-commands/ucode/template/commands.ut49
1 files changed, 18 insertions, 31 deletions
diff --git a/applications/luci-app-commands/ucode/template/commands.ut b/applications/luci-app-commands/ucode/template/commands.ut
index f11efe948c..90a3c298f0 100644
--- a/applications/luci-app-commands/ucode/template/commands.ut
+++ b/applications/luci-app-commands/ucode/template/commands.ut
@@ -29,15 +29,9 @@
-%}
<script type="text/javascript">//<![CDATA[
- var stxhr = new XHR();
-
function command_run(ev, id)
{
- var args;
var field = document.getElementById(id);
- if (field)
- args = encodeURIComponent(field.value);
-
var legend = document.getElementById('command-rc-legend');
var output = document.getElementById('command-rc-output');
@@ -51,31 +45,24 @@
legend.parentNode.style.display = 'block';
legend.style.display = 'inline';
- stxhr.get(L.url('admin/system/commands/run', id) + (args ? '?args=' + args : ''), null,
- function(x, st)
- {
- if (st)
- {
- if (st.binary)
- st.stdout = '[' + _('Binary data not displayed, download instead.') + ']';
-
- legend.style.display = 'none';
- output.innerHTML = String.format(
- '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' +
- '<div class="alert-message warning">%h (%h %d)</div>',
- st.command, st.stdout, st.stderr,
- (st.exitcode == 0) ? _('Command successful') : _('Command failed'),
- _('Code:'), st.exitcode);
- }
- else
- {
- legend.style.display = 'none';
- output.innerHTML = '<span class="error">%h</span>'.format(_('Failed to execute command!'));
- }
-
- location.hash = '#output';
- }
- );
+ L.Request.get(L.url('admin/system/commands/run', id), field ? { args: field.value } : null).then(function(reply) {
+ var st = reply.json();
+
+ if (st.binary)
+ st.stdout = '[' + _('Binary data not displayed, download instead.') + ']';
+
+ output.innerHTML = String.format(
+ '<pre><strong># %h\n</strong>%h<span style="color:red">%h</span></pre>' +
+ '<div class="alert-message warning">%h (%h %d)</div>',
+ st.command, st.stdout, st.stderr,
+ (st.exitcode == 0) ? _('Command successful') : _('Command failed'),
+ _('Code:'), st.exitcode);
+ }).catch(function() {
+ output.innerHTML = '<span class="error">%h</span>'.format(_('Failed to execute command!'));
+ }).finally(function() {
+ legend.style.display = 'none';
+ location.hash = '#output';
+ });
}
ev.preventDefault();