-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.js
62 lines (56 loc) · 1.51 KB
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function load_balance() {
$('#balance-table').html("Loading...");
$.get('balance.py?command=' + encodeURIComponent("print_balance"),
function(data) {
$('#balance-table').html(data);
}
);
}
function load_logs(filter) {
$('#logs-table').html("Loading...");
if (filter != '')
command_string = filter;
else
command_string = 'print_logs';
$.get('balance.py?command=' + encodeURIComponent(command_string),
function(data) {
$('#logs-table').html(data);
}
);
}
function print_error(msg) {
$('#status').html('<span style="color:red;">' + msg + '</span>')
.delay(8000)
.queue(function() { $(this).html('') });
}
function print_done(msg) {
$('#status').html('done').delay(5000).queue(function() { $(this).html('') });
}
$(document).ready(
function() {
$('#command-box').focus();
$('#command-box').keyup(
function(e) {
if (e.keyCode == 13) {
var command_string = $(this).val();
if (command_string.substring(0, 6) == 'filter') {
load_logs(command_string);
return;
}
$.get('balance.py?command=' + encodeURIComponent(command_string),
function(data) {
if (data.substring(0, 5) != 'error') {
print_done();
load_balance();
load_logs('');
} else {
print_error(data);
}
$('#command-box').val('');
}
);
}
}
);
}
);