From 915da49d173e9ab8d0c6d94cbeec124c83d23fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 4 Jul 2018 15:57:03 +0200 Subject: [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) --- .../src/js/models/threads/document_thread.js | 44 +++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'addons/mail/static/src/js/models/threads/document_thread.js') diff --git a/addons/mail/static/src/js/models/threads/document_thread.js b/addons/mail/static/src/js/models/threads/document_thread.js index 92cc26e845b..cf3e27c8c81 100644 --- a/addons/mail/static/src/js/models/threads/document_thread.js +++ b/addons/mail/static/src/js/models/threads/document_thread.js @@ -24,13 +24,16 @@ var DocumentThread = Thread.extend({ /** * @override - * @param {string} [data.messagesIDs] the list of message ids linked + * @param {Object} params + * @param {Object} params.data + * @param {string} [params.data.messagesIDs] the list of message ids linked * to the document (if not given, they will be fetched before fetching the * messages) - * @param {string} data.model - * @param {integer} data.resID + * @param {string} params.data.model + * @param {integer} params.data.resID */ - init: function (parent, data) { + init: function (params) { + var data = params.data; data.id = data.resModel + '_' + data.resID; data.type = 'document_thread'; @@ -98,6 +101,23 @@ var DocumentThread = Thread.extend({ windowState: windowState, }); }, + /** + * + * Fetch messages of the document thread + * + * @override + * @param {Object} options + * @param {boolean} [options.forceFetch] if true, fetch anyway, as user + * clicked on 'load more'. + * @returns {$.Promise} + */ + fetchMessages: function (options) { + var self = this; + return this._fetchMessages(options).then(function () { + self.call('mail_service', 'markMessagesAsRead', self._messageIDs); + return self._messages; + }); + }, /** * Overrides to store the thread's state in the LocalStorage, so that it is * shared between tabs, and restored on F5. @@ -137,21 +157,11 @@ var DocumentThread = Thread.extend({ return this._messageIDs; }, /** - * - * Get messages of the document thread - * * @override - * @param {Object} options - * @param {boolean} [options.forceFetch] if true, fetch anyway, as user - * clicked on 'load more'. - * @returns {$.Promise} + * @returns {mail.model.Message[]} */ - getMessages: function (options) { - var self = this; - return this._fetchMessages(options).then(function () { - self.call('mail_service', 'markMessagesAsRead', self._messageIDs); - return self._messages; - }); + getMessages: function () { + return this._messages; }, /** * States whether the thread is linked to a document -- cgit v1.2.3