45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import type { SweetAlertResult } from "sweetalert2";
|
|
import sweetalert from "../modules/sweetalertConfirm";
|
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
|
// Submit button clone.
|
|
const submit = document.getElementById("formSubmit"),
|
|
submitClone = document.getElementById("formSubmitClone");
|
|
|
|
if(submitClone && submit) {
|
|
submitClone.addEventListener("click", (event) => {
|
|
event.preventDefault();
|
|
submit.click();
|
|
return false;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Popup delete item.
|
|
*/
|
|
const elements = document.getElementsByClassName(
|
|
"confirmDeleteTS"
|
|
) as HTMLCollectionOf<Element>;
|
|
for (const element of elements) {
|
|
element.addEventListener("submit", function (e) {
|
|
e.preventDefault();
|
|
const el = e.target;
|
|
if (!el || !(el instanceof HTMLFormElement)) {
|
|
throw new Error(
|
|
"confirmDoneJS can only be executed on an exising form"
|
|
);
|
|
}
|
|
sweetalert.methods.confirm(
|
|
"Êtes-vous sûr ?",
|
|
"Toutes les données vont être perdu",
|
|
el as HTMLFormElement,
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
function (response: SweetAlertResult<any>) {
|
|
(el as HTMLFormElement).submit();
|
|
},
|
|
{ icon: "warning" }
|
|
);
|
|
return false;
|
|
});
|
|
}
|
|
});
|