2017-08-14 03:10:03 +02:00
|
|
|
/* global $, Materialize, location */
|
|
|
|
|
2017-09-11 12:14:07 +02:00
|
|
|
function postForm(user_id, amount, reason) {
|
2017-08-14 03:10:03 +02:00
|
|
|
var funct = $.ajax({
|
|
|
|
dataType: "json",
|
|
|
|
method: "POST",
|
2017-09-11 12:14:07 +02:00
|
|
|
data: {"user_id": user_id, "amount": amount, "reason": reason}
|
2017-08-14 03:10:03 +02:00
|
|
|
});
|
|
|
|
return funct.promise();
|
|
|
|
}
|
|
|
|
|
2017-09-11 12:14:07 +02:00
|
|
|
function patchForm(user_id, amount, reason) {
|
2017-08-14 03:10:03 +02:00
|
|
|
var funct = $.ajax({
|
|
|
|
dataType: "json",
|
|
|
|
method: "PATCH",
|
2017-09-11 12:14:07 +02:00
|
|
|
data: {"user_id": user_id, "amount": amount, "reason": reason}
|
2017-08-14 03:10:03 +02:00
|
|
|
});
|
|
|
|
return funct.promise();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
$("#new_submit").click(function () {
|
|
|
|
var user_id = $("#new_user_id").val();
|
|
|
|
var user_token = $("#new_user_token").val();
|
2017-09-11 12:14:07 +02:00
|
|
|
var reason = $("#new_reason").val();
|
2017-08-14 03:10:03 +02:00
|
|
|
if (user_id.length < 1 || user_token.length < 1) {
|
|
|
|
Materialize.toast("The user ID or balance field can't be blank!", 2000);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-11 12:14:07 +02:00
|
|
|
var formPost = postForm(user_id, user_token, reason);
|
2017-08-14 03:10:03 +02:00
|
|
|
formPost.done(function (data) {
|
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
formPost.fail(function (data) {
|
|
|
|
if (data.status == 409) {
|
|
|
|
Materialize.toast('This user id already exists!', 10000);
|
|
|
|
} else {
|
|
|
|
Materialize.toast('Oh no! Something has failed submitting a new entry!', 10000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function submit_modify_user(user_id) {
|
|
|
|
var amount = $("#input_"+user_id).val();
|
2017-09-11 12:14:07 +02:00
|
|
|
var reason = $("#input_reason_"+user_id).val();
|
|
|
|
var formPatch = patchForm(user_id, amount, reason);
|
2017-08-14 03:10:03 +02:00
|
|
|
formPatch.done(function (data) {
|
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
formPatch.fail(function (data) {
|
|
|
|
if (data.status == 409) {
|
|
|
|
Materialize.toast('This user id does not exists!', 10000);
|
|
|
|
} else {
|
|
|
|
Materialize.toast('Oh no! Something has failed changing the css toggle!', 10000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|