2022-10-04 23:45:14 +02:00
|
|
|
import { Grammar } from "./grammar.js";
|
2022-10-04 23:23:43 +02:00
|
|
|
import { ReglesOptionelles } from "./regles-optionelles.js";
|
|
|
|
|
|
|
|
export class RdDConfirm {
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static confirmer(options, autresActions) {
|
|
|
|
options.bypass = options.bypass || !(options.settingConfirmer == undefined || ReglesOptionelles.isUsing(options.settingConfirmer));
|
|
|
|
if (options.bypass) {
|
|
|
|
options.onAction();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let buttons = {
|
|
|
|
"action": RdDConfirm._createButtonAction(options),
|
|
|
|
"cancel": RdDConfirm._createButtonCancel()
|
|
|
|
};
|
|
|
|
if (options.settingConfirmer) {
|
|
|
|
buttons = mergeObject(RdDConfirm._createButtonActionSave(options), buttons);
|
|
|
|
}
|
|
|
|
if (autresActions) {
|
|
|
|
buttons = mergeObject(autresActions, buttons);
|
|
|
|
}
|
|
|
|
const dialogDetails = {
|
|
|
|
title: options.title,
|
|
|
|
content: options.content,
|
|
|
|
default: "cancel",
|
|
|
|
buttons: buttons
|
|
|
|
};
|
2022-10-04 23:42:07 +02:00
|
|
|
new Dialog(dialogDetails, { width: 150 * Object.keys(buttons).length }).render(true);
|
2022-10-04 23:23:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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": {
|
2022-10-04 23:45:14 +02:00
|
|
|
icon: '<i class="fas fa-user-check"></i>',
|
|
|
|
label: "Toujours "+ options.buttonLabel.toLowerCase(),
|
2022-10-04 23:23:43 +02:00
|
|
|
callback: () => {
|
|
|
|
ReglesOptionelles.set(options.settingConfirmer, false);
|
|
|
|
options.onAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|