[IMP] mail: move code to models (ComposerSuggestionView)

Task-3000269

closes odoo/odoo#101576

X-original-commit: 66734b6c187e78e039f7f32c8adf105cb32aa2d6
Signed-off-by: Louis Wicket (wil) <wil@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Alexandre Kühn
2022-09-29 13:23:17 +02:00
parent 1f78b1608d
commit b4750008fa
2 changed files with 15 additions and 22 deletions
@@ -1,6 +1,7 @@
/** @odoo-module **/
import { useUpdate } from '@mail/component_hooks/use_update';
import { useComponentToModel } from '@mail/component_hooks/use_component_to_model';
import { useUpdateToModel } from '@mail/component_hooks/use_update_to_model';
import { registerMessagingComponent } from '@mail/utils/messaging_component';
const { Component } = owl;
@@ -12,7 +13,8 @@ export class ComposerSuggestionView extends Component {
*/
setup() {
super.setup();
useUpdate({ func: () => this._update() });
useComponentToModel({ fieldName: 'component' });
useUpdateToModel({ methodName: 'onComponentUpdate' });
}
//--------------------------------------------------------------------------
@@ -26,26 +28,6 @@ export class ComposerSuggestionView extends Component {
return this.props.record;
}
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @private
*/
_update() {
if (
this.root.el &&
this.composerSuggestionView.composerSuggestionListViewOwner.hasToScrollToActiveSuggestionView &&
this.composerSuggestionView.composerSuggestionListViewOwnerAsActiveSuggestionView
) {
this.root.el.scrollIntoView({
block: 'center',
});
this.composerSuggestionView.composerSuggestionListViewOwner.update({ hasToScrollToActiveSuggestionView: false });
}
}
}
Object.assign(ComposerSuggestionView, {
@@ -26,8 +26,19 @@ registerModel({
composerViewOwner.closeSuggestions();
composerViewOwner.update({ doFocus: true });
},
onComponentUpdate() {
if (
this.component.root.el &&
this.composerSuggestionListViewOwner.hasToScrollToActiveSuggestionView &&
this.composerSuggestionListViewOwnerAsActiveSuggestionView
) {
this.component.root.el.scrollIntoView({ block: 'center' });
this.composerSuggestionListViewOwner.update({ hasToScrollToActiveSuggestionView: false });
}
},
},
fields: {
component: attr(),
composerSuggestionListViewOwner: one('ComposerSuggestionListView', {
compute() {
if (this.composerSuggestionListViewExtraComposerSuggestionViewItemOwner) {