From 9cc35e276d2f227cda88007b8dfe2adaf2df270f Mon Sep 17 00:00:00 2001 From: "Louis Wicket (wil)" Date: Thu, 29 Sep 2022 12:47:37 +0000 Subject: [PATCH] [IMP] mail: move code from components to models (ComposerTextInput) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Create ComposerTextInputView model + Replace uses of useRef with useRefToModel + Replace use of useUpdate with useUpdateToModel + Remove dead code (ComposerTextInput._isEmpty) Task-3001200. closes odoo/odoo#101707 Signed-off-by: Alexandre Kühn (aku) --- .../src/components/composer/composer.xml | 2 +- .../composer_text_input.js | 58 ++----------------- .../composer_text_input.xml | 12 ++-- .../src/models/composer_text_input_view.js | 52 +++++++++++++++++ .../mail/static/src/models/composer_view.js | 30 ++++------ 5 files changed, 77 insertions(+), 77 deletions(-) create mode 100644 addons/mail/static/src/models/composer_text_input_view.js diff --git a/addons/mail/static/src/components/composer/composer.xml b/addons/mail/static/src/components/composer/composer.xml index 2adca825f27..ac910a2111c 100644 --- a/addons/mail/static/src/components/composer/composer.xml +++ b/addons/mail/static/src/components/composer/composer.xml @@ -84,7 +84,7 @@ 'o-has-current-partner-avatar': composerView.hasCurrentPartnerAvatar, 'rounded-start-3': composerView.isCompact and composerView.hasCurrentPartnerAvatar, }" - record="composerView" + record="composerView.textInput" t-key="composerView.localId" />
diff --git a/addons/mail/static/src/components/composer_text_input/composer_text_input.js b/addons/mail/static/src/components/composer_text_input/composer_text_input.js index 3dc4004c65c..20af03a1544 100644 --- a/addons/mail/static/src/components/composer_text_input/composer_text_input.js +++ b/addons/mail/static/src/components/composer_text_input/composer_text_input.js @@ -1,7 +1,8 @@ /** @odoo-module **/ +import { useComponentToModel } from '@mail/component_hooks/use_component_to_model'; import { useRefToModel } from '@mail/component_hooks/use_ref_to_model'; -import { useUpdate } from '@mail/component_hooks/use_update'; +import { useUpdateToModel } from '@mail/component_hooks/use_update_to_model'; import { registerMessagingComponent } from '@mail/utils/messaging_component'; const { Component } = owl; @@ -13,70 +14,23 @@ export class ComposerTextInput extends Component { */ setup() { super.setup(); + useComponentToModel({ fieldName: 'component' }); useRefToModel({ fieldName: 'mirroredTextareaRef', refName: 'mirroredTextarea' }); useRefToModel({ fieldName: 'textareaRef', refName: 'textarea' }); /** * Updates the composer text input content when composer is mounted * as textarea content can't be changed from the DOM. */ - useUpdate({ func: () => this._update() }); + useUpdateToModel({ methodName: 'onComponentUpdate' }); } - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - /** - * @returns {ComposerView} + * @returns {ComposerTextInputView} */ - get composerView() { + get composerTextInputView() { return this.props.record; } - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Determines whether the textarea is empty or not. - * - * @private - * @returns {boolean} - */ - _isEmpty() { - return this.composerView.textareaRef.el.value === ""; - } - - /** - * Updates the content and height of a textarea - * - * @private - */ - _update() { - if (!this.root.el) { - return; - } - if (this.composerView.doFocus) { - this.composerView.update({ doFocus: false }); - if (this.messaging.device.isSmall) { - this.root.el.scrollIntoView(); - } - this.composerView.textareaRef.el.focus(); - } - if (this.composerView.hasToRestoreContent) { - this.composerView.textareaRef.el.value = this.composerView.composer.textInputContent; - if (this.composerView.isFocused) { - this.composerView.textareaRef.el.setSelectionRange( - this.composerView.composer.textInputCursorStart, - this.composerView.composer.textInputCursorEnd, - this.composerView.composer.textInputSelectionDirection, - ); - } - this.composerView.update({ hasToRestoreContent: false }); - } - this.composerView.updateTextInputHeight(); - } - } Object.assign(ComposerTextInput, { diff --git a/addons/mail/static/src/components/composer_text_input/composer_text_input.xml b/addons/mail/static/src/components/composer_text_input/composer_text_input.xml index 3ecdaa0e271..40d4d35e90b 100644 --- a/addons/mail/static/src/components/composer_text_input/composer_text_input.xml +++ b/addons/mail/static/src/components/composer_text_input/composer_text_input.xml @@ -2,18 +2,18 @@ - -
- - + +
+ + -