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

Task-3000287

closes odoo/odoo#101577

X-original-commit: 9623548e3778cd90a148a32ff5dadad5601ecc20
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:20 +02:00
parent b4750008fa
commit e01275265f
2 changed files with 12 additions and 30 deletions
@@ -1,8 +1,9 @@
/** @odoo-module **/
import { useUpdateToModel } from '@mail/component_hooks/use_update_to_model';
import { registerMessagingComponent } from '@mail/utils/messaging_component';
const { Component, onMounted, onPatched } = owl;
const { Component } = owl;
export class DialogManager extends Component {
@@ -11,40 +12,12 @@ export class DialogManager extends Component {
*/
setup() {
super.setup();
onMounted(() => this._mounted());
onPatched(() => this._patched());
useUpdateToModel({ methodName: 'onComponentUpdate' });
}
_mounted() {
this._checkDialogOpen();
}
_patched() {
this._checkDialogOpen();
}
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
get dialogManager() {
return this.props.record;
}
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @private
*/
_checkDialogOpen() {
if (this.dialogManager.dialogs.length > 0) {
document.body.classList.add('modal-open');
} else {
document.body.classList.remove('modal-open');
}
}
}
Object.assign(DialogManager, {
@@ -5,6 +5,15 @@ import { many } from '@mail/model/model_field';
registerModel({
name: 'DialogManager',
recordMethods: {
onComponentUpdate() {
if (this.dialogs.length > 0) {
document.body.classList.add('modal-open');
} else {
document.body.classList.remove('modal-open');
}
},
},
fields: {
// FIXME: dependent on implementation that uses insert order in relations!!
dialogs: many('Dialog', {