diff --git a/Models/ThemeConfig/DeleteConfig.ts b/Models/ThemeConfig/DeleteConfig.ts index 36f6516937..8eb92041a7 100644 --- a/Models/ThemeConfig/DeleteConfig.ts +++ b/Models/ThemeConfig/DeleteConfig.ts @@ -5,7 +5,7 @@ import Translations from "../../UI/i18n/Translations" import { TagUtils } from "../../Logic/Tags/TagUtils" export default class DeleteConfig { - public static readonly defaultDeleteReasons: { + private static readonly defaultDeleteReasons: { changesetMessage: string explanation: Translation }[] = [ @@ -27,8 +27,8 @@ export default class DeleteConfig { }, ] - public readonly extraDeleteReasons?: { - explanation: TypedTranslation + public readonly deleteReasons?: { + explanation: TypedTranslation | Translation changesetMessage: string }[] @@ -38,7 +38,7 @@ export default class DeleteConfig { public readonly neededChangesets?: number constructor(json: DeleteConfigJson, context: string) { - this.extraDeleteReasons = (json.extraDeleteReasons ?? []).map((reason, i) => { + this.deleteReasons = (json.extraDeleteReasons ?? []).map((reason, i) => { const ctx = `${context}.extraDeleteReasons[${i}]` if ((reason.changesetMessage ?? "").length <= 5) { throw `${ctx}.explanation is too short, needs at least 4 characters` @@ -48,6 +48,16 @@ export default class DeleteConfig { changesetMessage: reason.changesetMessage, } }) + + if(!json.omitDefaultDeleteReasons ){ + for (const defaultDeleteReason of DeleteConfig.defaultDeleteReasons) { + this.deleteReasons.push({ + changesetMessage: defaultDeleteReason.changesetMessage, + explanation: defaultDeleteReason.explanation.Clone(/*Must clone, hides translation otherwise*/) + }) + } + } + this.nonDeleteMappings = (json.nonDeleteMappings ?? []).map((nonDelete, i) => { const ctx = `${context}.extraDeleteReasons[${i}]` return { @@ -56,6 +66,10 @@ export default class DeleteConfig { } }) + if(this.nonDeleteMappings.length + this.deleteReasons.length == 0){ + throw "At "+context+": a deleteconfig should have some reasons to delete: either the default delete reasons or a nonDeleteMapping or extraDeletereason should be given" + } + this.softDeletionTags = undefined if (json.softDeletionTags !== undefined) { this.softDeletionTags = TagUtils.Tag( diff --git a/Models/ThemeConfig/Json/DeleteConfigJson.ts b/Models/ThemeConfig/Json/DeleteConfigJson.ts index 84e2ec8899..653a040d0c 100644 --- a/Models/ThemeConfig/Json/DeleteConfigJson.ts +++ b/Models/ThemeConfig/Json/DeleteConfigJson.ts @@ -72,4 +72,10 @@ export interface DeleteConfigJson { * For some small features (e.g. bicycle racks) this is too much and this requirement can be lowered or dropped, which can be done here. */ neededChangesets?: number + + /** + * Set this flag if the default delete reasons should be omitted from the dialog. + * This requires at least one extraDeleteReason or nonDeleteMapping + */ + omitDefaultDeleteReasons?: false | boolean } diff --git a/UI/Popup/DeleteWizard.ts b/UI/Popup/DeleteWizard.ts index 862e660de0..b4803897cb 100644 --- a/UI/Popup/DeleteWizard.ts +++ b/UI/Popup/DeleteWizard.ts @@ -235,7 +235,7 @@ export default class DeleteWizard extends Toggle { return t.explanations.hardDelete } // This is a soft deletion: we explain _why_ the deletion is soft - return t.explanations.softDelete.Subs({ reason: reason }) + return t.explanations.softDelete.Subs({ reason: reason}) }) ) } @@ -263,7 +263,7 @@ export default class DeleteWizard extends Toggle { ) } - for (const extraDeleteReason of config.extraDeleteReasons ?? []) { + for (const extraDeleteReason of config.deleteReasons ?? []) { elements.push( new FixedInputElement( new SubstitutedTranslation(extraDeleteReason.explanation, tagsSource, state), @@ -274,17 +274,6 @@ export default class DeleteWizard extends Toggle { ) } - for (const extraDeleteReason of DeleteConfig.defaultDeleteReasons) { - elements.push( - new FixedInputElement( - extraDeleteReason.explanation.Clone(/*Must clone here, as this explanation might be used on many locations*/), - { - deleteReason: extraDeleteReason.changesetMessage, - } - ) - ) - } - return new RadioButton(elements, { selectFirstAsDefault: false }) } } @@ -453,7 +442,7 @@ class DeleteabilityChecker { return } if (waysOrRelations) { - // not deleteble by mapcomplete + // not deleteable by mapcomplete state.setData({ canBeDeleted: false, reason: t.partOfOthers,