diff --git a/web_widget_number_ux_choice/README.rst b/web_widget_number_ux_choice/README.rst deleted file mode 100644 index 7aee7a490..000000000 --- a/web_widget_number_ux_choice/README.rst +++ /dev/null @@ -1,86 +0,0 @@ -=========================== -Web Widget UX Number Choice -=========================== - -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! This file is generated by oca-gen-addon-readme !! - !! changes will be overwritten. !! - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png - :target: https://odoo-community.org/page/development-status - :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 -.. |badge3| image:: https://img.shields.io/badge/github-quentinDupont%2Fgrap--odoo--incubator-lightgray.png?logo=github - :target: https://github.com/quentinDupont/grap-odoo-incubator/tree/12.0_ADD_web_widget_int_choice/web_widget_number_ux_choice - :alt: quentinDupont/grap-odoo-incubator - -|badge1| |badge2| |badge3| - -This widget changes input number field and make it easier to incremente the number thanks to 2 buttons (+ and -). -We can be parametred to choose the iteration step (0.1 for more precision etc.) - -**Table of contents** - -.. contents:: - :local: - -Usage -===== - -In your xml view, add ``widget="number_ux_choice"`` -This will add the 2 buttons +" and "-" just next to the input field in edit mode. -Iteration step by default is 1. - -.. figure:: https://raw.githubusercontent.com/quentinDupont/grap-odoo-incubator/12.0_ADD_web_widget_int_choice/web_widget_number_ux_choice/static/description/add_two_buttons.png - - -**Optional** -Add an option to choose the step iteration -Example for an 0.1 step : - -`` days`` - -**Examples** - -Iteration with 0.1 step - -.. figure:: https://raw.githubusercontent.com/quentinDupont/grap-odoo-incubator/12.0_ADD_web_widget_int_choice/web_widget_number_ux_choice/static/description/step0,1.gif - -Iteration with 10 step, with onchange - -.. figure:: https://raw.githubusercontent.com/quentinDupont/grap-odoo-incubator/12.0_ADD_web_widget_int_choice/web_widget_number_ux_choice/static/description/step10_with_onchange.gif - -Bug Tracker -=========== - -Bugs are tracked on `GitHub Issues `_. -In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. - -Do not contact contributors directly about support or help with technical issues. - -Credits -======= - -Authors -~~~~~~~ - -* GRAP - -Contributors -~~~~~~~~~~~~ - -* `GRAP `_: - - * Quentin DUPONT - -Maintainers -~~~~~~~~~~~ - -This module is part of the `quentinDupont/grap-odoo-incubator `_ project on GitHub. - -You are welcome to contribute. diff --git a/web_widget_number_ux_choice/readme/USAGE.rst b/web_widget_number_ux_choice/readme/USAGE.rst deleted file mode 100644 index c3fe11f50..000000000 --- a/web_widget_number_ux_choice/readme/USAGE.rst +++ /dev/null @@ -1,22 +0,0 @@ -In your xml view, add ``widget="number_ux_choice"`` -This will add the 2 buttons +" and "-" just next to the input field in edit mode. -Iteration step by default is 1. - -.. figure:: ../static/description/add_two_buttons.png - - -**Optional** -Add an option to choose the step iteration -Example for an 0.1 step : - -`` days`` - -**Examples** - -Iteration with 0.1 step - -.. figure:: ../static/description/step0,1.gif - -Iteration with 10 step, with onchange - -.. figure:: ../static/description/step10_with_onchange.gif diff --git a/web_widget_number_ux_choice/static/description/step0,1.gif b/web_widget_number_ux_choice/static/description/step0,1.gif deleted file mode 100644 index a2fc39acd..000000000 Binary files a/web_widget_number_ux_choice/static/description/step0,1.gif and /dev/null differ diff --git a/web_widget_number_ux_choice/static/description/step10_with_onchange.gif b/web_widget_number_ux_choice/static/description/step10_with_onchange.gif deleted file mode 100644 index 61645b282..000000000 Binary files a/web_widget_number_ux_choice/static/description/step10_with_onchange.gif and /dev/null differ diff --git a/web_widget_number_ux_choice/static/src/js/number_ux_choice.js b/web_widget_number_ux_choice/static/src/js/number_ux_choice.js deleted file mode 100644 index f44871967..000000000 --- a/web_widget_number_ux_choice/static/src/js/number_ux_choice.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) -* @author: Quentin DUPONT -* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) **/ - -odoo.define('web.web_widget_number_ux_choice', function(require) { - "use strict"; - - var basic_fields = require('web.basic_fields'); - var Registry = require('web.field_registry'); - // var session = require('web.session'); - // var rpc = require('web.rpc'); - // var pyUtils = require("web.py_utils"); - - /* - * Get precision for the @input field - */ - function getPrecision(input) { - if (!isFinite(input)) return 0; - var e = 1, p = 0; - while (Math.round(input * e) / e !== input) { e *= 10; p++; } - return p; - } - - /* - * @self : input field - * @step : must be Float - * @minusOrPlus : "minus" or "plus" - * - * set new value to @self */ - function addStep(self, step, minusOrPlus) { - var oldVal= parseFloat(self._getValue()); - var precision = Math.max(getPrecision(oldVal), getPrecision(step)) - if (minusOrPlus == "minus") { - step = -step - } - var newVal = oldVal + step; - var newVal_s = newVal.toFixed(precision).toString(); - self._setValue(newVal_s); - self.$input[0].value = newVal_s; - } - - var NumberUxChoice = basic_fields.FieldFloat.extend({ - template: 'NumberUxChoice', - - _render: function () { - var self = this; - this._super(); - this.$("button").parents().removeClass("o_field_integer o_field_number o_input o_required_modifier"); - this.$("button").click(function() { - var node = $(this).parent()[0]; - - // Get step option or default is 1 - if (typeof node.attributes['step'] !== 'undefined') { - var step = parseFloat(node.attributes['step'].value); - } else { - var step = 1; - } - // PLUS button - if ($(this).hasClass("btn_number_ux_choice_plus")) { - addStep(self, step, "plus") - // MINUS button - } else if ($(this).hasClass("btn_number_ux_choice_minus")){ - addStep(self, step, "minus") - - }; - }); - }, - - }); - - Registry.add('number_ux_choice', NumberUxChoice); - -}); diff --git a/web_widget_number_ux_choice/static/src/scss/number_ux_choice.scss b/web_widget_number_ux_choice/static/src/scss/number_ux_choice.scss deleted file mode 100644 index 303ca36be..000000000 --- a/web_widget_number_ux_choice/static/src/scss/number_ux_choice.scss +++ /dev/null @@ -1,11 +0,0 @@ - -.input_number_ux_choice { - width: 71% !important; -} - -.btns_number_ux_choice { - width: 27% !important; - button { - height: 25px; - } -} diff --git a/web_widget_number_ux_choice/view/web_widget_number_ux_choice.xml b/web_widget_number_ux_choice/view/web_widget_number_ux_choice.xml deleted file mode 100644 index 7c53bdd0f..000000000 --- a/web_widget_number_ux_choice/view/web_widget_number_ux_choice.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - diff --git a/web_widget_numeric_step/README.rst b/web_widget_numeric_step/README.rst new file mode 100644 index 000000000..4e45fa408 --- /dev/null +++ b/web_widget_numeric_step/README.rst @@ -0,0 +1,90 @@ +======================= +Web Widget Numeric Step +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-quentinDupont%2Fweb-lightgray.png?logo=github + :target: https://github.com/quentinDupont/web/tree/12.0_ADD_web_widget_ux_choice/web_widget_numeric_step + :alt: quentinDupont/web + +|badge1| |badge2| |badge3| + +This widget changes input number field and make it easier to incremente the number thanks to 2 buttons (+ and -). +Use JS native logic for input number, so you can use the options ``min``, ``max``, ``step``, ``placeholder``. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In your xml view, add ``widget="numeric_step"`` +This will add the 2 buttons "+" and "-" just next to the input field in edit mode. +Iteration step by default is 1. + +.. figure:: https://raw.githubusercontent.com/quentinDupont/web/12.0_ADD_web_widget_ux_choice/web_widget_numeric_step/static/description/add_two_buttons.png + + +**Optional** + +Add an option to choose the step iteration and limits (min and max values). + +Example for an 0.25 step, min to -1 and max to 10 : + +`` days`` + +**Examples** + +Iteration with 0.25 step, min to -1 and max to 10. + +Start to incremente with button, continue incrementing with scrolling mouse. + +.. figure:: https://raw.githubusercontent.com/quentinDupont/web/12.0_ADD_web_widget_ux_choice/web_widget_numeric_step/static/description/step0,25andlimits.gif + +Iteration with 10 step, max limit 15, placeholder with onchange + +.. figure:: https://raw.githubusercontent.com/quentinDupont/web/12.0_ADD_web_widget_ux_choice/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* `GRAP `_: + + * Quentin DUPONT + +Maintainers +~~~~~~~~~~~ + +This module is part of the `quentinDupont/web `_ project on GitHub. + +You are welcome to contribute. diff --git a/web_widget_number_ux_choice/__init__.py b/web_widget_numeric_step/__init__.py similarity index 100% rename from web_widget_number_ux_choice/__init__.py rename to web_widget_numeric_step/__init__.py diff --git a/web_widget_number_ux_choice/__manifest__.py b/web_widget_numeric_step/__manifest__.py similarity index 67% rename from web_widget_number_ux_choice/__manifest__.py rename to web_widget_numeric_step/__manifest__.py index 83ca48ab1..7830c8688 100644 --- a/web_widget_number_ux_choice/__manifest__.py +++ b/web_widget_numeric_step/__manifest__.py @@ -1,8 +1,8 @@ -# Odoo, Open Source Web Widget Integer Choice +# Odoo, Open Source Web Widget Numeric Step # # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).# { - 'name': "Web Widget UX Number Choice", + 'name': "Web Widget Numeric Step", 'category': "web", 'version': "12.0.1.0.0", 'author': "GRAP, " @@ -11,10 +11,10 @@ 'website': 'https://github.com/OCA/web', 'depends': ['web'], 'data': [ - 'view/web_widget_number_ux_choice.xml' + 'view/web_widget_numeric_step.xml' ], 'qweb': [ - 'static/src/xml/number_ux_choice.xml', + 'static/src/xml/numeric_step.xml', ], 'auto_install': False, 'installable': True, diff --git a/web_widget_number_ux_choice/i18n/fr.po b/web_widget_numeric_step/i18n/fr.po similarity index 100% rename from web_widget_number_ux_choice/i18n/fr.po rename to web_widget_numeric_step/i18n/fr.po diff --git a/web_widget_number_ux_choice/readme/CONTRIBUTORS.rst b/web_widget_numeric_step/readme/CONTRIBUTORS.rst similarity index 100% rename from web_widget_number_ux_choice/readme/CONTRIBUTORS.rst rename to web_widget_numeric_step/readme/CONTRIBUTORS.rst diff --git a/web_widget_number_ux_choice/readme/DESCRIPTION.rst b/web_widget_numeric_step/readme/DESCRIPTION.rst similarity index 51% rename from web_widget_number_ux_choice/readme/DESCRIPTION.rst rename to web_widget_numeric_step/readme/DESCRIPTION.rst index f1a22d2b4..f4906b4ab 100644 --- a/web_widget_number_ux_choice/readme/DESCRIPTION.rst +++ b/web_widget_numeric_step/readme/DESCRIPTION.rst @@ -1,2 +1,2 @@ This widget changes input number field and make it easier to incremente the number thanks to 2 buttons (+ and -). -We can be parametred to choose the iteration step (0.1 for more precision etc.) \ No newline at end of file +Use JS native logic for input number, so you can use the options ``min``, ``max``, ``step``, ``placeholder``. \ No newline at end of file diff --git a/web_widget_numeric_step/readme/USAGE.rst b/web_widget_numeric_step/readme/USAGE.rst new file mode 100644 index 000000000..47aaf790c --- /dev/null +++ b/web_widget_numeric_step/readme/USAGE.rst @@ -0,0 +1,26 @@ +In your xml view, add ``widget="numeric_step"`` +This will add the 2 buttons "+" and "-" just next to the input field in edit mode. +Iteration step by default is 1. + +.. figure:: ../static/description/add_two_buttons.png + + +**Optional** + +Add an option to choose the step iteration and limits (min and max values). + +Example for an 0.25 step, min to -1 and max to 10 : + +`` days`` + +**Examples** + +Iteration with 0.25 step, min to -1 and max to 10. + +Start to incremente with button, continue incrementing with scrolling mouse. + +.. figure:: ../static/description/step0,25andlimits.gif + +Iteration with 10 step, max limit 15, placeholder with onchange + +.. figure:: ../static/description/step10_limit15_placeholder117_with_onchange.gif diff --git a/web_widget_number_ux_choice/static/description/add_two_buttons.png b/web_widget_numeric_step/static/description/add_two_buttons.png similarity index 100% rename from web_widget_number_ux_choice/static/description/add_two_buttons.png rename to web_widget_numeric_step/static/description/add_two_buttons.png diff --git a/web_widget_number_ux_choice/static/description/icon.png b/web_widget_numeric_step/static/description/icon.png similarity index 100% rename from web_widget_number_ux_choice/static/description/icon.png rename to web_widget_numeric_step/static/description/icon.png diff --git a/web_widget_number_ux_choice/static/description/index.html b/web_widget_numeric_step/static/description/index.html similarity index 80% rename from web_widget_number_ux_choice/static/description/index.html rename to web_widget_numeric_step/static/description/index.html index 92dfe7ed4..c838ff91f 100644 --- a/web_widget_number_ux_choice/static/description/index.html +++ b/web_widget_numeric_step/static/description/index.html @@ -4,7 +4,7 @@ -Web Widget UX Number Choice +Web Widget Numeric Step -
-

