From c4400a72f7a6b57de07a726fc9c48b86784ccf5d Mon Sep 17 00:00:00 2001 From: Alexandre Saunier Date: Mon, 11 Mar 2019 16:34:50 +0100 Subject: [PATCH] [ADD] web_widget_text_count --- .../odoo/addons/web_widget_text_count | 1 + setup/web_widget_text_count/setup.py | 6 + web_widget_text_count/README.rst | 80 ++++ web_widget_text_count/__init__.py | 0 web_widget_text_count/__manifest__.py | 17 + web_widget_text_count/readme/CONTRIBUTORS.rst | 3 + web_widget_text_count/readme/DESCRIPTION.rst | 4 + web_widget_text_count/readme/ROADMAP.rst | 3 + web_widget_text_count/readme/USAGE.rst | 5 + .../static/description/index.html | 426 ++++++++++++++++++ .../static/src/js/fields_text_count.js | 50 ++ .../static/src/scss/field_text_count.scss | 12 + web_widget_text_count/views/templates.xml | 9 + 13 files changed, 616 insertions(+) create mode 120000 setup/web_widget_text_count/odoo/addons/web_widget_text_count create mode 100644 setup/web_widget_text_count/setup.py create mode 100644 web_widget_text_count/README.rst create mode 100644 web_widget_text_count/__init__.py create mode 100644 web_widget_text_count/__manifest__.py create mode 100644 web_widget_text_count/readme/CONTRIBUTORS.rst create mode 100644 web_widget_text_count/readme/DESCRIPTION.rst create mode 100644 web_widget_text_count/readme/ROADMAP.rst create mode 100644 web_widget_text_count/readme/USAGE.rst create mode 100644 web_widget_text_count/static/description/index.html create mode 100644 web_widget_text_count/static/src/js/fields_text_count.js create mode 100644 web_widget_text_count/static/src/scss/field_text_count.scss create mode 100644 web_widget_text_count/views/templates.xml diff --git a/setup/web_widget_text_count/odoo/addons/web_widget_text_count b/setup/web_widget_text_count/odoo/addons/web_widget_text_count new file mode 120000 index 000000000000..86fd66cd27ca --- /dev/null +++ b/setup/web_widget_text_count/odoo/addons/web_widget_text_count @@ -0,0 +1 @@ +../../../../web_widget_text_count \ No newline at end of file diff --git a/setup/web_widget_text_count/setup.py b/setup/web_widget_text_count/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/web_widget_text_count/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_widget_text_count/README.rst b/web_widget_text_count/README.rst new file mode 100644 index 000000000000..1404b5ff8132 --- /dev/null +++ b/web_widget_text_count/README.rst @@ -0,0 +1,80 @@ +========================= +Web Textarea with Counter +========================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/12.0/web_text_count_field + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_text_count_field + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Widget ``text_count`` displays a character counter next to the text field. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +.. code-block:: xml + + + +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 +~~~~~~~ + +* Camptocamp SA + +Contributors +~~~~~~~~~~~~ + +* Yannick Vaucher + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_text_count/__init__.py b/web_widget_text_count/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/web_widget_text_count/__manifest__.py b/web_widget_text_count/__manifest__.py new file mode 100644 index 000000000000..3f98edbe9270 --- /dev/null +++ b/web_widget_text_count/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2019 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Web Textarea with Counter", + "category": "Web", + "version": "12.0.1.0.0", + "author": "Camptocamp SA, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "license": "AGPL-3", + "depends": [ + 'web', + ], + 'data': [ + 'views/templates.xml', + ], + 'installable': True, +} diff --git a/web_widget_text_count/readme/CONTRIBUTORS.rst b/web_widget_text_count/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..d1ad79c4f2e2 --- /dev/null +++ b/web_widget_text_count/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Yannick Vaucher +* Simone Orsi +* Vyshnevska Iryna diff --git a/web_widget_text_count/readme/DESCRIPTION.rst b/web_widget_text_count/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..a664ca45ec73 --- /dev/null +++ b/web_widget_text_count/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Widget ``text_count`` displays a character counter next to the text field. +If in xml you setup additional attribute size for this field, counter will show +amount characters you left for this field, and will prohibit further input when +maximum is reached. diff --git a/web_widget_text_count/readme/ROADMAP.rst b/web_widget_text_count/readme/ROADMAP.rst new file mode 100644 index 000000000000..c6be1fce7774 --- /dev/null +++ b/web_widget_text_count/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +Patch Text class on Python level to allow propagation of size same as in Char fields. +At the moment the size attribute can be applied only as an attribute on the tag. +Support inline position of the counter next to the textarea. diff --git a/web_widget_text_count/readme/USAGE.rst b/web_widget_text_count/readme/USAGE.rst new file mode 100644 index 000000000000..2f2390aeb26d --- /dev/null +++ b/web_widget_text_count/readme/USAGE.rst @@ -0,0 +1,5 @@ +.. code-block:: xml + + + or + diff --git a/web_widget_text_count/static/description/index.html b/web_widget_text_count/static/description/index.html new file mode 100644 index 000000000000..b0873169f133 --- /dev/null +++ b/web_widget_text_count/static/description/index.html @@ -0,0 +1,426 @@ + + + + + + +Web Textarea with Counter + + + +
+

