From 61f04df765102dfb9b25d7d11042dfdbc160ae51 Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Tue, 8 Jul 2025 20:04:54 +0200 Subject: [PATCH] 289 - Confirm Delete Dialogs (#298) * Added confirm dialogs to delete * Localization fix --- lang/en.json | 4 +++ .../sheets-configs/adversary-settings.mjs | 12 +++++++++ .../sheets-configs/environment-settings.mjs | 22 ++++++++++++--- .../applications/sheets/actors/character.mjs | 22 ++++++++++++--- .../applications/sheets/api/actor-setting.mjs | 5 +++- .../sheets/api/application-mixin.mjs | 19 +++++++++++-- module/applications/sheets/api/base-item.mjs | 27 +++++++++++++++++++ 7 files changed, 101 insertions(+), 10 deletions(-) diff --git a/lang/en.json b/lang/en.json index 857a9387..75c8cfa7 100755 --- a/lang/en.json +++ b/lang/en.json @@ -213,6 +213,10 @@ "encounter": "Encounter" } }, + "DeleteConfirmation": { + "title": "Delete {type} - {name}", + "text": "Are you sure you want to delete {name}?" + }, "DamageReduction": { "armorMarks": "Armor Marks", "armorWithStress": "Spend 1 stress to use an extra mark", diff --git a/module/applications/sheets-configs/adversary-settings.mjs b/module/applications/sheets-configs/adversary-settings.mjs index d95e6129..57deea25 100644 --- a/module/applications/sheets-configs/adversary-settings.mjs +++ b/module/applications/sheets-configs/adversary-settings.mjs @@ -70,6 +70,18 @@ export default class DHAdversarySettings extends DHBaseActorSettings { * @type {ApplicationClickAction} */ static async #removeExperience(_, target) { + const experience = this.actor.system.experiences[target.dataset.experience]; + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize(`DAGGERHEART.GENERAL.Experience.single`), + name: experience.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: experience.name }) + }); + if (!confirmed) return; + await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null }); } diff --git a/module/applications/sheets-configs/environment-settings.mjs b/module/applications/sheets-configs/environment-settings.mjs index d0ca897a..7422f5fc 100644 --- a/module/applications/sheets-configs/environment-settings.mjs +++ b/module/applications/sheets-configs/environment-settings.mjs @@ -82,10 +82,24 @@ export default class DHEnvironmentSettings extends DHBaseActorSettings { static async #deleteAdversary(event, target) { const adversaryKey = target.dataset.adversary; const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`; - console.log(target.dataset.potentialAdversar); - const newAdversaries = foundry.utils - .getProperty(this.actor, path) - .filter(x => x && (x?.uuid ?? x) !== adversaryKey); + const property = foundry.utils.getProperty(this.actor, path); + const adversary = property.find(x => (x?.uuid ?? x) === adversaryKey); + + if (adversary) { + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize('TYPES.Actor.adversary'), + name: adversary.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: adversary.name }) + }); + + if (!confirmed) return; + } + + const newAdversaries = property.filter(x => x && (x?.uuid ?? x) !== adversaryKey); await this.actor.update({ [path]: newAdversaries }); } diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index 02e693d7..a77fe71f 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -249,7 +249,23 @@ export default class CharacterSheet extends DHBaseActorSheet { { name: 'DAGGERHEART.Sheets.PC.ContextMenu.Delete', icon: '', - callback: el => getItem(el).delete() + callback: async el => { + const item = getItem(el); + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize(`TYPES.${item.documentName}.${item.type}`), + name: item.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { + name: item.name + }) + }); + if (!confirmed) return; + + item.delete(); + } } ]; } @@ -372,7 +388,7 @@ export default class CharacterSheet extends DHBaseActorSheet { li.hidden = !(menu.has(item.id) && matchesSearch); } } - + /* -------------------------------------------- */ /* Filter Menus */ /* -------------------------------------------- */ @@ -495,7 +511,7 @@ export default class CharacterSheet extends DHBaseActorSheet { const config = { event: event, title: `${game.i18n.localize('DAGGERHEART.GENERAL.dualityRoll')}: ${this.actor.name}`, - headerTitle: game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilitychecktitle', { + headerTitle: game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', { ability: abilityLabel }), roll: { diff --git a/module/applications/sheets/api/actor-setting.mjs b/module/applications/sheets/api/actor-setting.mjs index 50e2b0a9..79aa1c37 100644 --- a/module/applications/sheets/api/actor-setting.mjs +++ b/module/applications/sheets/api/actor-setting.mjs @@ -42,9 +42,12 @@ export default class DHBaseActorSettings extends DHApplicationMixin(DocumentShee /**@inheritdoc */ async _prepareContext(options) { const context = await super._prepareContext(options); - context.systemFields.attack.fields = this.actor.system.attack.schema.fields; context.isNPC = this.actor.isNPC; + if (context.systemFields.attack) { + context.systemFields.attack.fields = this.actor.system.attack.schema.fields; + } + return context; } } diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index d0ef63d6..0e5f211d 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -218,7 +218,6 @@ export default function DHApplicationMixin(Base) { */ static async #createDoc(event, button) { const { documentClass, type } = button.dataset; - console.log(documentClass, type); const parent = this.document; const cls = getDocumentClass(documentClass); @@ -250,7 +249,23 @@ export default function DHApplicationMixin(Base) { */ static async #deleteDoc(_event, button) { const { type, docId } = button.dataset; - await this.document.getEmbeddedDocument(type, docId, { strict: true }).delete(); + const document = this.document.getEmbeddedDocument(type, docId, { strict: true }); + const typeName = game.i18n.localize( + document.type === 'base' ? `DOCUMENT.${type}` : `TYPES.${type}.${document.type}` + ); + + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: typeName, + name: document.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: document.name }) + }); + if (!confirmed) return; + + await document.delete(); } } diff --git a/module/applications/sheets/api/base-item.mjs b/module/applications/sheets/api/base-item.mjs index f9d52025..d624acc6 100644 --- a/module/applications/sheets/api/base-item.mjs +++ b/module/applications/sheets/api/base-item.mjs @@ -139,6 +139,19 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { static async #removeAction(event, button) { event.stopPropagation(); const actionIndex = button.closest('[data-index]').dataset.index; + const action = this.document.system.actions[actionIndex]; + + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize(`DAGGERHEART.GENERAL.Action.single`), + name: action.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: action.name }) + }); + if (!confirmed) return; + await this.document.update({ 'system.actions': this.document.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex)) }); @@ -180,6 +193,20 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { static async #removeFeature(event, button) { event.stopPropagation(); const target = button.closest('.feature-item'); + const feature = this.document.system.features.find(x => x && x.id === target.id); + + if (feature) { + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize(`TYPES.Item.feature`), + name: feature.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: feature.name }) + }); + if (!confirmed) return; + } await this.document.update({ 'system.features': this.document.system.features