diff --git a/web_widget_number_ux_choice/README.rst b/web_widget_number_ux_choice/README.rst new file mode 100644 index 000000000..7aee7a490 --- /dev/null +++ b/web_widget_number_ux_choice/README.rst @@ -0,0 +1,86 @@ +=========================== +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/__init__.py b/web_widget_number_ux_choice/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_widget_number_ux_choice/__manifest__.py b/web_widget_number_ux_choice/__manifest__.py new file mode 100644 index 000000000..83ca48ab1 --- /dev/null +++ b/web_widget_number_ux_choice/__manifest__.py @@ -0,0 +1,21 @@ +# Odoo, Open Source Web Widget Integer Choice +# +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).# +{ + 'name': "Web Widget UX Number Choice", + 'category': "web", + 'version': "12.0.1.0.0", + 'author': "GRAP, " + "Odoo Community Association (OCA)", + 'license': 'AGPL-3', + 'website': 'https://github.com/OCA/web', + 'depends': ['web'], + 'data': [ + 'view/web_widget_number_ux_choice.xml' + ], + 'qweb': [ + 'static/src/xml/number_ux_choice.xml', + ], + 'auto_install': False, + 'installable': True, +} diff --git a/web_widget_number_ux_choice/i18n/fr.po b/web_widget_number_ux_choice/i18n/fr.po new file mode 100644 index 000000000..3be7542a9 --- /dev/null +++ b/web_widget_number_ux_choice/i18n/fr.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_widget_number_ux_choice +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-08-30 12:07+0000\n" +"PO-Revision-Date: 2019-08-30 12:07+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_widget_number_ux_choice +#. openerp-web +#: code:addons/web_widget_number_ux_choice/static/src/xml/number_ux_choice.xml:12 +#, python-format +msgid "Minus" +msgstr "Moins" + +#. module: web_widget_number_ux_choice +#. openerp-web +#: code:addons/web_widget_number_ux_choice/static/src/xml/number_ux_choice.xml:12 +#, python-format +msgid "Plus" +msgstr "Plus" + diff --git a/web_widget_number_ux_choice/readme/CONTRIBUTORS.rst b/web_widget_number_ux_choice/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..65f8f81d1 --- /dev/null +++ b/web_widget_number_ux_choice/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `GRAP `_: + + * Quentin DUPONT diff --git a/web_widget_number_ux_choice/readme/DESCRIPTION.rst b/web_widget_number_ux_choice/readme/DESCRIPTION.rst new file mode 100644 index 000000000..f1a22d2b4 --- /dev/null +++ b/web_widget_number_ux_choice/readme/DESCRIPTION.rst @@ -0,0 +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 diff --git a/web_widget_number_ux_choice/readme/USAGE.rst b/web_widget_number_ux_choice/readme/USAGE.rst new file mode 100644 index 000000000..c3fe11f50 --- /dev/null +++ b/web_widget_number_ux_choice/readme/USAGE.rst @@ -0,0 +1,22 @@ +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/add_two_buttons.png b/web_widget_number_ux_choice/static/description/add_two_buttons.png new file mode 100644 index 000000000..2670f06ec Binary files /dev/null and b/web_widget_number_ux_choice/static/description/add_two_buttons.png differ diff --git a/web_widget_number_ux_choice/static/description/icon.png b/web_widget_number_ux_choice/static/description/icon.png new file mode 100644 index 000000000..3a662b992 Binary files /dev/null and b/web_widget_number_ux_choice/static/description/icon.png differ diff --git a/web_widget_number_ux_choice/static/description/index.html b/web_widget_number_ux_choice/static/description/index.html new file mode 100644 index 000000000..92dfe7ed4 --- /dev/null +++ b/web_widget_number_ux_choice/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Web Widget UX Number Choice + + + +
+

Web Widget UX Number Choice

+ + +

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

+

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

+ +
+

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.

+
+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 :

+

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

+

Examples

+

Iteration with 0.1 step

+
+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

+
+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

+ +
+
+

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/static/description/step0,1.gif b/web_widget_number_ux_choice/static/description/step0,1.gif new file mode 100644 index 000000000..a2fc39acd Binary files /dev/null and b/web_widget_number_ux_choice/static/description/step0,1.gif 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 new file mode 100644 index 000000000..61645b282 Binary files /dev/null and b/web_widget_number_ux_choice/static/description/step10_with_onchange.gif 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 new file mode 100644 index 000000000..f44871967 --- /dev/null +++ b/web_widget_number_ux_choice/static/src/js/number_ux_choice.js @@ -0,0 +1,74 @@ +/** +* 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 new file mode 100644 index 000000000..303ca36be --- /dev/null +++ b/web_widget_number_ux_choice/static/src/scss/number_ux_choice.scss @@ -0,0 +1,11 @@ + +.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/static/src/xml/number_ux_choice.xml b/web_widget_number_ux_choice/static/src/xml/number_ux_choice.xml new file mode 100644 index 000000000..00baada9d --- /dev/null +++ b/web_widget_number_ux_choice/static/src/xml/number_ux_choice.xml @@ -0,0 +1,19 @@ + + + + + + +
+
+
+ + + +
+
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 new file mode 100644 index 000000000..7c53bdd0f --- /dev/null +++ b/web_widget_number_ux_choice/view/web_widget_number_ux_choice.xml @@ -0,0 +1,9 @@ + + + +