From efdc676776394823a99663936ee7bee8b7571f45 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 4 Oct 2022 01:53:18 +0200 Subject: [PATCH] Ajout confirmation pour vider les conteneurs --- module/actor-sheet.js | 2 +- module/actor-vehicule-sheet.js | 2 +- module/actor.js | 29 ++++++++++++++++++----------- module/rdd-utility.js | 29 +++++++++++++++-------------- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 64000d44..1142e670 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -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(); }); diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js index 58699eb8..b2305320 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor-vehicule-sheet.js @@ -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(); }); diff --git a/module/actor.js b/module/actor.js index 9f87ef5d..54fe111f 100644 --- a/module/actor.js +++ b/module/actor.js @@ -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: `

Etes vous certain de vouloir vider tous les conteneurs ?

`, + 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) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index f5fd4d06..2d023f74 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -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: `

Etes vous certain de vouloir supprimer ${options.supprimer ?? 'cet objet'} ?

`, + title: options.title, + content: options.content, buttons: { - delete: { + action: { icon: '', - 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: `

Etes vous certain de vouloir supprimer le lien vers le véhicule/monture/suivant : ${subActor.name} ?

`, + 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 = "

Etes vous certain de vouloir supprimer cet objet ?"; + let msgTxt = '

Etes vous certain de vouloir supprimer cet objet ?'; let buttons = { delete: { icon: '', label: "Supprimer l'objet", callback: () => { - console.log("Delete : ", itemId); + console.log('Delete : ', itemId); sheet.actor.deleteEmbeddedDocuments('Item', [itemId], { renderSheet: false }); RdDUtility.slideOnDelete(sheet, htmlToDelete); }