Titan/webapp/titanembeds/static/js/admin_cosmetics.js

150 lines
5.1 KiB
JavaScript
Raw Permalink Normal View History

/* global $, Materialize, location */
2019-11-06 22:45:48 +01:00
function postForm(user_id, css, css_limit, guest_icon, send_rich_embed, badges) {
if (css_limit == "") {
css_limit = 0;
}
var funct = $.ajax({
dataType: "json",
method: "POST",
2019-11-06 22:45:48 +01:00
data: {"user_id": user_id, "css": css, "css_limit": css_limit, "guest_icon": guest_icon, "send_rich_embed": send_rich_embed, "badges": badges}
});
return funct.promise();
}
function deleteForm(user_id) {
var funct = $.ajax({
dataType: "json",
method: "DELETE",
data: {"user_id": user_id}
});
return funct.promise();
}
function patchForm(user_id, param) {
var data = Object.assign({"user_id": user_id}, param);
var funct = $.ajax({
dataType: "json",
method: "PATCH",
data: data,
});
return funct.promise();
}
$(function() {
2017-12-07 07:49:32 +01:00
$('select').material_select();
$("#new_submit").click(function () {
var user_id = $("#new_user_id").val();
if (user_id.length < 1) {
Materialize.toast("The user ID field can't be blank!", 2000);
return;
}
var css_checked = $("#new_css_switch").is(':checked');
var css_limit = $("#new_css_limit").val();
var guest_icon_checked = $("#new_guest_icon_switch").is(':checked');
2019-11-06 22:45:48 +01:00
var send_rich_embed_checked = $("#new_send_rich_embed_switch").is(":checked");
2017-12-07 07:49:32 +01:00
var badges = $("#new_badges > option:selected").map(function(){ return this.value }).get().join();
2019-11-06 22:45:48 +01:00
var formPost = postForm(user_id, css_checked, css_limit, guest_icon_checked, send_rich_embed_checked, badges);
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 delete_user(user_id) {
var confirmation = confirm("Are you sure that you want to delete user?");
if (confirmation) {
var formDelete = deleteForm(user_id);
formDelete.done(function (data) {
location.reload();
});
formDelete.fail(function (data) {
if (data.status == 409) {
Materialize.toast('This user id does not exists!', 10000);
} else {
Materialize.toast('Oh no! Something has failed deleting this user entry!', 10000);
}
});
}
}
function update_css_switch(user_id, element) {
var css_checked = $(element).is(':checked');
var formPatch = patchForm(user_id, {"css": css_checked});
formPatch.done(function (data) {
Materialize.toast('CSS updated!', 10000);
});
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);
}
});
}
function update_css_limit(user_id, value) {
var formPatch = patchForm(user_id, {"css_limit": value});
formPatch.done(function (data) {
Materialize.toast('CSS value updated!', 10000);
});
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 limit field!', 10000);
}
});
}
function update_guest_icon_switch(user_id, element) {
var webhook_checked = $(element).is(':checked');
var formPatch = patchForm(user_id, {"guest_icon": webhook_checked});
formPatch.done(function (data) {
Materialize.toast('Guest Icon updated!', 10000);
});
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 guest icon toggle!', 10000);
}
});
2017-12-07 07:49:32 +01:00
}
2019-11-06 22:45:48 +01:00
function update_send_rich_embed_switch(user_id, element) {
var send_rich_checked = $(element).is(':checked');
var formPatch = patchForm(user_id, {"send_rich_embed": send_rich_checked});
formPatch.done(function (data) {
Materialize.toast('Send Rich Embed updated!', 10000);
});
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 send rich embed toggle!', 10000);
}
});
}
2017-12-07 07:49:32 +01:00
function update_badges(user_id, element) {
var badges = $(element).val().join();
var formPatch = patchForm(user_id, {"badges": badges});
formPatch.done(function (data) {
Materialize.toast('Badges updated!', 10000);
});
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 badges!', 10000);
}
});
}