[IMP] mail: move code from components to models (PersonaImStatusIcon)
+ Turn props on component into fields on PersonImStatusIconView model + Move handler from component methods to model record methods Task-3004188. closes odoo/odoo#101943 Signed-off-by: Louis Wicket (wil) <wil@odoo.com>
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
'o-isDeviceSmall': messaging.device.isSmall,
|
||||
'small': !messaging.device.isSmall,
|
||||
}"
|
||||
hasOpenChat="channelMemberView.hasOpenChat"
|
||||
record="channelMemberView.personaImStatusIconView"
|
||||
/>
|
||||
</t>
|
||||
|
||||
-1
@@ -19,7 +19,6 @@
|
||||
<t t-if="composerSuggestionView.personaImStatusIconView">
|
||||
<PersonaImStatusIcon
|
||||
className="'o_ComposerSuggestionView_personaImStatusIcon flex-shrink-0 me-1'"
|
||||
hasBackground="false"
|
||||
record="composerSuggestionView.personaImStatusIconView"
|
||||
/>
|
||||
</t>
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
'small': !messaging.device.isSmall,
|
||||
'text-100': messageView.message.is_note and !messageView.isSelected,
|
||||
}"
|
||||
hasOpenChat="messageView.hasAuthorOpenChat"
|
||||
record="messageView.personaImStatusIconView"
|
||||
/>
|
||||
</t>
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registerMessagingComponent } from '@mail/utils/messaging_component';
|
||||
import { markEventHandled } from '@mail/utils/utils';
|
||||
|
||||
const { Component } = owl;
|
||||
|
||||
export class PersonaImStatusIcon extends Component {
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @returns {PersonaImStatusIconView}
|
||||
*/
|
||||
@@ -18,38 +13,10 @@ export class PersonaImStatusIcon extends Component {
|
||||
return this.props.record;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onClick(ev) {
|
||||
markEventHandled(ev, 'PersonaImStatusIcon.Click');
|
||||
if (!this.props.hasOpenChat || !this.personaImStatusIconView.persona.partner) {
|
||||
return;
|
||||
}
|
||||
this.personaImStatusIconView.persona.partner.openChat();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.assign(PersonaImStatusIcon, {
|
||||
defaultProps: {
|
||||
hasBackground: true,
|
||||
hasOpenChat: false,
|
||||
},
|
||||
props: {
|
||||
hasBackground: { type: Boolean, optional: true },
|
||||
/**
|
||||
* Determines whether a click on `this` should open a chat with
|
||||
* `this.partner`.
|
||||
*/
|
||||
hasOpenChat: { type: Boolean, optional: true },
|
||||
record: Object,
|
||||
},
|
||||
props: { record: Object },
|
||||
template: 'mail.PersonaImStatusIcon',
|
||||
});
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
t-att-class="{
|
||||
'o-away': personaImStatusIconView.persona.im_status === 'away',
|
||||
'o-bot': messaging.partnerRoot.persona === personaImStatusIconView.persona,
|
||||
'o-has-open-chat cursor-pointer': props.hasOpenChat,
|
||||
'o-has-open-chat cursor-pointer': personaImStatusIconView.hasOpenChat,
|
||||
'o-offline': personaImStatusIconView.persona.im_status === 'offline',
|
||||
'o-online': personaImStatusIconView.persona.im_status === 'online',
|
||||
}"
|
||||
t-attf-class="{{ className }}"
|
||||
t-on-click="_onClick"
|
||||
t-on-click="personaImStatusIconView.onClick"
|
||||
t-ref="root"
|
||||
name="root"
|
||||
>
|
||||
<t t-if="props.hasBackground">
|
||||
<t t-if="personaImStatusIconView.hasBackground">
|
||||
<i class="o_PersonaImStatusIcon_outerBackground fa fa-circle fa-stack-1x"/>
|
||||
<i class="o_PersonaImStatusIcon_innerBackground fa fa-circle fa-stack-1x text-white"/>
|
||||
</t>
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { one } from '@mail/model/model_field';
|
||||
import { attr, one } from '@mail/model/model_field';
|
||||
import { registerModel } from '@mail/model/model_core';
|
||||
import { clear } from '@mail/model/model_field_command';
|
||||
import { markEventHandled } from '@mail/utils/utils';
|
||||
|
||||
registerModel({
|
||||
name: 'PersonaImStatusIconView',
|
||||
identifyingMode: 'xor',
|
||||
recordMethods: {
|
||||
/**
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
onClick(ev) {
|
||||
markEventHandled(ev, 'PersonaImStatusIcon.Click');
|
||||
if (!this.hasOpenChat || !this.persona.partner) {
|
||||
return;
|
||||
}
|
||||
this.persona.partner.openChat();
|
||||
},
|
||||
},
|
||||
fields: {
|
||||
channelInvitationFormSelectablePartnerViewOwner: one('ChannelInvitationFormSelectablePartnerView', {
|
||||
identifying: true,
|
||||
@@ -24,6 +37,31 @@ registerModel({
|
||||
identifying: true,
|
||||
inverse: 'personaImStatusIconView',
|
||||
}),
|
||||
hasBackground: attr({
|
||||
compute() {
|
||||
if (this.composerSuggestionViewOwner) {
|
||||
return false;
|
||||
}
|
||||
return clear();
|
||||
},
|
||||
default: true,
|
||||
}),
|
||||
/**
|
||||
* Determines whether a click on this view should open a chat with the
|
||||
* corresponding persona.
|
||||
*/
|
||||
hasOpenChat: attr({
|
||||
compute() {
|
||||
if (this.channelMemberViewOwner) {
|
||||
return this.channelMemberViewOwner.hasOpenChat;
|
||||
}
|
||||
if (this.messageViewOwner) {
|
||||
return this.messageViewOwner.hasAuthorOpenChat;
|
||||
}
|
||||
return clear();
|
||||
},
|
||||
default: false,
|
||||
}),
|
||||
messageViewOwner: one('MessageView', {
|
||||
identifying: true,
|
||||
inverse: 'personaImStatusIconView',
|
||||
|
||||
Reference in New Issue
Block a user