admin.js
2.61 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
$(document).ready(function() {
// button handler to allow all students
$("#allowall").click(function(e) {
alert('not implemented'); // FIXME
});
// button handler to allow all students
$("#denyall").click(function(e) {
alert('not implemented'); // FIXME
});
// checkbox event handler to allow/deny students
function autorizeStudent(e) {
$.ajax({
type: "POST",
url: "/adminwebservice",
data: {"cmd": "allow", "name": this.name, "value": this.checked}
});
if (this.checked)
$(this).parent().parent().addClass("active");
else
$(this).parent().parent().removeClass("active");
}
// button handler to reset student password
function resetPassword(e) {
$.ajax({
type: "POST",
url: "/adminwebservice",
data: {"cmd": "reset", "name": this.value}
});
}
function populateOnlineTable(online) {
$("#online-header").html(online.length + " Activo(s)");
var rows = "";
$.each(online, function(i, r) {
rows += "<tr><td>" + r[0] + "</td><td>" + r[1] + "</td><td>" + r[2].slice(0,19) + "</td></tr>";
});
$("#online_students").html(rows);
}
function populateOfflineTable(offline, allowed) {
$("#offline-header").html(offline.length + " Inactivo(s)")
var rows = "";
$.each(offline, function(i, r) {
rows += '<tr id="' + r[0] + '" + class="' + (allowed.indexOf(r[0]) > -1? 'active':'') + '">\
<td><input type="checkbox" name="' + r[0] + '" value="true"' + (allowed.indexOf(r[0]) > -1? 'checked':'') + '></td>\
<td>' + r[0] + '</td>\
<td>' + r[1] + '</td>\
<td><button name="reset" value="' + r[0] + '" class="btn btn-xs btn-danger">reset</button></td>\
</tr>';
});
$("#offline_students").html(rows);
}
function populate() {
$.ajax({
url: "/adminwebservice",
dataType: "json",
success: function(data) {
populateOnlineTable(data["online"]);
populateOfflineTable(data["offline"], data["allowed"]);
// add event handlers
$('input[type="checkbox"]').change(autorizeStudent);
$('button[name="reset"]').click(resetPassword);
},
error: function() {alert("Servidor não responde.");}
});
}
populate(); // run once when the page is loaded
setInterval(populate, 5000); // poll server on 5s interval
});