summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/thread_field.js
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-07-04 15:57:03 +0200
committerAlexandre Kühn <aku@odoo.com>2018-07-19 13:58:34 +0200
commit915da49d173e9ab8d0c6d94cbeec124c83d23fc7 (patch)
treed7fe30d4a4c7f1a6923b88c91ac98582ee6500f4 /addons/mail/static/src/js/thread_field.js
parentec8c505bc1c9ec21939e9ffef53a9cc6f63f30c7 (diff)
[IMP] mail, *: template rendering with abstract thread, adapt thread instantiation, thread `getMessages`/`fetchMessages`, and create mode document thread.
* = im_livechat, im_support - thread widget now uses abstract thread in `render` method - thread models have their `init` parameters changed, so that the parent may be optional - reworked 'creating a new record...' in chatter in create mode: > new model CreateModeDocumentThread, which basically is a fake document thread with a fake message for its rendering in create mode of the chatter > special rendering method of thread_widget for such case: `renderChatterCreateMode` - renamed thread methods previously named `getMessages` to `fetchMessages`: > in order to not conflict with `getMessages`, used for rendering > now, `getMessages` always get messages that are locally, while `fetchMessages` may fetch messages. TODO: - special thread model for im_livechat (rendering is broken ATM)
Diffstat (limited to 'addons/mail/static/src/js/thread_field.js')
-rw-r--r--addons/mail/static/src/js/thread_field.js54
1 files changed, 20 insertions, 34 deletions
diff --git a/addons/mail/static/src/js/thread_field.js b/addons/mail/static/src/js/thread_field.js
index d3021ca1ce5..a239481931b 100644
--- a/addons/mail/static/src/js/thread_field.js
+++ b/addons/mail/static/src/js/thread_field.js
@@ -1,14 +1,13 @@
odoo.define('mail.ThreadField', function (require) {
"use strict";
-var Message = require('mail.model.Message');
+var CreateModeDocumentThread = require('mail.model.CreateModeDocumentThread');
var ThreadWidget = require('mail.widget.Thread');
var AbstractField = require('web.AbstractField');
var core = require('web.core');
var field_registry = require('web.field_registry');
var concurrency = require('web.concurrency');
-var session = require('web.session');
var _t = core._t;
@@ -105,37 +104,20 @@ var ThreadField = AbstractField.extend({
*/
_fetchAndRenderThread: function (options) {
var self = this;
- options = options || {};
- options.ids = this._messageIDs;
- var fetchDef = this.dp.add(this._documentThread.getMessages(options));
- return fetchDef.then(function (rawMessages) {
- var isCreateMode = false;
- if (!self.res_id) {
- rawMessages = self._forgeCreateMessages();
- isCreateMode = true;
- }
- self._threadWidget.render(rawMessages, {
- displayLoadMore: rawMessages.length < self._documentThread.getMessageIDs().length,
- isCreateMode: isCreateMode,
+ if (!this._documentThread) {
+ var thread = new CreateModeDocumentThread();
+ options = { isCreateMode: true };
+ self._threadWidget.render(thread, options);
+ return $.when();
+ } else {
+ var fetchDef = this.dp.add(this._documentThread.fetchMessages(options));
+ return fetchDef.then(function () {
+ self._threadWidget.render(self._documentThread, {
+ displayLoadMore: self._documentThread.getMessages().length < self._documentThread.getMessageIDs().length,
+ });
+ return self._documentThread.markAsRead();
});
- return self._documentThread.markAsRead();
- });
- },
- /**
- * Make a fake list of messages to render in create mode.
- * Instead of rendering no messages at all, it displays a single message
- * with body content "Creating a new record".
- *
- * @private
- * @returns {mail.model.Message[]} an array containing a single message 'Creating a new record...'
- */
- _forgeCreateMessages: function () {
- var createMessage = new Message(this, {
- id: 0,
- body: _t("<p>Creating a new record...</p>"),
- author_id: [session.partner_id, session.partner_display_name],
- });
- return [createMessage];
+ }
},
/**
* @override
@@ -162,7 +144,7 @@ var ThreadField = AbstractField.extend({
* Sets this._documentThread, the DocumentThread associated with the current
* model and resID.
*
- * @returns {mail.model.DocumentThread}
+ * If it is a new document in create mode, unset the document thread.
*/
_setDocumentThread: function () {
var params = {
@@ -171,7 +153,11 @@ var ThreadField = AbstractField.extend({
resID: this.res_id,
resModel: this.model,
};
- this._documentThread = this.call('mail_service', 'getOrAddDocumentThread', params);
+ if (!params.resID) {
+ this._documentThread = null;
+ } else {
+ this._documentThread = this.call('mail_service', 'getOrAddDocumentThread', params);
+ }
},
//--------------------------------------------------------------------------