Web Widget UX Number Choice

+
+

Web Widget Numeric Step

-

Beta License: AGPL-3 quentinDupont/grap-odoo-incubator

+

Beta License: AGPL-3 quentinDupont/web

This widget changes input number field and make it easier to incremente the number thanks to 2 buttons (+ and -). -We can be parametred to choose the iteration step (0.1 for more precision etc.)

+Use JS native logic for input number, so you can use the options min, max, step, placeholder.

Table of contents

    @@ -385,32 +385,33 @@ We can be parametred to choose the iteration step (0.1 for more precision etc.)<

Usage

-

In your xml view, add widget="number_ux_choice" -This will add the 2 buttons +” and “-” just next to the input field in edit mode. +

In your xml view, add widget="numeric_step" +This will add the 2 buttons “+” and “-” just next to the input field in edit mode. Iteration step by default is 1.

-https://raw.githubusercontent.com/quentinDupont/grap-odoo-incubator/12.0_ADD_web_widget_int_choice/web_widget_number_ux_choice/static/description/add_two_buttons.png +https://raw.githubusercontent.com/quentinDupont/web/12.0_ADD_web_widget_ux_choice/web_widget_numeric_step/static/description/add_two_buttons.png
-

Optional -Add an option to choose the step iteration -Example for an 0.1 step :

