2022-09-02 23:42:17 -07:00
|
|
|
import { post } from '@rails/request.js';
|
2022-01-07 17:52:19 -08:00
|
|
|
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2022-01-07 17:52:19 -08:00
|
|
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
|
|
|
|
|
|
|
export function banCheckboxHandler(event: Event): void {
|
|
|
|
const checkbox = event.target as HTMLInputElement;
|
|
|
|
|
|
|
|
if (checkbox.checked) {
|
|
|
|
document.querySelector('#ban-controls').classList.remove('d-none');
|
|
|
|
} else {
|
|
|
|
document.querySelector('#ban-controls').classList.add('d-none');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function permanentBanCheckboxHandler(event: Event): void {
|
|
|
|
const checkbox = event.target as HTMLInputElement;
|
|
|
|
|
|
|
|
if (checkbox.checked) {
|
|
|
|
document.querySelector('#ban-controls-time').classList.add('d-none');
|
|
|
|
} else {
|
|
|
|
document.querySelector('#ban-controls-time').classList.remove('d-none');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function banFormHandler(event: Event): void {
|
|
|
|
const form = event.target as HTMLFormElement;
|
|
|
|
const checkbox = document.querySelector<HTMLInputElement>('[name="ban"][type="checkbox"]');
|
|
|
|
const permaCheckbox = document.querySelector<HTMLInputElement>('[name="permaban"][type="checkbox"]');
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
ban: '0',
|
|
|
|
user: form.elements['user'].value,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (checkbox && checkbox.checked) {
|
|
|
|
data['ban'] = '1';
|
2022-06-26 00:35:22 -07:00
|
|
|
data['reason'] = form.elements['reason'].value;
|
2022-01-07 17:52:19 -08:00
|
|
|
|
|
|
|
if (!permaCheckbox.checked) {
|
|
|
|
data['duration'] = form.elements['duration'].value.trim();
|
|
|
|
data['duration_unit'] = form.elements['duration_unit'].value.trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 23:42:17 -07:00
|
|
|
post('/ajax/mod/ban', {
|
|
|
|
body: data,
|
|
|
|
contentType: 'application/json'
|
|
|
|
})
|
|
|
|
.then(async response => {
|
|
|
|
const data = await response.json;
|
|
|
|
|
2022-01-07 17:52:19 -08:00
|
|
|
showNotification(data.message, data.success);
|
2022-09-02 23:42:17 -07:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
2022-01-07 17:52:19 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
2022-09-02 23:42:17 -07:00
|
|
|
});
|
2022-01-07 17:52:19 -08:00
|
|
|
}
|