2022-09-02 23:43:19 -07:00
|
|
|
import { post } from '@rails/request.js';
|
2022-01-07 17:53:16 -08:00
|
|
|
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2022-01-07 17:53:16 -08:00
|
|
|
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;
|
|
|
|
|
2022-09-02 23:43:19 -07:00
|
|
|
post('/ajax/mod/privilege', {
|
|
|
|
body: {
|
2022-01-07 17:53:16 -08:00
|
|
|
user: checkbox.dataset.user,
|
|
|
|
type: privilegeType,
|
|
|
|
status: String(checkbox.checked)
|
2022-09-02 23:43:19 -07:00
|
|
|
},
|
|
|
|
contentType: 'application/json'
|
|
|
|
})
|
|
|
|
.then(async response => {
|
|
|
|
const data = await response.json;
|
|
|
|
|
2022-01-07 17:53:16 -08:00
|
|
|
if (data.success) {
|
|
|
|
checkbox.checked = data.checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
showNotification(data.message, data.success);
|
2022-09-02 23:43:19 -07:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
2022-01-07 17:53:16 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
|
|
|
checkbox.checked = false;
|
2022-09-02 23:43:19 -07:00
|
|
|
})
|
|
|
|
.finally(() => {
|
2022-01-07 17:53:16 -08:00
|
|
|
checkbox.disabled = false;
|
2022-09-02 23:43:19 -07:00
|
|
|
});
|
2022-01-07 17:53:16 -08:00
|
|
|
}
|