Web Textarea with Counter

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

Widget text_count displays a character counter next to the text field.

+

Table of contents

+ +
+

Usage

+
+<field name="text" widget="text_count" colspan="2"/>
+
+
+
+

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

+
    +
  • Camptocamp SA
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

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

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_widget_text_count/static/src/js/fields_text_count.js b/web_widget_text_count/static/src/js/fields_text_count.js new file mode 100644 index 000000000000..7263d1e369a0 --- /dev/null +++ b/web_widget_text_count/static/src/js/fields_text_count.js @@ -0,0 +1,50 @@ +odoo.define('text_count', function(require) { + "use strict"; + + var registry = require('web.field_registry'); + var basicFields = require('web.basic_fields'); + var FieldText = basicFields.FieldText; + + var FieldTextCount = FieldText.extend({ + events: _.extend({}, FieldText.prototype.events, { + 'input': 'count_char', + }), + supportedFieldTypes: ['text'], + + start: function () { + var self = this; + return this._super().then(function(){ + var size = 0 + if (self.mode === 'edit') { + if (self.attrs.size) { + self.$el.attr('maxlength', parseInt(self.attrs.size)); + size = self.attrs.size - self.$el.val().length; + } + else{ + size = self.$el.val().length; + } + self.$el = self.$el.add($('')); + } + }); + }, + + count_char: function (e) { + var $textarea = this.$el, + maxlength = parseInt($textarea.attr('maxlength'), 10), + $counter = $textarea.siblings('.text-counter-widget'); + if (maxlength){ + var left = maxlength - $textarea.val().length; + if (left < 0) { + left = 0; + } + } + else{ + left = $textarea.val().length; + } + $counter.val(left); + }, + + }); + + registry.add('text_count', FieldTextCount); +}); diff --git a/web_widget_text_count/static/src/scss/field_text_count.scss b/web_widget_text_count/static/src/scss/field_text_count.scss new file mode 100644 index 000000000000..495174e6fe65 --- /dev/null +++ b/web_widget_text_count/static/src/scss/field_text_count.scss @@ -0,0 +1,12 @@ +.text-counter-widget{ + background-color: transparent; + float: right; + white-space: pre-wrap; + border: 1px solid #ccc; + border-radius: 3px; + padding: 2px 4px; + color: #1f1f1f; + div.text-counter-widget { + white-space: pre-wrap; + } +} \ No newline at end of file diff --git a/web_widget_text_count/views/templates.xml b/web_widget_text_count/views/templates.xml new file mode 100644 index 000000000000..6f3674ad2c16 --- /dev/null +++ b/web_widget_text_count/views/templates.xml @@ -0,0 +1,9 @@ + + +