From dad92d1e53bafb8aa6a53b383ac7455c65eeec91 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Mon, 11 Sep 2017 10:14:07 +0000 Subject: [PATCH] Add reasons to admin token transactions --- webapp/titanembeds/blueprints/admin/admin.py | 6 ++++-- .../static/js/admin_token_transactions.js | 14 ++++++++------ .../templates/admin_token_transactions.html.j2 | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/webapp/titanembeds/blueprints/admin/admin.py b/webapp/titanembeds/blueprints/admin/admin.py index 65e3a86..420a870 100644 --- a/webapp/titanembeds/blueprints/admin/admin.py +++ b/webapp/titanembeds/blueprints/admin/admin.py @@ -213,11 +213,12 @@ def manage_titan_tokens(): def post_titan_tokens(): user_id = request.form.get("user_id", None) amount = request.form.get("amount", None, type=int) + reason = request.form.get("reason", None) if not user_id or not amount: abort(400) if get_titan_token(user_id) != -1: abort(409) - set_titan_token(user_id, amount, "NEW VIA ADMIN") + set_titan_token(user_id, amount, "NEW VIA ADMIN [{}]".format(str(reason))) return ('', 204) @admin.route("/tokens", methods=["PATCH"]) @@ -225,9 +226,10 @@ def post_titan_tokens(): def patch_titan_tokens(): user_id = request.form.get("user_id", None) amount = request.form.get("amount", None, type=int) + reason = request.form.get("reason", None) if not user_id or not amount: abort(400) if get_titan_token(user_id) == -1: abort(409) - set_titan_token(user_id, amount, "MODIFY VIA ADMIN") + set_titan_token(user_id, amount, "MODIFY VIA ADMIN [{}]".format(str(reason))) return ('', 204) \ No newline at end of file diff --git a/webapp/titanembeds/static/js/admin_token_transactions.js b/webapp/titanembeds/static/js/admin_token_transactions.js index c44c46d..ccb75f1 100644 --- a/webapp/titanembeds/static/js/admin_token_transactions.js +++ b/webapp/titanembeds/static/js/admin_token_transactions.js @@ -1,19 +1,19 @@ /* global $, Materialize, location */ -function postForm(user_id, amount) { +function postForm(user_id, amount, reason) { var funct = $.ajax({ dataType: "json", method: "POST", - data: {"user_id": user_id, "amount": amount} + data: {"user_id": user_id, "amount": amount, "reason": reason} }); return funct.promise(); } -function patchForm(user_id, amount) { +function patchForm(user_id, amount, reason) { var funct = $.ajax({ dataType: "json", method: "PATCH", - data: {"user_id": user_id, "amount": amount} + data: {"user_id": user_id, "amount": amount, "reason": reason} }); return funct.promise(); } @@ -22,11 +22,12 @@ $(function() { $("#new_submit").click(function () { var user_id = $("#new_user_id").val(); var user_token = $("#new_user_token").val(); + var reason = $("#new_reason").val(); if (user_id.length < 1 || user_token.length < 1) { Materialize.toast("The user ID or balance field can't be blank!", 2000); return; } - var formPost = postForm(user_id, user_token); + var formPost = postForm(user_id, user_token, reason); formPost.done(function (data) { location.reload(); }); @@ -42,7 +43,8 @@ $(function() { function submit_modify_user(user_id) { var amount = $("#input_"+user_id).val(); - var formPatch = patchForm(user_id, amount); + var reason = $("#input_reason_"+user_id).val(); + var formPatch = patchForm(user_id, amount, reason); formPatch.done(function (data) { location.reload(); }); diff --git a/webapp/titanembeds/templates/admin_token_transactions.html.j2 b/webapp/titanembeds/templates/admin_token_transactions.html.j2 index c81d779..20681b4 100644 --- a/webapp/titanembeds/templates/admin_token_transactions.html.j2 +++ b/webapp/titanembeds/templates/admin_token_transactions.html.j2 @@ -13,6 +13,7 @@ User ID Starting Balance + Reason Submit @@ -28,6 +29,11 @@ + +
+ +
+ Submit @@ -49,6 +55,7 @@ Modify Amount + Reason Submit @@ -58,7 +65,11 @@
-

(Place a subtract sign in the front to remove tokens. Otherwise, it will add the amount)

+ + +
+ +
Submit @@ -66,7 +77,7 @@ - +

(Place a subtract sign in the front to remove tokens. Otherwise, it will add the amount)

Balance: {{ don.tokens }} Tokens