mirror of https://github.com/OCA/web.git
[IMP] web_widget_numeric_step: Event handler
parent
b55d69e583
commit
989d0c4376
|
@ -5,7 +5,7 @@
|
||||||
{
|
{
|
||||||
'name': "Web Widget Numeric Step",
|
'name': "Web Widget Numeric Step",
|
||||||
'category': "web",
|
'category': "web",
|
||||||
'version': "12.0.1.1.0",
|
'version': "12.0.1.1.1",
|
||||||
'author': "GRAP, Tecnativa, "
|
'author': "GRAP, Tecnativa, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
|
|
@ -13,13 +13,14 @@ odoo.define('web_widget_numeric_step.field', function (require) {
|
||||||
var NumericStep = FieldFloat.extend({
|
var NumericStep = FieldFloat.extend({
|
||||||
template: 'web_widget_numeric_step',
|
template: 'web_widget_numeric_step',
|
||||||
className: 'o_field_numeric_step o_field_number',
|
className: 'o_field_numeric_step o_field_number',
|
||||||
events: _.extend({}, FieldFloat.prototype.events, {
|
events: _.extend({}, _.omit(FieldFloat.prototype.events, ['change', 'input']), {
|
||||||
'mousedown .btn_numeric_step': '_onStepMouseDown',
|
'mousedown .btn_numeric_step': '_onStepMouseDown',
|
||||||
'touchstart .btn_numeric_step': '_onStepMouseDown',
|
'touchstart .btn_numeric_step': '_onStepMouseDown',
|
||||||
'click .btn_numeric_step': '_onStepClick',
|
'click .btn_numeric_step': '_onStepClick',
|
||||||
'wheel .input_numeric_step': '_onWheel',
|
'wheel .input_numeric_step': '_onWheel',
|
||||||
'keydown .input_numeric_step': '_onKeyDown',
|
'keydown .input_numeric_step': '_onKeyDown',
|
||||||
'change .input_numeric_step': '_onChange',
|
'change .input_numeric_step': '_onChange',
|
||||||
|
'input .input_numeric_step': '_onInput',
|
||||||
}),
|
}),
|
||||||
supportedFieldTypes: ['float', 'integer'],
|
supportedFieldTypes: ['float', 'integer'],
|
||||||
|
|
||||||
|
@ -28,6 +29,10 @@ odoo.define('web_widget_numeric_step.field', function (require) {
|
||||||
MIN_DELAY: 50,
|
MIN_DELAY: 50,
|
||||||
SUBSTRACT_DELAY_STEP: 25,
|
SUBSTRACT_DELAY_STEP: 25,
|
||||||
|
|
||||||
|
DELAY_THROTTLE_CHANGE: 200,
|
||||||
|
|
||||||
|
_prevValue: null, // Used to know if the value was really changed
|
||||||
|
|
||||||
init: function () {
|
init: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
|
|
||||||
|
@ -44,6 +49,11 @@ odoo.define('web_widget_numeric_step.field', function (require) {
|
||||||
'min': Number(min_val),
|
'min': Number(min_val),
|
||||||
'max': Number(max_val),
|
'max': Number(max_val),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this._lazyOnChangeTrigger = _.debounce(function() {
|
||||||
|
self.$input.trigger("change");
|
||||||
|
}, this.DELAY_THROTTLE_CHANGE);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,12 +142,14 @@ odoo.define('web_widget_numeric_step.field', function (require) {
|
||||||
} else if (mode === 'minus') {
|
} else if (mode === 'minus') {
|
||||||
cval -= this._config.step;
|
cval -= this._config.step;
|
||||||
}
|
}
|
||||||
this.$input.val(this._sanitizeNumberValue(cval));
|
var nval = this._sanitizeNumberValue(cval);
|
||||||
this.isDirty = true;
|
if (nval !== this._prevValue) {
|
||||||
this._doDebouncedAction();
|
this.$input.val(nval);
|
||||||
// Every time that user update the value we must trigger an
|
// Every time that user update the value we must trigger an
|
||||||
// onchange method.
|
// onchange method.
|
||||||
this.$input.trigger("change");
|
this._lazyOnChangeTrigger();
|
||||||
|
}
|
||||||
|
this._prevValue = nval;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Handle Events
|
// Handle Events
|
||||||
|
@ -201,12 +213,11 @@ odoo.define('web_widget_numeric_step.field', function (require) {
|
||||||
/**
|
/**
|
||||||
* Sanitize user input value
|
* Sanitize user input value
|
||||||
*
|
*
|
||||||
* @param {ChangeEvent} ev
|
* @override
|
||||||
*/
|
*/
|
||||||
_onChange: function (ev) {
|
_onChange: function (ev) {
|
||||||
ev.target.value = this._sanitizeNumberValue(ev.target.value);
|
ev.target.value = this._sanitizeNumberValue(ev.target.value);
|
||||||
// Call _onChange of input widget
|
return this._super.apply(this, arguments);
|
||||||
this._super.apply(this, arguments);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Helper Functions
|
// Helper Functions
|
||||||
|
|
Loading…
Reference in New Issue