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;
|
2022-01-03 06:04:09 -08:00
|
|
|
element.disabled = true;
|
2022-01-02 18:26:28 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
}, (returnValue) => {
|
2022-01-03 06:04:09 -08:00
|
|
|
if (returnValue === false) {
|
|
|
|
element.disabled = false;
|
|
|
|
return;
|
|
|
|
}
|
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 => {
|
|
|
|
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
|
|
|
})
|
|
|
|
}
|