2022-09-02 20:05:06 -07:00
|
|
|
import { post } from '@rails/request.js';
|
2022-01-08 15:55:40 -08:00
|
|
|
import { showErrorNotification, showNotification } from 'utilities/notifications';
|
|
|
|
import swal from 'sweetalert';
|
|
|
|
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2022-01-08 15:55:40 -08:00
|
|
|
|
|
|
|
export function answerboxDestroyHandler(event: Event): void {
|
|
|
|
event.preventDefault();
|
|
|
|
const button = event.target as HTMLButtonElement;
|
|
|
|
const answerId = button.dataset.aId;
|
|
|
|
|
|
|
|
swal({
|
|
|
|
title: I18n.translate('frontend.destroy_own.confirm.title'),
|
|
|
|
text: I18n.translate('frontend.destroy_own.confirm.text'),
|
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: "#DD6B55",
|
2022-07-30 09:50:46 -07:00
|
|
|
confirmButtonText: I18n.translate('voc.y'),
|
|
|
|
cancelButtonText: I18n.translate('voc.n'),
|
2022-01-08 15:55:40 -08:00
|
|
|
closeOnConfirm: true
|
|
|
|
}, (returnValue) => {
|
|
|
|
if (returnValue === false) {
|
|
|
|
button.disabled = false;
|
|
|
|
return;
|
|
|
|
}
|
2022-09-02 20:05:06 -07:00
|
|
|
|
|
|
|
post('/ajax/destroy_answer', {
|
|
|
|
body: {
|
2022-01-08 15:55:40 -08:00
|
|
|
answer: answerId
|
2022-09-02 20:05:06 -07:00
|
|
|
},
|
|
|
|
contentType: 'application/json'
|
|
|
|
})
|
|
|
|
.then(async response => {
|
|
|
|
const data = await response.json;
|
|
|
|
|
2022-01-08 15:55:40 -08:00
|
|
|
if (data.success) {
|
|
|
|
document.querySelector(`.answerbox[data-id="${answerId}"]`).remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
showNotification(data.message, data.success);
|
2022-09-02 20:05:06 -07:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
2022-01-08 15:55:40 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
2022-09-02 20:05:06 -07:00
|
|
|
});
|
2022-01-08 15:55:40 -08:00
|
|
|
});
|
|
|
|
}
|