diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-11-16 13:52:40 +0100 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-11-17 10:47:49 +0100 |
| commit | ab900bb62a6c6fecc6940e2ef04c2ccf4986372c (patch) | |
| tree | 98e58362a4f3cde45585971a19248ece60c4f97f /addons/mail/static/src/js/form_renderer.js | |
| parent | 745d00362ab8353bf88457b05f090c470f780ef5 (diff) | |
[FIX] mail: keep model informed of new messages
Do not forward-port this after 11.0
After sending a message, if one switched in edit mode in the form view, the
created message disappeared.
This is because the model is not aware of messages (they are created through
their own routes, message are not handled as other one2many fields with commands)
and the widget was reset with a new datapoint instance when switching in edit mode.
In this rev. we keep the model informed of the new messages by directly writing
the message ids in the datapoint.
Note that the includes on FormController and BasicModel are one in the
form_renderer.js file to fix this issue in existing database without adding
files. Another revision will be done in master to add the correct files.
opw-781353
Diffstat (limited to 'addons/mail/static/src/js/form_renderer.js')
| -rw-r--r-- | addons/mail/static/src/js/form_renderer.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/addons/mail/static/src/js/form_renderer.js b/addons/mail/static/src/js/form_renderer.js index 520827d7695..9d9532e2171 100644 --- a/addons/mail/static/src/js/form_renderer.js +++ b/addons/mail/static/src/js/form_renderer.js @@ -1,7 +1,9 @@ odoo.define('mail.form_renderer', function (require) { "use strict"; +var BasicModel = require('web.BasicModel'); var Chatter = require('mail.Chatter'); +var FormController = require('web.FormController'); var FormRenderer = require('web.FormRenderer'); /** @@ -88,4 +90,51 @@ FormRenderer.include({ }, }); +/** + * Include the FormController and BasicModel to update the datapoint on the + * model when a message is posted. + */ +FormController.include({ + custom_events: _.extend({}, FormController.prototype.custom_events, { + new_message: '_onNewMessage', + }), + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @param {OdooEvent} event + * @param {string} event.data.id datapointID + * @param {integer[]} event.data.msgIDs list of message ids + */ + _onNewMessage: function (event) { + this.model.updateMessageIDs(event.data.id, event.data.msgIDs); + }, +}); + +BasicModel.include({ + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Update the message ids on a datapoint. + * + * Note that we directly update the res_ids on the datapoint as the message + * has already been posted ; this change can't be handled 'normally' with + * x2m commands because the change won't be saved as a normal field. + * + * @param {string} id + * @param {integer[]} msgIDs + */ + updateMessageIDs: function (id, msgIDs) { + var element = this.localData[id]; + element.res_ids = msgIDs; + element.count = msgIDs.length; + }, +}); + }); |
