diff --git a/src/panels/config/areas/ha-config-areas.ts b/src/panels/config/areas/ha-config-areas.ts index c7b767480a..7c5212bb5d 100644 --- a/src/panels/config/areas/ha-config-areas.ts +++ b/src/panels/config/areas/ha-config-areas.ts @@ -31,6 +31,7 @@ import { classMap } from "lit-html/directives/class-map"; import { computeRTL } from "../../../common/util/compute_rtl"; import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { configSections } from "../ha-panel-config"; +import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; @customElement("ha-config-areas") export class HaConfigAreas extends LitElement { @@ -150,9 +151,16 @@ export class HaConfigAreas extends LitElement { updateAreaRegistryEntry(this.hass!, entry!.area_id, values), removeEntry: async () => { if ( - !confirm(`Are you sure you want to delete this area? - -All devices in this area will become unassigned.`) + !(await showConfirmationDialog(this, { + title: this.hass.localize( + "ui.panel.config.areas.delete.confirmation_title" + ), + text: this.hass.localize( + "ui.panel.config.areas.delete.confirmation_text" + ), + dismissText: this.hass.localize("ui.common.no"), + confirmText: this.hass.localize("ui.common.yes"), + })) ) { return false; } diff --git a/src/panels/config/automation/action/ha-automation-action-row.ts b/src/panels/config/automation/action/ha-automation-action-row.ts index 43f756ae84..15d5f6b1df 100644 --- a/src/panels/config/automation/action/ha-automation-action-row.ts +++ b/src/panels/config/automation/action/ha-automation-action-row.ts @@ -16,6 +16,7 @@ import { dynamicElement } from "../../../../common/dom/dynamic-element-directive import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-card"; import { HomeAssistant } from "../../../../types"; +import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box"; import { Action } from "../../../../data/script"; @@ -206,15 +207,16 @@ export default class HaAutomationActionRow extends LitElement { } private _onDelete() { - if ( - confirm( - this.hass.localize( - "ui.panel.config.automation.editor.actions.delete_confirm" - ) - ) - ) { - fireEvent(this, "value-changed", { value: null }); - } + showConfirmationDialog(this, { + text: this.hass.localize( + "ui.panel.config.automation.editor.actions.delete_confirm" + ), + dismissText: this.hass.localize("ui.common.no"), + confirmText: this.hass.localize("ui.common.yes"), + confirm: () => { + fireEvent(this, "value-changed", { value: null }); + }, + }); } private _typeChanged(ev: CustomEvent) { diff --git a/src/panels/config/automation/condition/ha-automation-condition-row.ts b/src/panels/config/automation/condition/ha-automation-condition-row.ts index 111fd49a1b..e96beacab1 100644 --- a/src/panels/config/automation/condition/ha-automation-condition-row.ts +++ b/src/panels/config/automation/condition/ha-automation-condition-row.ts @@ -12,6 +12,7 @@ import { import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-card"; import { HomeAssistant } from "../../../../types"; +import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box"; import "./ha-automation-condition-editor"; import { Condition } from "../../../../data/automation"; @@ -104,15 +105,16 @@ export default class HaAutomationConditionRow extends LitElement { } private _onDelete() { - if ( - confirm( - this.hass.localize( - "ui.panel.config.automation.editor.conditions.delete_confirm" - ) - ) - ) { - fireEvent(this, "value-changed", { value: null }); - } + showConfirmationDialog(this, { + text: this.hass.localize( + "ui.panel.config.automation.editor.conditions.delete_confirm" + ), + dismissText: this.hass.localize("ui.common.no"), + confirmText: this.hass.localize("ui.common.yes"), + confirm: () => { + fireEvent(this, "value-changed", { value: null }); + }, + }); } private _switchYamlMode() { diff --git a/src/panels/config/automation/trigger/ha-automation-trigger-row.ts b/src/panels/config/automation/trigger/ha-automation-trigger-row.ts index 3559ca2053..0cce5fa0be 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger-row.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger-row.ts @@ -16,6 +16,7 @@ import { dynamicElement } from "../../../../common/dom/dynamic-element-directive import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-card"; import { HomeAssistant } from "../../../../types"; +import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box"; import "./types/ha-automation-trigger-device"; import "./types/ha-automation-trigger-event"; @@ -180,15 +181,16 @@ export default class HaAutomationTriggerRow extends LitElement { } private _onDelete() { - if ( - confirm( - this.hass.localize( - "ui.panel.config.automation.editor.triggers.delete_confirm" - ) - ) - ) { - fireEvent(this, "value-changed", { value: null }); - } + showConfirmationDialog(this, { + text: this.hass.localize( + "ui.panel.config.automation.editor.triggers.delete_confirm" + ), + dismissText: this.hass.localize("ui.common.no"), + confirmText: this.hass.localize("ui.common.yes"), + confirm: () => { + fireEvent(this, "value-changed", { value: null }); + }, + }); } private _typeChanged(ev: CustomEvent) { diff --git a/src/panels/config/cloud/dialog-manage-cloudhook/dialog-manage-cloudhook.ts b/src/panels/config/cloud/dialog-manage-cloudhook/dialog-manage-cloudhook.ts index 7d4feea6d2..b619490d2c 100644 --- a/src/panels/config/cloud/dialog-manage-cloudhook/dialog-manage-cloudhook.ts +++ b/src/panels/config/cloud/dialog-manage-cloudhook/dialog-manage-cloudhook.ts @@ -13,6 +13,7 @@ import { PaperInputElement } from "@polymer/paper-input/paper-input"; import { HomeAssistant } from "../../../../types"; import { haStyle } from "../../../../resources/styles"; import { WebhookDialogParams } from "./show-dialog-manage-cloudhook"; +import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box"; const inputLabel = "Public URL – Click to copy to clipboard"; @@ -108,18 +109,17 @@ export class DialogManageCloudhook extends LitElement { } private async _disableWebhook() { - if ( - !confirm( - this.hass!.localize( - "ui.panel.config.cloud.dialog_cloudhook.confirm_disable" - ) - ) - ) { - return; - } - - this._params!.disableHook(); - this._closeDialog(); + showConfirmationDialog(this, { + text: this.hass!.localize( + "ui.panel.config.cloud.dialog_cloudhook.confirm_disable" + ), + dismissText: this.hass!.localize("ui.common.no"), + confirmText: this.hass!.localize("ui.common.yes"), + confirm: () => { + this._params!.disableHook(); + this._closeDialog(); + }, + }); } private _copyClipboard(ev: FocusEvent) { diff --git a/src/panels/config/person/ha-config-person.ts b/src/panels/config/person/ha-config-person.ts index 59aa055f0a..bfc718dfba 100644 --- a/src/panels/config/person/ha-config-person.ts +++ b/src/panels/config/person/ha-config-person.ts @@ -29,6 +29,7 @@ import { } from "./show-dialog-person-detail"; import { User, fetchUsers } from "../../../data/user"; import { configSections } from "../ha-panel-config"; +import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; class HaConfigPerson extends LitElement { @property() public hass?: HomeAssistant; @@ -189,11 +190,12 @@ class HaConfigPerson extends LitElement { }, removeEntry: async () => { if ( - !confirm(`${this.hass!.localize( - "ui.panel.config.person.confirm_delete" - )} - -${this.hass!.localize("ui.panel.config.person.confirm_delete2")}`) + !(await showConfirmationDialog(this, { + title: this.hass!.localize("ui.panel.config.person.confirm_delete"), + text: this.hass!.localize("ui.panel.config.person.confirm_delete2"), + dismissText: this.hass!.localize("ui.common.no"), + confirmText: this.hass!.localize("ui.common.yes"), + })) ) { return false; } diff --git a/src/panels/config/zone/ha-config-zone.ts b/src/panels/config/zone/ha-config-zone.ts index b441c09379..75a4bd6d6a 100644 --- a/src/panels/config/zone/ha-config-zone.ts +++ b/src/panels/config/zone/ha-config-zone.ts @@ -422,9 +422,12 @@ export class HaConfigZone extends SubscribeMixin(LitElement) { private async _removeEntry(entry: Zone) { if ( - !confirm(`${this.hass!.localize("ui.panel.config.zone.confirm_delete")} - -${this.hass!.localize("ui.panel.config.zone.confirm_delete2")}`) + !(await showConfirmationDialog(this, { + title: this.hass!.localize("ui.panel.config.zone.confirm_delete"), + text: this.hass!.localize("ui.panel.config.zone.confirm_delete2"), + dismissText: this.hass!.localize("ui.common.no"), + confirmText: this.hass!.localize("ui.common.yes"), + })) ) { return false; } diff --git a/src/panels/lovelace/hui-editor.ts b/src/panels/lovelace/hui-editor.ts index a66dd52e7f..17b76f8bd1 100644 --- a/src/panels/lovelace/hui-editor.ts +++ b/src/panels/lovelace/hui-editor.ts @@ -168,19 +168,19 @@ class LovelaceFullConfigEditor extends LitElement { private _closeEditor() { if (this._changed) { - if ( - !confirm( - this.hass.localize( - "ui.panel.lovelace.editor.raw_editor.confirm_unsaved_changes" - ) - ) - ) { - return; - } - } - window.onbeforeunload = null; - if (this.closeEditor) { - this.closeEditor(); + showConfirmationDialog(this, { + text: this.hass.localize( + "ui.panel.lovelace.editor.raw_editor.confirm_unsaved_changes" + ), + dismissText: this.hass!.localize("ui.common.no"), + confirmText: this.hass!.localize("ui.common.yes"), + confirm: () => { + window.onbeforeunload = null; + if (this.closeEditor) { + this.closeEditor(); + } + }, + }); } } @@ -188,13 +188,13 @@ class LovelaceFullConfigEditor extends LitElement { try { await this.lovelace!.deleteConfig(); } catch (err) { - alert( - this.hass.localize( + showAlertDialog(this, { + text: this.hass.localize( "ui.panel.lovelace.editor.raw_editor.error_remove", "error", err - ) - ); + ), + }); } window.onbeforeunload = null; if (this.closeEditor) { diff --git a/src/translations/en.json b/src/translations/en.json index 11d6338bec..371067b730 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -796,6 +796,10 @@ "delete": "DELETE", "update": "UPDATE", "create": "CREATE" + }, + "delete": { + "confirmation_title": "Are you sure you want to delete this area?", + "confirmation_text": "All devices in this area will become unassigned." } }, "helpers": { @@ -1015,7 +1019,7 @@ "add": "Add trigger", "duplicate": "Duplicate", "delete": "[%key:ui::panel::mailbox::delete_button%]", - "delete_confirm": "Sure you want to delete?", + "delete_confirm": "Are you sure you want to delete this?", "unsupported_platform": "Unsupported platform: {platform}", "type_select": "Trigger type", "type": {