diff options
| author | Elkasitu <adt@odoo.com> | 2017-07-17 11:09:35 +0200 |
|---|---|---|
| committer | Elkasitu <adt@odoo.com> | 2017-07-18 15:12:55 +0200 |
| commit | e83c3e2678500c9bf2c17b4d23ae9a294ebafaa7 (patch) | |
| tree | ccdbcd92402deb11b9c68b76689ab8e2448cbd82 /addons/web/static/src/js | |
| parent | f7dd085e80c463c828396408f37c12700fec36de (diff) | |
[FIX] web: Fix actions for widgets w/o controllers
Execution of actions is usually done with trigger_up, which delegates
the action execution to the widget's controller.
This is troublesome for actions done on widgets that have no
controllers, like widgets in Studio for example.
The commit fixes this by adding a standalone option for AbstractFields,
if the flag is true when instantiating a widget, the action will be
called directly from within the widget object and will not be propagated
upwards.
A test to verify that this works properly has been added as well
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/fields/abstract_field.js | 9 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 32 |
2 files changed, 26 insertions, 15 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index 4ae4eec9c05..fa2f37a123f 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -65,9 +65,12 @@ var AbstractField = Widget.extend({ * @constructor * @param {Widget} parent * @param {string} name The field name defined in the model - * @param {Object} record A record object (result of the get method of a basic model) + * @param {Object} record A record object (result of the get method of + * a basic model) * @param {Object} [options] * @param {string} [options.mode=readonly] should be 'readonly' or 'edit' + * @param {string} [options.standalone=false] this flag indicates that the + * field does not have a controller to delegate to */ init: function (parent, name, record, options) { this._super(parent); @@ -157,6 +160,10 @@ var AbstractField = Widget.extend({ // calls to the format (resp. parse) function. this.formatOptions = {}; this.parseOptions = {}; + + // standalone is a flag indicating that the field does not have a + // controller to delegate actions to + this.standalone = options.standalone; }, /** * When a field widget is appended to the DOM, its start method is called, diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 14512c02912..7522bb3bc37 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -223,21 +223,25 @@ var FieldMany2One = AbstractField.extend({ _quickCreate: function (name) { var self = this; var slowCreate = this._searchCreatePopup.bind(this, "form", false, this._createContext(name)); + var action = function () { + return self._rpc({ + model: self.field.relation, + method: 'name_create', + args: [name], + context: self.record.getContext(self.recordParams), + }).then(function (result) { + if (self.mode === "edit") { + self.reinitialize({id: result[0], display_name: result[1]}); + } + }, slowCreate); + }; + if (this.nodeOptions.quick_create) { - this.trigger_up('mutexify', { - action: function () { - return self._rpc({ - model: self.field.relation, - method: 'name_create', - args: [name], - context: self.record.getContext(self.recordParams), - }).then(function (result) { - if (self.mode === "edit") { - self.reinitialize({id: result[0], display_name: result[1]}); - } - }, slowCreate); - }, - }); + if (this.standalone) { + action(); + } else { + this.trigger_up('mutexify', {action: action}); + } } else { slowCreate(); } |
