[ADD] web: StandaloneFieldManagerMixin
This mixin is meant to be used by widgets that instanciate standalone field widgets.
This commit is contained in:
committed by
Aaron Bohy
parent
dde1223a14
commit
4d12ec87bc
@@ -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;
|
||||
|
||||
});
|
||||
@@ -196,6 +196,7 @@
|
||||
<script type="text/javascript" src="/web/static/src/js/views/basic/basic_controller.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/basic/basic_renderer.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/field_manager_mixin.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/standalone_field_manager_mixin.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/view_registry.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/view_dialogs.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/views/form/form_renderer.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user