diff --git a/web_text_count_field/README.rst b/web_text_count_field/README.rst new file mode 100644 index 00000000..1404b5ff --- /dev/null +++ b/web_text_count_field/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_text_count_field/__init__.py b/web_text_count_field/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/web_text_count_field/__manifest__.py b/web_text_count_field/__manifest__.py new file mode 100644 index 00000000..510937af --- /dev/null +++ b/web_text_count_field/__manifest__.py @@ -0,0 +1,20 @@ +# 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', + ], + 'qweb': [ + 'static/src/xml/fields_text_count.xml', + ], + 'installable': True, +} diff --git a/web_text_count_field/readme/CONTRIBUTORS.rst b/web_text_count_field/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..477abbd4 --- /dev/null +++ b/web_text_count_field/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Yannick Vaucher diff --git a/web_text_count_field/readme/DESCRIPTION.rst b/web_text_count_field/readme/DESCRIPTION.rst new file mode 100644 index 00000000..92e5d629 --- /dev/null +++ b/web_text_count_field/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Widget ``text_count`` displays a character counter next to the text field. diff --git a/web_text_count_field/readme/USAGE.rst b/web_text_count_field/readme/USAGE.rst new file mode 100644 index 00000000..a30b8023 --- /dev/null +++ b/web_text_count_field/readme/USAGE.rst @@ -0,0 +1,3 @@ +.. code-block:: xml + + diff --git a/web_text_count_field/static/description/index.html b/web_text_count_field/static/description/index.html new file mode 100644 index 00000000..b0873169 --- /dev/null +++ b/web_text_count_field/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_text_count_field/static/src/js/fields_text_count.js b/web_text_count_field/static/src/js/fields_text_count.js new file mode 100644 index 00000000..9bd5c1cd --- /dev/null +++ b/web_text_count_field/static/src/js/fields_text_count.js @@ -0,0 +1,38 @@ +odoo.define('text_count', function(require) { + "use strict"; + + var registry = require('web.field_registry'); + var FieldText = require('web.FieldText'); + + var FieldTextCount = FieldText.extend({ + template: 'FieldTextCount', + + start: function () { + this._super(); + var $textarea = this.$element.find('textarea')[0]; + $textarea.addEventListener("keyup", this.count_char); + }, + + count_char: function (e) { + var len = this.value.length; + var counter = $(this.parentNode).find('span')[0]; + counter.innerHTML = len; + }, + + update_dom: function () { + this._super.apply(this, arguments); + var $textarea = this.$element.find('textarea')[0]; + this.$element.find('span')[0].innerHTML = $textarea.value.length; + } + }); + + registry.add('text_count', FieldTextCount); + + /* + // TODO? + var FieldTextCountReadonly = openerp.web.page.FieldCharReadonly.extend({ + force_readonly: true + }); + openerp.web.page.readonly.add('text_count', FieldTextCountReadonly); + */ +}); diff --git a/web_text_count_field/static/src/scss/field_text_count.scss b/web_text_count_field/static/src/scss/field_text_count.scss new file mode 100644 index 00000000..40118ef1 --- /dev/null +++ b/web_text_count_field/static/src/scss/field_text_count.scss @@ -0,0 +1,16 @@ +.oe_form_readonly { + .oe_form_frame_cell { + .field_text_count { + padding: 3px 2px 2px 2px; + background-color: white; + height: auto; + min-height:100px; + } + } + + .oe_form_field_text_count { + div.field_text_count { + white-space: pre-wrap; + } + } +} diff --git a/web_text_count_field/static/src/xml/fields_text_count.xml b/web_text_count_field/static/src/xml/fields_text_count.xml new file mode 100644 index 00000000..a327acea --- /dev/null +++ b/web_text_count_field/static/src/xml/fields_text_count.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/web_text_count_field/views/templates.xml b/web_text_count_field/views/templates.xml new file mode 100644 index 00000000..944a78a6 --- /dev/null +++ b/web_text_count_field/views/templates.xml @@ -0,0 +1,9 @@ + + +