2021-12-28 12:13:30 -08:00
|
|
|
import Rails from '@rails/ujs';
|
|
|
|
import swal from 'sweetalert';
|
2022-01-02 19:31:41 -08:00
|
|
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
2022-01-13 14:25:46 -08:00
|
|
|
import I18n from 'retrospring/i18n';
|
2021-12-28 12:13:30 -08:00
|
|
|
|
|
|
|
export function destroyListHandler(event: Event): void {
|
|
|
|
event.preventDefault();
|
|
|
|
const button = event.target as HTMLButtonElement;
|
|
|
|
const list = button.dataset.list;
|
|
|
|
|
|
|
|
swal({
|
2021-12-28 12:29:08 -08:00
|
|
|
title: I18n.translate('frontend.list.confirm.title'),
|
|
|
|
text: I18n.translate('frontend.list.confirm.text'),
|
2021-12-28 12:13:30 -08:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: "#DD6B55",
|
|
|
|
confirmButtonText: I18n.translate('views.actions.delete'),
|
|
|
|
cancelButtonText: I18n.translate('views.actions.cancel'),
|
|
|
|
closeOnConfirm: true
|
|
|
|
}, () => {
|
|
|
|
Rails.ajax({
|
|
|
|
url: '/ajax/destroy_list',
|
|
|
|
type: 'POST',
|
|
|
|
data: new URLSearchParams({
|
|
|
|
list: list
|
|
|
|
}).toString(),
|
|
|
|
success: (data) => {
|
|
|
|
if (data.success) {
|
|
|
|
const element = document.querySelector(`li.list-group-item#list-${list}`);
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
element.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-02 19:31:41 -08:00
|
|
|
showNotification(data.message, data.success);
|
2021-12-28 12:13:30 -08:00
|
|
|
},
|
|
|
|
error: (data, status, xhr) => {
|
|
|
|
console.log(data, status, xhr);
|
2022-01-02 19:31:41 -08:00
|
|
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
2021-12-28 12:13:30 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|