diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/mail/static/src/components/chatter_container | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/mail/static/src/components/chatter_container')
3 files changed, 179 insertions, 0 deletions
diff --git a/addons/mail/static/src/components/chatter_container/chatter_container.js b/addons/mail/static/src/components/chatter_container/chatter_container.js new file mode 100644 index 00000000..2b186e62 --- /dev/null +++ b/addons/mail/static/src/components/chatter_container/chatter_container.js @@ -0,0 +1,139 @@ +odoo.define('mail/static/src/components/chatter_container/chatter_container.js', function (require) { +'use strict'; + +const components = { + Chatter: require('mail/static/src/components/chatter/chatter.js'), +}; +const useShouldUpdateBasedOnProps = require('mail/static/src/component_hooks/use_should_update_based_on_props/use_should_update_based_on_props.js'); +const useStore = require('mail/static/src/component_hooks/use_store/use_store.js'); +const useUpdate = require('mail/static/src/component_hooks/use_update/use_update.js'); +const { clear } = require('mail/static/src/model/model_field_command.js'); + +const { Component } = owl; + +/** + * This component abstracts chatter component to its parent, so that it can be + * mounted and receive chatter data even when a chatter component cannot be + * created. Indeed, in order to create a chatter component, we must create + * a chatter record, the latter requiring messaging to be initialized. The view + * may attempt to create a chatter before messaging has been initialized, so + * this component delays the mounting of chatter until it becomes initialized. + */ +class ChatterContainer extends Component { + + /** + * @override + */ + constructor(...args) { + super(...args); + this.chatter = undefined; + this._wasMessagingInitialized = false; + useShouldUpdateBasedOnProps(); + useStore(props => { + const isMessagingInitialized = this.env.isMessagingInitialized(); + // Delay creation of chatter record until messaging is initialized. + // Ideally should observe models directly to detect change instead + // of using `useStore`. + if (!this._wasMessagingInitialized && isMessagingInitialized) { + this._wasMessagingInitialized = true; + this._insertFromProps(props); + } + return { chatter: this.chatter }; + }); + useUpdate({ func: () => this._update() }); + } + + /** + * @override + */ + willUpdateProps(nextProps) { + if (this.env.isMessagingInitialized()) { + this._insertFromProps(nextProps); + } + return super.willUpdateProps(...arguments); + } + + /** + * @override + */ + destroy() { + super.destroy(); + if (this.chatter) { + this.chatter.delete(); + } + } + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + */ + _insertFromProps(props) { + const values = Object.assign({}, props); + if (values.threadId === undefined) { + values.threadId = clear(); + } + if (!this.chatter) { + this.chatter = this.env.models['mail.chatter'].create(values); + } else { + this.chatter.update(values); + } + } + + /** + * @private + */ + _update() { + if (this.chatter) { + this.chatter.refresh(); + } + } + +} + +Object.assign(ChatterContainer, { + components, + props: { + hasActivities: { + type: Boolean, + optional: true, + }, + hasExternalBorder: { + type: Boolean, + optional: true, + }, + hasFollowers: { + type: Boolean, + optional: true, + }, + hasMessageList: { + type: Boolean, + optional: true, + }, + hasMessageListScrollAdjust: { + type: Boolean, + optional: true, + }, + hasTopbarCloseButton: { + type: Boolean, + optional: true, + }, + isAttachmentBoxVisibleInitially: { + type: Boolean, + optional: true, + }, + threadId: { + type: Number, + optional: true, + }, + threadModel: String, + }, + template: 'mail.ChatterContainer', +}); + + +return ChatterContainer; + +}); diff --git a/addons/mail/static/src/components/chatter_container/chatter_container.scss b/addons/mail/static/src/components/chatter_container/chatter_container.scss new file mode 100644 index 00000000..8cd51580 --- /dev/null +++ b/addons/mail/static/src/components/chatter_container/chatter_container.scss @@ -0,0 +1,25 @@ +// ------------------------------------------------------------------ +// Layout +// ------------------------------------------------------------------ + +.o_ChatterContainer { + display: flex; + flex: 1 1 auto; + width: map-get($sizes, 100); +} + +.o_ChatterContainer_noChatter { + flex: 1 1 auto; + display: flex; + align-items: center; + justify-content: center; +} + +.o_ChatterContainer_noChatterIcon { + margin-right: map-get($spacers, 2); +} + +// ------------------------------------------------------------------ +// Style +// ------------------------------------------------------------------ + diff --git a/addons/mail/static/src/components/chatter_container/chatter_container.xml b/addons/mail/static/src/components/chatter_container/chatter_container.xml new file mode 100644 index 00000000..c1d8d220 --- /dev/null +++ b/addons/mail/static/src/components/chatter_container/chatter_container.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates xml:space="preserve"> + + <t t-name="mail.ChatterContainer" owl="1"> + <div class="o_ChatterContainer"> + <t t-if="chatter"> + <Chatter chatterLocalId="chatter.localId"/> + </t> + <t t-else=""> + <div class="o_ChatterContainer_noChatter"><i class="o_ChatterContainer_noChatterIcon fa fa-spinner fa-spin"/>Please wait...</div> + </t> + </div> + </t> + +</templates> |
