mirror of https://github.com/OCA/web.git
[MIG] web_widget_numeric_step: Migration to 17.0
parent
593e6d35ff
commit
ccc7cd7f56
|
@ -5,7 +5,7 @@
|
||||||
{
|
{
|
||||||
"name": "Web Widget Numeric Step",
|
"name": "Web Widget Numeric Step",
|
||||||
"category": "web",
|
"category": "web",
|
||||||
"version": "16.0.1.1.3",
|
"version": "17.0.1.0.0",
|
||||||
"author": "GRAP, Tecnativa, " "Odoo Community Association (OCA)",
|
"author": "GRAP, Tecnativa, " "Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/** @odoo-module */
|
/** @odoo-module */
|
||||||
|
|
||||||
import {registry} from "@web/core/registry";
|
|
||||||
import {standardFieldProps} from "@web/views/fields/standard_field_props";
|
|
||||||
import {_lt} from "@web/core/l10n/translation";
|
|
||||||
import {FloatField} from "@web/views/fields/float/float_field";
|
|
||||||
import {hasTouch} from "@web/core/browser/feature_detection";
|
import {hasTouch} from "@web/core/browser/feature_detection";
|
||||||
|
import {_lt} from "@web/core/l10n/translation";
|
||||||
|
import {registry} from "@web/core/registry";
|
||||||
|
import {FloatField} from "@web/views/fields/float/float_field";
|
||||||
|
import {standardFieldProps} from "@web/views/fields/standard_field_props";
|
||||||
|
|
||||||
export class NumericStep extends FloatField {
|
export class NumericStep extends FloatField {
|
||||||
setup() {
|
setup() {
|
||||||
|
@ -19,9 +19,9 @@ export class NumericStep extends FloatField {
|
||||||
this._doStep(mode);
|
this._doStep(mode);
|
||||||
}
|
}
|
||||||
_onKeyDown(ev) {
|
_onKeyDown(ev) {
|
||||||
if (ev.keyCode === $.ui.keyCode.UP) {
|
if (ev.keyCode === 38) {
|
||||||
this._doStep("plus");
|
this._doStep("plus");
|
||||||
} else if (ev.keyCode === $.ui.keyCode.DOWN) {
|
} else if (ev.keyCode === 40) {
|
||||||
this._doStep("minus");
|
this._doStep("minus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,10 @@ export class NumericStep extends FloatField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateField(val) {
|
updateField(val) {
|
||||||
return Promise.resolve(this.props.update(val));
|
return this.props.record.update({[this.props.name]: val});
|
||||||
}
|
}
|
||||||
_doStep(mode) {
|
_doStep(mode) {
|
||||||
let cval = this.props.value;
|
let cval = this.props.record.data[this.props.name];
|
||||||
if (mode === "plus") {
|
if (mode === "plus") {
|
||||||
cval += this.props.step;
|
cval += this.props.step;
|
||||||
} else if (mode === "minus") {
|
} else if (mode === "minus") {
|
||||||
|
@ -49,11 +49,6 @@ export class NumericStep extends FloatField {
|
||||||
cval = this.props.max;
|
cval = this.props.max;
|
||||||
}
|
}
|
||||||
this.updateField(cval);
|
this.updateField(cval);
|
||||||
this.props.setDirty(this._isSetDirty(cval));
|
|
||||||
this.props.setDirty(false);
|
|
||||||
}
|
|
||||||
_isSetDirty(val) {
|
|
||||||
return this.props.value != val;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,21 +61,25 @@ NumericStep.props = {
|
||||||
max: {type: Number, optional: true},
|
max: {type: Number, optional: true},
|
||||||
placeholder: {type: String, optional: true},
|
placeholder: {type: String, optional: true},
|
||||||
};
|
};
|
||||||
|
|
||||||
NumericStep.displayName = _lt("Numeric Step");
|
|
||||||
NumericStep.supportedTypes = ["float"];
|
|
||||||
NumericStep.defaultProps = {
|
NumericStep.defaultProps = {
|
||||||
|
...FloatField.defaultProps,
|
||||||
inputType: "text",
|
inputType: "text",
|
||||||
};
|
};
|
||||||
NumericStep.extractProps = ({attrs}) => {
|
|
||||||
|
export const numericStep = {
|
||||||
|
component: NumericStep,
|
||||||
|
supportedTypes: ["float"],
|
||||||
|
displayName: _lt("Numeric Step"),
|
||||||
|
extractProps: ({attrs, options}) => {
|
||||||
return {
|
return {
|
||||||
name: attrs.name,
|
name: attrs.name,
|
||||||
inputType: attrs.options.type,
|
inputType: attrs.type,
|
||||||
step: attrs.options.step || 1,
|
step: options.step || 1,
|
||||||
min: attrs.options.min,
|
min: options.min,
|
||||||
max: attrs.options.max,
|
max: options.max,
|
||||||
placeholder: attrs.options.placeholder,
|
placeholder: attrs.placeholder,
|
||||||
};
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
registry.category("fields").add("numeric_step", NumericStep);
|
registry.category("fields").add("numeric_step", numericStep);
|
||||||
|
|
Loading…
Reference in New Issue