Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
89
web_widget_numeric_step/static/src/numeric_step.esm.js
Executable file
89
web_widget_numeric_step/static/src/numeric_step.esm.js
Executable file
@@ -0,0 +1,89 @@
|
||||
import {FloatField} from "@web/views/fields/float/float_field";
|
||||
import {_t} from "@web/core/l10n/translation";
|
||||
import {registry} from "@web/core/registry";
|
||||
import {standardFieldProps} from "@web/views/fields/standard_field_props";
|
||||
|
||||
export class NumericStep extends FloatField {
|
||||
setup() {
|
||||
super.setup();
|
||||
}
|
||||
_onStepClick(ev) {
|
||||
const mode = ev.target.dataset.mode;
|
||||
this._doStep(mode);
|
||||
}
|
||||
_onKeyDown(ev) {
|
||||
if (ev.keyCode === 38) {
|
||||
this._doStep("plus");
|
||||
} else if (ev.keyCode === 40) {
|
||||
this._doStep("minus");
|
||||
}
|
||||
}
|
||||
_onWheel(ev) {
|
||||
ev.preventDefault();
|
||||
if (!this._lastWheelTime) {
|
||||
this._lastWheelTime = 0;
|
||||
}
|
||||
const now = Date.now();
|
||||
const throttleLimit = 100;
|
||||
if (now - this._lastWheelTime >= throttleLimit) {
|
||||
this._lastWheelTime = now;
|
||||
|
||||
if (ev.deltaY > 0) {
|
||||
this._doStep("minus");
|
||||
} else {
|
||||
this._doStep("plus");
|
||||
}
|
||||
}
|
||||
}
|
||||
updateField(val) {
|
||||
return this.props.record.update({[this.props.name]: val});
|
||||
}
|
||||
_doStep(mode) {
|
||||
let cval = this.props.record.data[this.props.name];
|
||||
if (mode === "plus") {
|
||||
cval += this.props.step;
|
||||
} else if (mode === "minus") {
|
||||
cval -= this.props.step;
|
||||
}
|
||||
if (cval < this.props.min) {
|
||||
cval = this.props.min;
|
||||
} else if (cval > this.props.max) {
|
||||
cval = this.props.max;
|
||||
}
|
||||
this.updateField(cval);
|
||||
}
|
||||
}
|
||||
|
||||
NumericStep.template = "web_widget_numeric_step";
|
||||
NumericStep.props = {
|
||||
...standardFieldProps,
|
||||
inputType: {type: String, optional: true},
|
||||
step: {type: Number, optional: true},
|
||||
min: {type: Number, optional: true},
|
||||
max: {type: Number, optional: true},
|
||||
placeholder: {type: String, optional: true},
|
||||
additional_class: {type: String, optional: true},
|
||||
};
|
||||
NumericStep.defaultProps = {
|
||||
...FloatField.defaultProps,
|
||||
inputType: "text",
|
||||
};
|
||||
|
||||
export const numericStep = {
|
||||
component: NumericStep,
|
||||
supportedTypes: ["float"],
|
||||
displayName: _t("Numeric Step"),
|
||||
extractProps: ({attrs, options}) => {
|
||||
return {
|
||||
name: attrs.name,
|
||||
inputType: attrs.type,
|
||||
step: options.step || 1,
|
||||
min: options.min,
|
||||
max: options.max,
|
||||
placeholder: attrs.placeholder,
|
||||
additional_class: attrs.class,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
registry.category("fields").add("numeric_step", numericStep);
|
||||
22
web_widget_numeric_step/static/src/numeric_step.scss
Executable file
22
web_widget_numeric_step/static/src/numeric_step.scss
Executable file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2023 Moduon Team S.L.
|
||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
.widget_numeric_step {
|
||||
// Hide the buttons until the user hovers if possible
|
||||
@media (hover: hover) {
|
||||
.btn_numeric_step {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
&:hover .btn_numeric_step {
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
|
||||
.o_numeric_step_cell {
|
||||
// Default for old browsers
|
||||
min-width: 15 * $btn-padding-x;
|
||||
// Value hardcoded in `FIXED_FIELD_COLUMN_WIDTHS.float` + width of 2
|
||||
// FontAwesome icons + 2 buttons * 2 horizontal paddings
|
||||
min-width: calc(92px + 2ex + 4 * #{$btn-padding-x});
|
||||
}
|
||||
47
web_widget_numeric_step/static/src/numeric_step.xml
Executable file
47
web_widget_numeric_step/static/src/numeric_step.xml
Executable file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
Copyright 2019 GRAP - Quentin DUPONT
|
||||
Copyright 2020 Tecnativa - Alexandre Díaz
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
-->
|
||||
<template>
|
||||
<t t-name="web_widget_numeric_step">
|
||||
<div t-attf-class="d-flex widget_numeric_step {{props.additional_class or ''}}">
|
||||
<div class="input-group-prepend widget_numeric_step_btn">
|
||||
<button
|
||||
class="fa fa-minus btn btn-default btn_numeric_step"
|
||||
aria-label="Minus"
|
||||
tabindex="-1"
|
||||
title="Minus"
|
||||
type="button"
|
||||
data-mode="minus"
|
||||
t-att-disabled="props.readonly"
|
||||
t-on-click="_onStepClick"
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
t-att-id="props.id"
|
||||
t-ref="numpadDecimal"
|
||||
t-att-placeholder="props.placeholder"
|
||||
t-att-type="props.inputType"
|
||||
class="o_input"
|
||||
inputmode="decimal"
|
||||
t-att-step="props.step"
|
||||
t-on-keydown="_onKeyDown"
|
||||
t-on-wheel="_onWheel"
|
||||
/>
|
||||
<div class="input-group-append widget_numeric_step_btn">
|
||||
<button
|
||||
class="fa fa-plus btn btn-default btn_numeric_step"
|
||||
aria-label="Plus"
|
||||
tabindex="-1"
|
||||
title="Plus"
|
||||
type="button"
|
||||
data-mode="plus"
|
||||
t-att-disabled="props.readonly"
|
||||
t-on-click="_onStepClick"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
Reference in New Issue
Block a user