$(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 += "" + r[0] + "" + r[1] + "" + r[2].slice(0,19) + ""; }); $("#online_students").html(rows); } function populateOfflineTable(offline, allowed) { $("#offline-header").html(offline.length + " Inactivo(s)") var rows = ""; $.each(offline, function(i, r) { rows += '\ -1? 'checked':'') + '>\ ' + r[0] + '\ ' + r[1] + '\ \ '; }); $("#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 });