mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 18:06:36 +00:00
Use ha-dialog for dialog-area-registry-detail (#7508)
This commit is contained in:
parent
40b2387667
commit
a72183851a
@ -10,7 +10,8 @@ import {
|
|||||||
internalProperty,
|
internalProperty,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import "../../../components/dialog/ha-paper-dialog";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
import "../../../components/ha-dialog";
|
||||||
import { AreaRegistryEntryMutableParams } from "../../../data/area_registry";
|
import { AreaRegistryEntryMutableParams } from "../../../data/area_registry";
|
||||||
import { PolymerChangedEvent } from "../../../polymer-types";
|
import { PolymerChangedEvent } from "../../../polymer-types";
|
||||||
import { haStyleDialog } from "../../../resources/styles";
|
import { haStyleDialog } from "../../../resources/styles";
|
||||||
@ -37,6 +38,12 @@ class DialogAreaDetail extends LitElement {
|
|||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public closeDialog(): void {
|
||||||
|
this._error = "";
|
||||||
|
this._params = undefined;
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this._params) {
|
if (!this._params) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -44,17 +51,14 @@ class DialogAreaDetail extends LitElement {
|
|||||||
const entry = this._params.entry;
|
const entry = this._params.entry;
|
||||||
const nameInvalid = !this._isNameValid();
|
const nameInvalid = !this._isNameValid();
|
||||||
return html`
|
return html`
|
||||||
<ha-paper-dialog
|
<ha-dialog
|
||||||
with-backdrop
|
open
|
||||||
opened
|
@closed=${this.closeDialog}
|
||||||
@opened-changed="${this._openedChanged}"
|
.heading=${entry
|
||||||
|
? entry.name
|
||||||
|
: this.hass.localize("ui.panel.config.areas.editor.default_name")}
|
||||||
>
|
>
|
||||||
<h2>
|
<div>
|
||||||
${entry
|
|
||||||
? entry.name
|
|
||||||
: this.hass.localize("ui.panel.config.areas.editor.default_name")}
|
|
||||||
</h2>
|
|
||||||
<paper-dialog-scrollable>
|
|
||||||
${this._error ? html` <div class="error">${this._error}</div> ` : ""}
|
${this._error ? html` <div class="error">${this._error}</div> ` : ""}
|
||||||
<div class="form">
|
<div class="form">
|
||||||
${entry
|
${entry
|
||||||
@ -79,29 +83,29 @@ class DialogAreaDetail extends LitElement {
|
|||||||
.invalid=${nameInvalid}
|
.invalid=${nameInvalid}
|
||||||
></paper-input>
|
></paper-input>
|
||||||
</div>
|
</div>
|
||||||
</paper-dialog-scrollable>
|
|
||||||
<div class="paper-dialog-buttons">
|
|
||||||
${entry
|
|
||||||
? html`
|
|
||||||
<mwc-button
|
|
||||||
class="warning"
|
|
||||||
@click="${this._deleteEntry}"
|
|
||||||
.disabled=${this._submitting}
|
|
||||||
>
|
|
||||||
${this.hass.localize("ui.panel.config.areas.editor.delete")}
|
|
||||||
</mwc-button>
|
|
||||||
`
|
|
||||||
: html``}
|
|
||||||
<mwc-button
|
|
||||||
@click="${this._updateEntry}"
|
|
||||||
.disabled=${nameInvalid || this._submitting}
|
|
||||||
>
|
|
||||||
${entry
|
|
||||||
? this.hass.localize("ui.panel.config.areas.editor.update")
|
|
||||||
: this.hass.localize("ui.panel.config.areas.editor.create")}
|
|
||||||
</mwc-button>
|
|
||||||
</div>
|
</div>
|
||||||
</ha-paper-dialog>
|
${entry
|
||||||
|
? html`
|
||||||
|
<mwc-button
|
||||||
|
slot="secondaryAction"
|
||||||
|
class="warning"
|
||||||
|
@click="${this._deleteEntry}"
|
||||||
|
.disabled=${this._submitting}
|
||||||
|
>
|
||||||
|
${this.hass.localize("ui.panel.config.areas.editor.delete")}
|
||||||
|
</mwc-button>
|
||||||
|
`
|
||||||
|
: html``}
|
||||||
|
<mwc-button
|
||||||
|
slot="primaryAction"
|
||||||
|
@click="${this._updateEntry}"
|
||||||
|
.disabled=${nameInvalid || this._submitting}
|
||||||
|
>
|
||||||
|
${entry
|
||||||
|
? this.hass.localize("ui.panel.config.areas.editor.update")
|
||||||
|
: this.hass.localize("ui.panel.config.areas.editor.create")}
|
||||||
|
</mwc-button>
|
||||||
|
</ha-dialog>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,12 +156,6 @@ class DialogAreaDetail extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _openedChanged(ev: PolymerChangedEvent<boolean>): void {
|
|
||||||
if (!(ev.detail as any).value) {
|
|
||||||
this._params = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
return [
|
return [
|
||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
@ -165,9 +163,6 @@ class DialogAreaDetail extends LitElement {
|
|||||||
.form {
|
.form {
|
||||||
padding-bottom: 24px;
|
padding-bottom: 24px;
|
||||||
}
|
}
|
||||||
mwc-button.warning {
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
.error {
|
.error {
|
||||||
color: var(--error-color);
|
color: var(--error-color);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user