summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2017-02-22 11:55:51 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit4d12ec87bcb95150e82c519d7c8ac51b75ef9968 (patch)
tree153dc4cc1c4bf42999a84c5cfa5a114cf765cc9d /addons/web/static/src
parentdde1223a1467537de7db5a45eff4afddc3529004 (diff)
[ADD] web: StandaloneFieldManagerMixin
This mixin is meant to be used by widgets that instanciate standalone field widgets.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/standalone_field_manager_mixin.js56
1 files changed, 56 insertions, 0 deletions
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;
+
+});