Port moderator privilege feature to TypeScript

This commit is contained in:
Andreas Nedbal 2022-01-08 02:53:16 +01:00 committed by Andreas Nedbal
parent 54b9791dc3
commit 9e2a9a2be9
1 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,64 @@
import Rails from '@rails/ujs';
import I18n from '../../../legacy/i18n';
import { showNotification, showErrorNotification } from 'utilities/notifications';
export function privilegeCheckHandler(event: Event): void {
const checkbox = event.target as HTMLInputElement;
checkbox.disabled = true;
const privilegeType = checkbox.dataset.type;
Rails.ajax({
url: '/ajax/mod/privilege',
type: 'POST',
data: new URLSearchParams({
user: checkbox.dataset.user,
type: privilegeType,
status: String(checkbox.checked)
}).toString(),
success: (data) => {
if (data.success) {
checkbox.checked = data.checked;
}
showNotification(data.message, data.success);
},
error: (data, status, xhr) => {
console.log(data, status, xhr);
showErrorNotification(I18n.translate('frontend.error.message'));
checkbox.checked = false;
},
complete: () => {
checkbox.disabled = false;
}
});
/*
($ document).on "click", "input[type=checkbox][name=check-your-privileges]", ->
box = $(this)
box.attr 'disabled', 'disabled'
privType = box[0].dataset.type
boxChecked = box[0].checked
$.ajax
url: '/ajax/mod/privilege'
type: 'POST'
data:
user: box[0].dataset.user
type: privType
status: boxChecked
success: (data, status, jqxhr) ->
if data.success
box[0].checked = if data.checked? then data.checked else !boxChecked
showNotification data.message, data.success
error: (jqxhr, status, error) ->
box[0].checked = false
console.log jqxhr, status, error
showNotification translate('frontend.error.message'), false
complete: (jqxhr, status) ->
box.removeAttr "disabled"
*/
}