Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix message dialog confirm button

Robin Dekkers647b9d81de19
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.ts
index 85069b643..d5bc02467 100644
--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.ts
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.ts
@@ -31,10 +31,10 @@ export class OrRuleFormMessage extends translate(i18next)(LitElement) {
const message:EmailNotificationMessage | undefined = this.action.notification!.message;
return html`
- <div style="display:grid">
+ <form style="display:grid">
<or-input value="${message && message.subject ? message.subject : ""}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionNotificationName(e.detail.value, "subject")}" .label="${i18next.t("subject")}" type="${InputType.TEXT}" required placeholder=" "></or-input>
<or-input value="${message && message.html ? message.html : ""}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionNotificationName(e.detail.value, "html")}" .label="${i18next.t("message")}" type="${InputType.TEXTAREA}" required placeholder=" " ></or-input>
- </div>
+ </form>
`
}
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts
index 1c0258491..44373d5ec 100644
--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts
@@ -28,6 +28,16 @@ export class OrRuleFormPushNotification extends translate(i18next)(LitElement) {
`
}
+ protected updated(_changedProperties: Map<PropertyKey, unknown>): void {
+ if(_changedProperties.has("action")) {
+ let message:PushNotificationMessage | undefined = this.action.notification!.message;
+ if(this.action.notification && message && !message.action) {
+ message = {action: {openInBrowser: true}}
+ this.action.notification.message = {...this.action.notification.message, ...message};
+ }
+ }
+ }
+
protected render() {
const message:PushNotificationMessage | undefined = this.action.notification!.message;
const title = message && message.title ? message.title : "";
diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts
index 9514047bf..e27f1b080 100644
--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts
+++ b/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts
@@ -10,7 +10,32 @@ import i18next from "i18next";
import {translate} from "@openremote/or-translate";
import {DialogAction, OrMwcDialog, OrMwcDialogOpenedEvent} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
-
+const checkValidity = (form:HTMLElement | null, dialog:OrMwcDialog) => {
+ if(form) {
+ const inputs = form.querySelectorAll('or-input')
+ const elements = Array.prototype.slice.call(inputs);
+
+ const valid = elements.every((element) => {
+ if(element.shadowRoot) {
+ const input = element.shadowRoot.querySelector('input, textarea, select') as any
+
+ if(input && input.checkValidity()) {
+ return true
+ } else {
+ element._mdcComponent.valid = false;
+ element._mdcComponent.helperTextContent = 'required';
+
+ return false;
+ }
+ } else {
+ return false;
+ }
+ })
+ if(valid) {
+ dialog.close();
+ }
+ }
+}
@customElement("or-rule-notification-modal")
export class OrRuleNotificationModal extends translate(i18next)(LitElement) {
@@ -55,38 +80,23 @@ export class OrRuleNotificationModal extends translate(i18next)(LitElement) {
this.renderDialogHTML(this.action);
}
}
+
+
checkForm() {
const dialog: OrMwcDialog = this.shadowRoot!.host as OrMwcDialog;
- if (this.shadowRoot && this.shadowRoot.querySelector('or-rule-form-push-notification')) {
+
+ if (this.shadowRoot) {
+ const messageNotification = this.shadowRoot.querySelector('or-rule-form-message');
const pushNotification = this.shadowRoot.querySelector('or-rule-form-push-notification');
+
if(pushNotification && pushNotification.shadowRoot) {
const form = pushNotification.shadowRoot.querySelector('form')
- if(form) {
- const inputs = form.querySelectorAll('or-input')
- const elements = Array.prototype.slice.call(inputs);
-
- const valid = elements.every((element) => {
- if(element.shadowRoot) {
- const input = element.shadowRoot.querySelector('input, textarea, select') as any
-
- if(input && input.checkValidity()) {
- return true
- } else {
- element._mdcComponent.valid = false;
- element._mdcComponent.helperTextContent = 'required';
-
- return false;
- }
- } else {
- return false;
- }
- })
- if(valid) {
- dialog.close();
- }
- }
-
+ return checkValidity(form, dialog)
+ }
+ else if(messageNotification && messageNotification.shadowRoot) {
+ const form = messageNotification.shadowRoot.querySelector('form')
+ return checkValidity(form, dialog)
}
}
}