-

<field name="sale_delay" widget="number_ux_choice" options="{'step': 0.1}" /> days

+

Optional

+

Add an option to choose the step iteration and limits (min and max values).

+

Example for an 0.25 step, min to -1 and max to 10 :

+

<field name="sale_delay" widget="numeric_step" options="{'step': 0.25, 'min': -1, 'max': 10}" /> days

Examples

-

Iteration with 0.1 step

+

Iteration with 0.25 step, min to -1 and max to 10.

+

Start to incremente with button, continue incrementing with scrolling mouse.

-https://raw.githubusercontent.com/quentinDupont/grap-odoo-incubator/12.0_ADD_web_widget_int_choice/web_widget_number_ux_choice/static/description/step0,1.gif +https://raw.githubusercontent.com/quentinDupont/web/12.0_ADD_web_widget_ux_choice/web_widget_numeric_step/static/description/step0,25andlimits.gif
-

Iteration with 10 step, with onchange

+

Iteration with 10 step, max limit 15, placeholder with onchange

-https://raw.githubusercontent.com/quentinDupont/grap-odoo-incubator/12.0_ADD_web_widget_int_choice/web_widget_number_ux_choice/static/description/step10_with_onchange.gif +https://raw.githubusercontent.com/quentinDupont/web/12.0_ADD_web_widget_ux_choice/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -432,7 +433,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Maintainers

