// from: https://www.tornadoweb.org/en/stable/guide/security.html // with changes: removed datatype and callback from original postJSON function getCookie(name) { var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); return r ? r[1] : undefined; } jQuery.postJSON = function(url, args) { args._xsrf = getCookie("_xsrf"); $.ajax({url: url, data: $.param(args), type: "POST"}); }; // --------------------------------------------------------------------------- $(document).ready(function() { function button_handlers() { // button handlers (runs once) $("#allow_all").click( function() { $(":checkbox").prop("checked", true).trigger('change'); } ); $("#deny_all").click( function() { $(":checkbox").prop("checked", false).trigger('change'); } ); $("#reset_password").click( function () { $.postJSON("/admin", { "cmd": "reset_password", "value": $("#reset_number").val() }); } ); $("#inserir_novo_aluno").click( function () { $.postJSON("/admin", { "cmd": "insert_student", "value": JSON.stringify({ "number": $("#novo_numero").val(), "name": $("#novo_nome").val() }) }); } ); // authorization checkboxes in the students_table: $("tbody", "#students_table").on("change", "input", autorizeStudent); } // ---------------------------------------------------------------------- // checkbox handler to allow/deny students individually function autorizeStudent(e) { if (this.checked) { // $(this).parent().parent().addClass("table-primary"); // row class $.postJSON("/admin", {"cmd": "allow", "value": this.name}); } else { // $(this).parent().parent().removeClass("active"); $.postJSON("/admin", {"cmd": "deny", "value": this.name}); } } // ---------------------------------------------------------------------- function generate_grade_bar(grade) { var barcolor; if (grade < 10) barcolor = 'bg-danger'; else if (grade < 15) barcolor = 'bg-warning'; else barcolor = 'bg-success'; return '