diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-03-10 12:28:26 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | b5b649e5b21d41279f12f0dbe6cfa53ca2c52580 (patch) | |
| tree | 3f62e4586180fafee9f992b0dec52dcdaa61665f /addons/web/static/src/js/fields | |
| parent | ba1a2d7145606e22ae316a636a1852a7ae80a3df (diff) | |
[FIX] web: fetching special data in field widgets
Some field widgets need additional data to render themself. These data
should ideally be fetched in the data fetching phase. In 10.0, these
data were fetched during field rendering which implied that the data
fetching was done sequentially. To limit this effect, before this
commit, these special fields were flagged by the basic view according
to some field properties and the basic model flagged the fields with
the required data. Now, the system has been improved. The field widget
classes can define a key "specialData" which refers to a BasicModel
method. These methods will be used to fetch the required data at the
right time and these data will be available at
`this.record.specialData[this.name]` in the AbstractField instance.
The new system also fixes a bug: the required data was fetched only
at record loading but should in fact be re-fetched at each view
change.
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/abstract_field.js | 10 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 12 |
2 files changed, 16 insertions, 6 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index e1ff2e8cca9..1d45402ee29 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -45,19 +45,25 @@ var AbstractField = Widget.extend({ * skip the widget when pressing tab */ readonly: false, - /** * If this flag is set to true, the field widget will be reset on every * change which is made in the view (if the view supports it). This is * currently a form view feature. */ resetOnAnyFieldChange: false, - /** * if true, the widget will replace a cell in an editable list view */ replace_element: false, /** + * If this flag is given a string, the related BasicModel will be used to + * initialize specialData the field might need. This data will be available + * through this.record.specialData[this.name]. + * + * @see BasicModel._fetchSpecialData + */ + specialData: false, + /** * to override to indicate which field types are supported by the widget */ supportedFieldTypes: [], diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 4d3aaf14e7d..68bd7a52343 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1107,10 +1107,11 @@ var FieldMany2ManyCheckBoxes = AbstractField.extend({ events: _.extend({}, AbstractField.prototype.events, { change: '_onChange', }), + specialData: "_fetchSpecialRelation", supportedFieldTypes: ['many2many'], init: function () { this._super.apply(this, arguments); - this.m2mValues = this.field.__many2many_information; + this.m2mValues = this.record.specialData[this.name]; }, //-------------------------------------------------------------------------- @@ -1170,6 +1171,7 @@ var FieldStatus = AbstractField.extend({ events: { 'click .o_arrow_button': '_onClickStage', }, + specialData: "_fetchSpecialStatus", supportedFieldTypes: ['selection', 'many2one'], init: function () { this._super.apply(this, arguments); @@ -1192,7 +1194,7 @@ var FieldStatus = AbstractField.extend({ */ _setState: function () { if (this.field.type === 'many2one') { - this.status_information = this.field.__status_information; + this.status_information = this.record.specialData[this.name]; var status = _.findWhere(this.status_information, {id: this.value.res_id}); if (status) { status.selected = true; @@ -1260,6 +1262,7 @@ var FieldStatus = AbstractField.extend({ */ var FieldSelection = AbstractField.extend({ template: 'FieldSelection', + specialData: "_fetchSpecialRelation", supportedFieldTypes: ['selection', 'many2one'], events: _.extend({}, AbstractField.prototype.events, { 'change': '_onChange', @@ -1272,7 +1275,7 @@ var FieldSelection = AbstractField.extend({ this._super.apply(this, arguments); this.values = []; if (this.field.type === 'many2one') { - this.values = this.field.__selection_information; + this.values = this.record.specialData[this.name]; } else { this.values = _.reject(this.field.selection, function (v) { return v[0] === false && v[1] === ''; @@ -1357,6 +1360,7 @@ var FieldSelection = AbstractField.extend({ var FieldRadio = FieldSelection.extend({ template: 'FieldRadio', + specialData: "_fetchSpecialMany2ones", supportedFieldTypes: ['selection', 'many2one'], events: _.extend({}, AbstractField.prototype.events, { 'click input': '_onInputClick', @@ -1369,7 +1373,7 @@ var FieldRadio = FieldSelection.extend({ if (this.field.type === 'selection') { this.values = this.field.selection || []; } else if (this.field.type === 'many2one') { - this.values = _.map(this.field.__status_information, function (val) { + this.values = _.map(this.record.specialData[this.name], function (val) { return [val.id, val.display_name]; }); } |
