From 7a8620ed465c3403ca38e07dec45b26a4794baec Mon Sep 17 00:00:00 2001 From: theld <lars@adornis.de> Date: Wed, 9 Apr 2025 10:28:05 +0000 Subject: [PATCH] feat: allow disabling the mail editor via property --- modules/mails/client/x-mail-editor.ts | 7 ++++- .../mails/client/x-mails-template-editor.ts | 28 +++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/mails/client/x-mail-editor.ts b/modules/mails/client/x-mail-editor.ts index 453c6d9aec..a24a721a54 100644 --- a/modules/mails/client/x-mail-editor.ts +++ b/modules/mails/client/x-mail-editor.ts @@ -99,7 +99,7 @@ export class XMailEditor extends FormField<MailTemplate> { override render() { return xComponents(html` - <x-flex space="lg" flex h100> + <x-flex space="lg" h100> ${this.hintContent()} ${this.variablesDisplay()} <x-flex horizontal space="md" wrap flex> ${this.editorContent()} ${this.previewContent()} </x-flex> ${this.attachments ? this.attachmentSection() : nothing} @@ -109,6 +109,7 @@ export class XMailEditor extends FormField<MailTemplate> { } protected editorContent() { + if (this.disabled) return nothing; return xComponents(html` <x-flex class="wrapper" space="lg" flex> ${this.recipientPreview()} ${this.writerContent()} </x-flex> `); @@ -126,6 +127,7 @@ export class XMailEditor extends FormField<MailTemplate> { } protected writerContent() { + if (this.disabled) return nothing; return xComponents(html` <x-flex space="md" flex> <x-h3> Nachricht </x-h3> @@ -155,6 +157,7 @@ export class XMailEditor extends FormField<MailTemplate> { } protected saveButton() { + if (this.disabled) return nothing; // for the moment we only allow already existing templates to be saved as we do not allow customizable mail flows that could use custom created mail templates if (this.value.value?._id) return xComponents(html` @@ -166,6 +169,7 @@ export class XMailEditor extends FormField<MailTemplate> { } protected deleteButton() { + if (this.disabled) return nothing; if (this.value.value?._id && this.clearable) return xComponents( html` @@ -263,6 +267,7 @@ export class XMailEditor extends FormField<MailTemplate> { } protected attachmentSection() { + if (this.disabled) return nothing; const definition = mailTemplateDefinitions[this._form.document!.emailType]; if (!definition) return nothing; const availableAttachments = definition.attachments; diff --git a/modules/mails/client/x-mails-template-editor.ts b/modules/mails/client/x-mails-template-editor.ts index d261ed44ad..934f2ce4f8 100644 --- a/modules/mails/client/x-mails-template-editor.ts +++ b/modules/mails/client/x-mails-template-editor.ts @@ -1,6 +1,5 @@ import type { ValueEvent } from '@adornis/base/utilTypes.js'; import { ChemistryLitElement } from '@adornis/chemistry/chemistry-lit-element.js'; -import { css } from '@adornis/chemistry/directives/css.js'; import '@adornis/chemistry/elements/components/x-button.js'; import '@adornis/chemistry/elements/components/x-empty-placeholder.js'; import '@adornis/chemistry/elements/components/x-flex.js'; @@ -39,6 +38,7 @@ export class XMailsTemplateEditor extends ChemistryLitElement { @property({ type: Boolean }) clearable?: boolean; @property({ type: Boolean }) footer?: boolean; @property({ type: Boolean }) attachments?: boolean; + @property({ type: Boolean }) disabled?: boolean; @state() selectedMailType = ''; @state() selectedMailScope = ''; @@ -67,7 +67,7 @@ export class XMailsTemplateEditor extends ChemistryLitElement { override render() { const selectedTemplate = this._getSelectedTemplate(); return xComponents(html` - <x-flex space="lg"> + <x-flex space="lg" h100> ${this._templateSelection()} ${selectedTemplate ? this.editSection(selectedTemplate) @@ -121,18 +121,18 @@ export class XMailsTemplateEditor extends ChemistryLitElement { protected editSection(selectedTemplate: MailTemplate) { return xComponents(html` - <x-flex space="md" ${css({ paddingTop: this.spacing.lg })}> - <x-mail-editor - .value=${selectedTemplate} - ?clearable=${this.clearable} - @delete=${() => { - this.selectedMailType = ''; - this.selectedMailScope = ''; - }} - ?footer=${this.footer} - ?attachments=${this.attachments} - ></x-mail-editor> - </x-flex> + <x-mail-editor + flex + ?disabled=${this.disabled} + .value=${selectedTemplate} + ?clearable=${this.clearable} + @delete=${() => { + this.selectedMailType = ''; + this.selectedMailScope = ''; + }} + ?footer=${this.footer} + ?attachments=${this.attachments} + ></x-mail-editor> `); } } -- GitLab