Ajout confirmation pour vider les conteneurs

This commit is contained in:
Vincent Vandemeulebrouck 2022-10-04 01:53:18 +02:00
parent d25c6b7f1c
commit efdc676776
4 changed files with 35 additions and 27 deletions

View File

@ -234,7 +234,7 @@ export class RdDActorSheet extends ActorSheet {
html.find('.creer-une-oeuvre').click(async event => {
RdDUtility.selectTypeOeuvre(this);
});
html.find('#nettoyer-conteneurs').click(async event => {
html.find('.nettoyer-conteneurs').click(async event => {
this.actor.nettoyerConteneurs();
});

View File

@ -125,7 +125,7 @@ export class RdDActorVehiculeSheet extends ActorSheet {
html.find('.creer-un-objet').click(async event => {
RdDUtility.selectObjetType(this);
});
html.find('#nettoyer-conteneurs').click(async event => {
html.find('.nettoyer-conteneurs').click(async event => {
this.actor.nettoyerConteneurs();
});

View File

@ -1163,18 +1163,25 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
/** Fonction de remise à plat de l'équipement (ie vide les champs 'contenu') */
async nettoyerConteneurs() {
const corrections = [];
for (let item of this.items) {
if (item.estContenu) {
item.estContenu = undefined;
RdDUtility.confirmer({
content: `<p>Etes vous certain de vouloir vider tous les conteneurs ?</p>`,
title: 'Vider les conteneurs',
buttonLabel: 'Vider',
onAction: async () => {
const corrections = [];
for (let item of this.items) {
if (item.estContenu) {
item.estContenu = undefined;
}
if (item.type == 'conteneur' && item.system.contenu.length > 0) {
corrections.push({ _id: item.id, 'system.contenu': [] });
}
}
if (corrections.length > 0) {
await this.updateEmbeddedDocuments('Item', corrections);
}
}
if (item.type == 'conteneur' && item.system.contenu.length > 0) {
corrections.push({ _id: item.id, 'system.contenu': [] });
}
}
if (corrections.length > 0) {
await this.updateEmbeddedDocuments('Item', corrections);
}
});
}
async processDropItem(params) {

View File

@ -855,17 +855,16 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static confirmerSuppression(sheet, htmlToDelete, options) {
static confirmer(options) {
const d = new Dialog({
title: options.title ?? 'Confirmer la suppression',
content: `<p>Etes vous certain de vouloir supprimer ${options.supprimer ?? 'cet objet'} ?</p>`,
title: options.title,
content: options.content,
buttons: {
delete: {
action: {
icon: '<i class="fas fa-check"></i>',
label: options.deleteLabel ?? 'Supprimer',
label: options.buttonLabel,
callback: () => {
options.onDelete();
RdDUtility.slideOnDelete(sheet, htmlToDelete);
options.onAction();
}
},
cancel: {
@ -880,12 +879,14 @@ export class RdDUtility {
/* -------------------------------------------- */
static confirmerSuppressionSubacteur(sheet, subActor, htmlToDelete) {
RdDUtility.confirmerSuppression(sheet, htmlToDelete,{
supprimer: "le lien vers le véhicule/monture/suivant : " + subActor.name,
deleteLabel: "Supprimer le lien",
onDelete: () => {
console.log("Delete : ", subActor.id);
RdDUtility.confirmer({
content: `<p>Etes vous certain de vouloir supprimer le lien vers le véhicule/monture/suivant : ${subActor.name} ?</p>`,
title: 'Confirmer la suppression',
buttonLabel: 'Supprimer le lien',
onAction: () => {
console.log('Delete : ', subActor.id);
sheet.actor.removeSubacteur(subActor.id);
RdDUtility.slideOnDelete(sheet, htmlToDelete);
}
})
}
@ -898,13 +899,13 @@ export class RdDUtility {
return;
}
let msgTxt = "<p>Etes vous certain de vouloir supprimer cet objet ?";
let msgTxt = '<p>Etes vous certain de vouloir supprimer cet objet ?';
let buttons = {
delete: {
icon: '<i class="fas fa-check"></i>',
label: "Supprimer l'objet",
callback: () => {
console.log("Delete : ", itemId);
console.log('Delete : ', itemId);
sheet.actor.deleteEmbeddedDocuments('Item', [itemId], { renderSheet: false });
RdDUtility.slideOnDelete(sheet, htmlToDelete);
}