2022-09-02 21:57:52 -07:00
|
|
|
import { post } from '@rails/request.js';
|
2022-01-02 18:26:28 -08:00
|
|
|
import swal from 'sweetalert';
|
|
|
|
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2022-01-02 18:26:28 -08:00
|
|
|
import { updateDeleteButton } from '../delete';
|
|
|
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
|
|
|
|
|
|
|
export function deleteEntryHandler(event: Event): void {
|
|
|
|
const element: HTMLButtonElement = event.target as HTMLButtonElement;
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
id: element.getAttribute('data-ib-id')
|
|
|
|
};
|
|
|
|
|
|
|
|
swal({
|
2022-01-02 19:36:45 -08:00
|
|
|
title: I18n.translate('frontend.inbox.confirm.title'),
|
|
|
|
text: I18n.translate('frontend.inbox.confirm.text'),
|
2022-01-02 18:26:28 -08:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: "#DD6B55",
|
2022-07-30 09:50:46 -07:00
|
|
|
confirmButtonText: I18n.translate('voc.delete'),
|
|
|
|
cancelButtonText: I18n.translate('voc.cancel'),
|
2022-01-02 18:26:28 -08:00
|
|
|
closeOnConfirm: true
|
2023-11-06 15:58:21 -08:00
|
|
|
}, () => {
|
|
|
|
element.disabled = true;
|
2022-09-02 21:57:52 -07:00
|
|
|
|
|
|
|
post('/ajax/delete_inbox', {
|
|
|
|
body: data,
|
|
|
|
contentType: 'application/json'
|
|
|
|
})
|
|
|
|
.then(async response => {
|
|
|
|
const data = await response.json;
|
|
|
|
|
2022-01-02 18:26:28 -08:00
|
|
|
if (!data.success) return false;
|
|
|
|
const inboxEntry: Node = element.closest('.inbox-entry');
|
|
|
|
|
|
|
|
updateDeleteButton(false);
|
|
|
|
showNotification(data.message);
|
|
|
|
|
|
|
|
(inboxEntry as HTMLElement).remove();
|
2022-09-02 21:57:52 -07:00
|
|
|
})
|
|
|
|
.catch(err => {
|
2023-11-06 15:58:21 -08:00
|
|
|
element.disabled = false;
|
2022-09-02 21:57:52 -07:00
|
|
|
console.log(err);
|
2022-01-02 19:36:45 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
2022-09-02 21:57:52 -07:00
|
|
|
});
|
2022-01-02 18:26:28 -08:00
|
|
|
})
|
|
|
|
}
|