diff --git a/server/api/problem.py b/server/api/problem.py index a790cad..f02d4a8 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -18,7 +18,7 @@ def problem_add(): name = request.form["name"] category = request.form["category"] description = request.form["description"] - hint = request.form["hint"] + hint = request.form["problem-hint"] flag = request.form["flag"] value = request.form["value"] @@ -54,7 +54,7 @@ def problem_delete(): problem = Problems.query.filter_by(pid=pid).first() if problem: Solves.query.filter_by(pid=pid).delete() - Challenges.query.filter_by(pid=pid).delete() + Problems.query.filter_by(pid=pid).delete() db.session.commit() return { "success": 1, "message": "Success!" } return { "success": 0, "message": "Problem does not exist!" } diff --git a/web/css/style.css b/web/css/style.css index 89b6931..5b5d85c 100644 --- a/web/css/style.css +++ b/web/css/style.css @@ -174,3 +174,19 @@ li a, .navbar-brand { -moz-animation-duration: 1s; animation-duration: 1s; } +.modal { + text-align: center; +} +@media screen and (min-width: 768px) { + .modal:before { + display: inline-block; + vertical-align: middle; + content: " "; + height: 100%; + } +} +.modal-dialog { + display: inline-block; + text-align: left; + vertical-align: middle; +} diff --git a/web/js/admin/problems.js b/web/js/admin/problems.js index 0c4b543..0061b19 100644 --- a/web/js/admin/problems.js +++ b/web/js/admin/problems.js @@ -52,7 +52,8 @@ function render_problems() { problem += `

- + + ` $("#problems").append(problem); } @@ -68,10 +69,18 @@ function render_problems() { var disabled = $("input[name=disabled]", problem).prop("checked") ? 1 : 0; update_problem(pid, name, category, description, hint, flag, disabled, value); }); + $("[name=delete-modal]").click(function(e) { + var problem = $(this).parents("form:first"); + var pid = $("input[name=pid]", problem).val(); + var div = $(this).closest("div.panel"); + $("#delete").off().click(function(e) { + delete_problem(pid, div); + }); + }); }); } -function 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, @@ -87,7 +96,24 @@ function update_problem (pid, name, category, description, hint, flag, disabled, } else { display_message("status_" + pid, "danger", data.message, function() {}); } - }) + }); +} + +function delete_problem(pid, div) { + $.post("/api/problem/delete", { + pid: pid + }, function(data) { + if (data.success == 1) { + display_message("delete_status", "success", data.message, function() { + div.slideUp("normal", function() { + $(this).remove(); + $("#delete-modal").modal("hide"); + } ); + }); + } else { + display_message("delete_status", "warning", data.message, function() {}); + } + }); } $(function() { diff --git a/web/pages/admin/problems.html b/web/pages/admin/problems.html index 97695ec..1a2c84e 100644 --- a/web/pages/admin/problems.html +++ b/web/pages/admin/problems.html @@ -1,44 +1,77 @@

Problems

-
-
-
-
-
-
- -
-
- -
-
-
-
- -

-
-
- -
-
- -
-
-
-
- -
-
- - -
-
+
+
+ + +