IW4M-Admin/WebfrontCore/wwwroot/js/console.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-23 02:06:13 -05:00
function executeCommand() {
const serverId = $('#console_server_select').val();
const command = $('#console_command_value').val();
if (command.length === 0) {
return false;
}
showLoader();
2022-04-19 19:43:58 -04:00
$.get('/Console/Execute', { serverId: serverId, command: command })
2018-02-23 02:06:13 -05:00
.done(function (response) {
2022-04-19 19:43:58 -04:00
$('#console_command_response pre').html('');
hideLoader();
2022-04-19 19:43:58 -04:00
response.map(r => r.response).forEach(item => {
$('#console_command_response').append(`<div>${item}</div>`);
})
$('#console_command_response').append('<hr/>')
2018-02-23 02:06:13 -05:00
$('#console_command_value').val("");
})
2022-04-19 19:43:58 -04:00
.fail(function (response) {
$('#console_command_response pre').html('');
errorLoader();
hideLoader();
2022-04-19 19:43:58 -04:00
if (response.status < 500) {
response.responseJSON.map(r => r.response).forEach(item => {
$('#console_command_response').append(`<div class="text-danger">${item}</div>`);
})
} else {
$('#console_command_response').append(`<div class="text-danger">Could not execute command...</div>`);
}
2018-02-23 02:06:13 -05:00
});
}
$(document).ready(function () {
if ($('#console_command_button').length === 0) {
return false;
}
2018-02-23 02:06:13 -05:00
$('#console_command_button').click(function (e) {
executeCommand();
});
$(document).keydown(function (event) {
const keyCode = event.keyCode ? event.keyCode : event.which;
2018-02-23 02:06:13 -05:00
if (keyCode === 13) {
executeCommand();
}
});
2022-04-19 19:43:58 -04:00
});