-

This module is part of the quentinDupont/grap-odoo-incubator project on GitHub.

+

This module is part of the quentinDupont/web project on GitHub.

You are welcome to contribute.

diff --git a/web_widget_numeric_step/static/description/step0,25andlimits.gif b/web_widget_numeric_step/static/description/step0,25andlimits.gif new file mode 100644 index 000000000..1e5827236 Binary files /dev/null and b/web_widget_numeric_step/static/description/step0,25andlimits.gif differ diff --git a/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif b/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif new file mode 100644 index 000000000..eb0b6e815 Binary files /dev/null and b/web_widget_numeric_step/static/description/step10_limit15_placeholder117_with_onchange.gif differ diff --git a/web_widget_numeric_step/static/src/js/numeric_step.js b/web_widget_numeric_step/static/src/js/numeric_step.js new file mode 100644 index 000000000..ca54e891b --- /dev/null +++ b/web_widget_numeric_step/static/src/js/numeric_step.js @@ -0,0 +1,95 @@ +/** +* Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) +* @author: Quentin DUPONT +* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) **/ + +odoo.define('web.web_widget_numeric_step', function(require) { + "use strict"; + + var Registry = require('web.field_registry'); + var NumericStep = require('web.basic_fields').FieldFloat; + + /** + * Get decimal precision for the input field + * + * @param {object} input Input field + * @return {int} Precision + */ + function getPrecision(input) { + if (!isFinite(input)) return 0; + var ten_multiple = 1, precision = 0; + while (Math.round(input * ten_multiple) / ten_multiple !== input) { + ten_multiple *= 10; + precision++; + } + return precision; + } + + /** + * Increase input number with chosen step iteration + * + * @param {object} self Input field + * @param {Float} step Step iteration + * @param {String} minusOrPlus Choose "minus" to decrease. Default is "plus" + */ + function addStep(self, step, minusOrPlus) { + var oldVal= parseFloat(self._getValue()); + var precision = Math.max(getPrecision(oldVal), getPrecision(step)) + if (minusOrPlus == "minus") { + step = -step + } + var newVal = oldVal + step; + // Check input limits + if (newVal > self.attrs.options.max) { + newVal = self.attrs.options.max; + } else if (newVal < self.attrs.options.min) { + newVal = self.attrs.options.min; + } + var newVal_s = newVal.toFixed(precision).toString(); + self._setValue(newVal_s); + self.$input[0].value = newVal_s; + } + + + NumericStep.include({ + template: 'web_widget_numeric_step', + + _render: function () { + var self = this; + // Use native options for input number + this.nodeOptions['type'] = "number"; + this._super(); + + // Add native options for input number + var input_number_options = ['max', 'min', 'placeholder', 'step']; + for (var options of input_number_options) { + if (typeof this.nodeOptions[options] !== 'undefined') { + this.$el[0][options] = this.nodeOptions[options]; + } + } + + this.$("button").parents().removeClass("o_field_integer o_field_number o_input o_required_modifier"); + this.$("button").click(function() { + var node = $(this).parent()[0]; + + // Get step option or default is 1 + if (typeof node.attributes['step'] !== 'undefined') { + var step = parseFloat(node.attributes['step'].value); + } else { + var step = 1; + } + // PLUS button + if ($(this).hasClass("btn_numeric_step_plus")) { + addStep(self, step, "plus") + // MINUS button + } else if ($(this).hasClass("btn_numeric_step_minus")){ + addStep(self, step, "minus") + + }; + }); + }, + }); + + Registry.add('numeric_step', NumericStep); + +}); diff --git a/web_widget_numeric_step/static/src/scss/numeric_step.scss b/web_widget_numeric_step/static/src/scss/numeric_step.scss new file mode 100644 index 000000000..df61457fc --- /dev/null +++ b/web_widget_numeric_step/static/src/scss/numeric_step.scss @@ -0,0 +1,29 @@ + +.input_numeric_step { + width: 71% !important; +} + +.btns_numeric_step { + width: 27% !important; + button { + height: 25px; + } +} + +/* Turn Off Number Input Spinners */ +input{ + /* Firefox */ + -moz-appearance: textfield; + + /* Chrome */ + &::-webkit-inner-spin-button { + -webkit-appearance: none; + margin:0; + } + + /* Opéra*/ + &::-o-inner-spin-button { + -o-appearance: none; + margin: 0; + } +} diff --git a/web_widget_number_ux_choice/static/src/xml/number_ux_choice.xml b/web_widget_numeric_step/static/src/xml/numeric_step.xml similarity index 61% rename from web_widget_number_ux_choice/static/src/xml/number_ux_choice.xml rename to web_widget_numeric_step/static/src/xml/numeric_step.xml index 00baada9d..904e4c14c 100644 --- a/web_widget_number_ux_choice/static/src/xml/number_ux_choice.xml +++ b/web_widget_numeric_step/static/src/xml/numeric_step.xml @@ -5,11 +5,11 @@ Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> - + - -
-
diff --git a/web_widget_numeric_step/view/web_widget_numeric_step.xml b/web_widget_numeric_step/view/web_widget_numeric_step.xml new file mode 100644 index 000000000..bfeb67b5a --- /dev/null +++ b/web_widget_numeric_step/view/web_widget_numeric_step.xml @@ -0,0 +1,9 @@ + + + +