[IMP] mail: introduce MailTemplateView
Task-2793280 closes odoo/odoo#87213 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -106,13 +106,14 @@
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-if="activityView.activity.mailTemplates.length > 0">
|
||||
<t t-if="activityView.mailTemplateViews.length > 0">
|
||||
<div class="o_Activity_mailTemplates">
|
||||
<t t-foreach="activityView.activity.mailTemplates" t-as="mailTemplate" t-key="mailTemplate.localId">
|
||||
<t t-foreach="activityView.mailTemplateViews" t-as="mailTemplateView" t-key="mailTemplateView.localId">
|
||||
<MailTemplate
|
||||
className="'o_Activity_mailTemplate'"
|
||||
activityLocalId="activityView.activity.localId"
|
||||
mailTemplateLocalId="mailTemplate.localId"
|
||||
localId="mailTemplateView.localId"
|
||||
mailTemplateLocalId="mailTemplateView.mailTemplate.localId"
|
||||
/>
|
||||
</t>
|
||||
</div>
|
||||
|
||||
@@ -24,6 +24,13 @@ export class MailTemplate extends Component {
|
||||
return this.messaging && this.messaging.models['MailTemplate'].get(this.props.mailTemplateLocalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {MailTemplateView}
|
||||
*/
|
||||
get mailTemplateView() {
|
||||
return this.messaging && this.messaging.models['MailTemplateView'].get(this.props.localId);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -53,6 +60,7 @@ export class MailTemplate extends Component {
|
||||
Object.assign(MailTemplate, {
|
||||
props: {
|
||||
activityLocalId: String,
|
||||
localId: String,
|
||||
mailTemplateLocalId: String,
|
||||
},
|
||||
template: 'mail.MailTemplate',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="mail.MailTemplate" owl="1">
|
||||
<t t-if="mailTemplate">
|
||||
<t t-if="mailTemplateView">
|
||||
<div class="o_MailTemplate" t-attf-class="{{ className }}" t-ref="root">
|
||||
<i class="fa fa-envelope-o" title="Mail" role="img"/>
|
||||
<span class="o_MailTemplate_name" t-esc="mailTemplate.name"/>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registerModel } from '@mail/model/model_core';
|
||||
import { attr, one } from '@mail/model/model_field';
|
||||
import { clear, insertAndReplace } from '@mail/model/model_field_command';
|
||||
import { attr, many, one } from '@mail/model/model_field';
|
||||
import { clear, insertAndReplace, replace } from '@mail/model/model_field_command';
|
||||
|
||||
import { auto_str_to_date, getLangDateFormat, getLangDatetimeFormat } from 'web.time';
|
||||
|
||||
@@ -121,6 +121,20 @@ registerModel({
|
||||
const datetimeFormat = getLangDateFormat();
|
||||
return momentDeadlineDate.format(datetimeFormat);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {FieldCommand}
|
||||
*/
|
||||
_computeMailTemplateViews() {
|
||||
if (this.activity.mailTemplates.length === 0) {
|
||||
return clear();
|
||||
}
|
||||
return insertAndReplace(
|
||||
this.activity.mailTemplates.map(
|
||||
mailTemplate => ({ mailTemplate: replace(mailTemplate) })
|
||||
),
|
||||
);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @returns {string}
|
||||
@@ -199,6 +213,11 @@ registerModel({
|
||||
formattedDeadlineDate: attr({
|
||||
compute: '_computeFormattedDeadlineDate',
|
||||
}),
|
||||
mailTemplateViews: many('MailTemplateView', {
|
||||
compute: '_computeMailTemplateViews',
|
||||
inverse: 'activityViewOwner',
|
||||
isCausal: true,
|
||||
}),
|
||||
/**
|
||||
* Label for mark as done. This is just for translations purpose.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registerModel } from '@mail/model/model_core';
|
||||
import { one } from '@mail/model/model_field';
|
||||
|
||||
registerModel({
|
||||
name: 'MailTemplateView',
|
||||
identifyingFields: ['activityViewOwner', 'mailTemplate'],
|
||||
fields: {
|
||||
activityViewOwner: one('ActivityView', {
|
||||
inverse: 'mailTemplateViews',
|
||||
readonly: true,
|
||||
required: true,
|
||||
}),
|
||||
mailTemplate: one('MailTemplate', {
|
||||
readonly: true,
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user