diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-03-01 09:47:39 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 2bd4497b494e6d3dece46026283cce75beb1da91 (patch) | |
| tree | d68e467e845fe0916b8356779191db3bb05a78cf /addons/web/static/src/js | |
| parent | 1163bab5c62c8737449a43a637f77ec2c572bcb8 (diff) | |
[FIX] web: apply onchange even if warning
The onchange route returns field values, but it can also return
a warning, that needs to be displayed in a dialog. When it does,
the new values must be applied anyway, which wasn't the case
before this rev.
We generalized the 'warning' custom event handled by the webclient
so that it can display a warning in a dialog (and not only through
the NotificationManager).
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/chrome/abstract_web_client.js | 35 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 6 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/field_manager_mixin.js | 6 |
3 files changed, 35 insertions, 12 deletions
diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js index 1caa03f2955..5a84f4fe4b3 100644 --- a/addons/web/static/src/js/chrome/abstract_web_client.js +++ b/addons/web/static/src/js/chrome/abstract_web_client.js @@ -16,6 +16,7 @@ var concurrency = require('web.concurrency'); var core = require('web.core'); var crash_manager = require('web.crash_manager'); var data_manager = require('web.data_manager'); +var Dialog = require('web.Dialog'); var Loading = require('web.Loading'); var mixins = require('web.mixins'); var NotificationManager = require('web.notification').NotificationManager; @@ -23,6 +24,7 @@ var session = require('web.session'); var Widget = require('web.Widget'); var _t = core._t; +var qweb = core.qweb; var AbstractWebClient = Widget.extend(mixins.ServiceProvider, { custom_events: { @@ -46,11 +48,7 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, { this.notification_manager.notify(e.data.title, e.data.message, e.data.sticky); } }, - warning: function (e) { - if(this.notification_manager) { - this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky); - } - }, + warning: '_displayWarning', load_views: function (event) { var params = { model: event.data.modelName, @@ -284,6 +282,33 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, { toggle_fullscreen: function (fullscreen) { this.$el.toggleClass('o_fullscreen', fullscreen); }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Displays a warning in a dialog of with the NotificationManager + + * @param {OdooEvent} e + * @param {string} e.data.message the warning's message + * @param {string} e.data.title the warning's title + * @param {string} [e.data.type] 'dialog' to display in a dialog + * @param {boolean} [e.data.sticky] whether or not the warning should be + * sticky (if displayed with the NotificationManager) + */ + _displayWarning: function (e) { + var data = e.data; + if (data.type === 'dialog') { + new Dialog(this, { + size: 'medium', + title: data.title, + $content: qweb.render("CrashManager.warning", data), + }).open(); + } else if (this.notification_manager) { + this.notification_manager.warn(e.data.title, e.data.message, e.data.sticky); + } + }, }); return AbstractWebClient; diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 5f1e6ccbb9c..b16bf1e10b0 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -969,7 +969,11 @@ var BasicModel = AbstractModel.extend({ var args = [idList, currentData, fields, onchange_spec, context]; return self.performModelRPC(record.model, 'onchange', args, {}).then(function (result) { if (result.warning) { - return $.Deferred().reject(result.warning); + self.trigger_up('warning', { + message: result.warning.message, + title: result.warning.title, + type: 'dialog', + }); } var defs = []; _.each(result.value, function (val, name) { diff --git a/addons/web/static/src/js/views/field_manager_mixin.js b/addons/web/static/src/js/views/field_manager_mixin.js index f110f9be8bf..00607157a1f 100644 --- a/addons/web/static/src/js/views/field_manager_mixin.js +++ b/addons/web/static/src/js/views/field_manager_mixin.js @@ -86,12 +86,6 @@ var FieldManagerMixin = { } else { self._confirmChange(dataPointID, result, event); } - }).fail(function (warning) { - new Dialog(self, { - size: 'medium', - title: warning.title, - $content: qweb.render("CrashManager.warning", warning) - }).open(); }); }, /** |
