function render_problems() { $.post("/api/admin/problem/data", { }, function(data) { data = data["data"]; for (var i = 0; i < data.length; i++) { files = data[i]["files"]; var checked = ""; if (data[i]["disabled"]) { checked = "checked"; } problem = `



` $("#problems").append(problem); } $("[name=update]").click(function(e) { var problem = $(this).parents("form:first"); var pid = $("input[name=pid]", problem).val(); var name = $("input[name=name]", problem).val(); var description = $("textarea[name=description]", problem).val(); var hint = $("input[name=hint]", problem).val(); var category = $("input[name=category]", problem).val(); var value = $("input[name=value]", problem).val(); var flag = $("input[name=flag]", problem).val(); var disabled = $("input[name=disabled]", problem).prop("checked") ? 1 : 0; update_problem(pid, name, category, description, hint, flag, disabled, value); }); }); } function update_problem (pid, name, category, description, hint, flag, disabled, value) { $.post("/api/problem/update", { pid: pid, name: name, category: category, description: description, hint: hint, flag: flag, disabled: disabled, value: value }, function(data) { if (data.success == 1) { display_message("status_" + pid, "success", data.message, function() {}); } else { display_message("status_" + pid, "danger", data.message, function() {}); } }) } $(function() { render_problems(); });