foundryvtt-reve-de-dragon/module/rdd-confirm.js
Vincent Vandemeulebrouck 99f29cb95b Fix confirmation de suppression
Lors de la suppression, la demande de confirmation était toujours
faite, même si on indiquait de ne plus demander
2024-06-29 00:12:31 +02:00

52 lines
1.6 KiB
JavaScript

import { ReglesOptionnelles } from "./settings/regles-optionnelles.js";
export class RdDConfirm {
/* -------------------------------------------- */
static confirmer(options, autresActions) {
if (options.settingConfirmer && !ReglesOptionnelles.isSet(options.settingConfirmer)) {
return options.onAction()
}
let buttons = {
"action": RdDConfirm._createButtonAction(options),
"cancel": RdDConfirm._createButtonCancel()
};
if (options.settingConfirmer) {
buttons = foundry.utils.mergeObject(RdDConfirm._createButtonActionSave(options), buttons);
}
if (autresActions) {
buttons = foundry.utils.mergeObject(autresActions, buttons, { inplace: false });
}
const dialogDetails = {
title: options.title,
content: options.content,
default: "cancel",
buttons: buttons
};
new Dialog(dialogDetails, { width: 150 * Object.keys(buttons).length }).render(true);
}
static _createButtonCancel() {
return { icon: '<i class="fas fa-times"></i>', label: "Annuler" };
}
static _createButtonAction(options) {
return {
icon: '<i class="fas fa-check"></i>',
label: options.buttonLabel,
callback: () => options.onAction()
};
}
static _createButtonActionSave(options) {
return {
"actionSave": {
icon: '<i class="fas fa-user-check"></i>',
label: options.buttonLabel + "<br>et ne plus demander",
callback: () => {
ReglesOptionnelles.set(options.settingConfirmer, false);
options.onAction();
}
}
};
}
}