From 4d12ec87bcb95150e82c519d7c8ac51b75ef9968 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Wed, 22 Feb 2017 11:55:51 +0100 Subject: [PATCH] [ADD] web: StandaloneFieldManagerMixin This mixin is meant to be used by widgets that instanciate standalone field widgets. --- .../views/standalone_field_manager_mixin.js | 56 +++++++++++++++++++ addons/web/views/webclient_templates.xml | 1 + 2 files changed, 57 insertions(+) create mode 100644 addons/web/static/src/js/views/standalone_field_manager_mixin.js diff --git a/addons/web/static/src/js/views/standalone_field_manager_mixin.js b/addons/web/static/src/js/views/standalone_field_manager_mixin.js new file mode 100644 index 00000000000..968258108e7 --- /dev/null +++ b/addons/web/static/src/js/views/standalone_field_manager_mixin.js @@ -0,0 +1,56 @@ +odoo.define('web.StandaloneFieldManagerMixin', function (require) { +"use strict"; + +/** + * The StandaloneFieldManagerMixin is a mixin, designed to be used by a widget + * that instanciates its own field widgets. + */ + +var FieldManagerMixin = require('web.FieldManagerMixin'); + +var StandaloneFieldManagerMixin = _.extend({}, FieldManagerMixin, { + + /** + * @override + */ + init: function () { + FieldManagerMixin.init.apply(this, arguments); + + // registeredWidgets is a dict of all field widgets used by the widget + this.registeredWidgets = {}; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * This method will be called whenever a field value has changed (and has + * been confirmed by the model). + * + * @private + * @param {string} id basicModel Id for the changed record + * @param {string[]} fields the fields (names) that have been changed + * @param {OdooEvent} event the event that triggered the change + */ + _confirmChange: function (id, fields, event) { + FieldManagerMixin._confirmChange.apply(this, arguments); + var record = this.model.get(id); + _.each(this.registeredWidgets[id], function (widget, fieldName) { + if (_.contains(fields, fieldName)) { + widget.reset(record, event); + } + }); + }, + + _registerWidget: function (datapointID, fieldName, widget) { + if (!this.registeredWidgets[datapointID]) { + this.registeredWidgets[datapointID] = {}; + } + this.registeredWidgets[datapointID][fieldName] = widget; + }, +}); + +return StandaloneFieldManagerMixin; + +}); diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml index fc012465a9d..8792b7c988a 100644 --- a/addons/web/views/webclient_templates.xml +++ b/addons/web/views/webclient_templates.xml @@ -196,6 +196,7 @@ +