diff --git a/setup/web_hide_field_with_key/odoo/addons/web_hide_field_with_key b/setup/web_hide_field_with_key/odoo/addons/web_hide_field_with_key new file mode 120000 index 000000000..cc679d051 --- /dev/null +++ b/setup/web_hide_field_with_key/odoo/addons/web_hide_field_with_key @@ -0,0 +1 @@ +../../../../web_hide_field_with_key \ No newline at end of file diff --git a/setup/web_hide_field_with_key/setup.py b/setup/web_hide_field_with_key/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_hide_field_with_key/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_hide_field_with_key/README.rst b/web_hide_field_with_key/README.rst new file mode 100644 index 000000000..2a983c419 --- /dev/null +++ b/web_hide_field_with_key/README.rst @@ -0,0 +1,95 @@ +======================== +Web hide field with keys +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b7fd81a70afbf20b3a6518d377df8e218ec47eb99304a692ef1c2e1fac4cb12d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/web_hide_field_with_key + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_hide_field_with_key + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This allows to hide field by pressing the "p" key on the keyboard + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Add the class web-hide-field to a field: + +:: + + + +Then press the "p" key and the field will disappear + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Francois Poizat + +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. + +.. |maintainer-franzpoize| image:: https://github.com/franzpoize.png?size=40px + :target: https://github.com/franzpoize + :alt: franzpoize + +Current `maintainer `__: + +|maintainer-franzpoize| + +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_hide_field_with_key/__init__.py b/web_hide_field_with_key/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_hide_field_with_key/__manifest__.py b/web_hide_field_with_key/__manifest__.py new file mode 100644 index 000000000..b74736b95 --- /dev/null +++ b/web_hide_field_with_key/__manifest__.py @@ -0,0 +1,18 @@ +{ + "name": "Web hide field with keys", + "summary": "Hide fields for models", + "category": "Misc", + "author": "Akretion,Odoo Community Association (OCA)", + "license": "AGPL-3", + "version": "16.0.1.0.0", + "depends": ["base", "product"], + "maintainers": ["franzpoize"], + "website": "https://github.com/OCA/web", + "assets": { + "web.assets_common": [ + "web_hide_field_with_key/static/src/js/**/*", + ], + }, + "data": [], + "external_dependencies": {}, +} diff --git a/web_hide_field_with_key/readme/CONTRIBUTORS.rst b/web_hide_field_with_key/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..7bf4caa02 --- /dev/null +++ b/web_hide_field_with_key/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Francois Poizat diff --git a/web_hide_field_with_key/readme/DESCRIPTION.rst b/web_hide_field_with_key/readme/DESCRIPTION.rst new file mode 100644 index 000000000..fb74b3481 --- /dev/null +++ b/web_hide_field_with_key/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This allows to hide field by pressing the "p" key on the keyboard diff --git a/web_hide_field_with_key/readme/USAGE.rst b/web_hide_field_with_key/readme/USAGE.rst new file mode 100644 index 000000000..4330d8ae4 --- /dev/null +++ b/web_hide_field_with_key/readme/USAGE.rst @@ -0,0 +1,7 @@ +Add the class web-hide-field to a field: + +:: + + + +Then press the "p" key and the field will disappear diff --git a/web_hide_field_with_key/static/description/index.html b/web_hide_field_with_key/static/description/index.html new file mode 100644 index 000000000..16b1b4d67 --- /dev/null +++ b/web_hide_field_with_key/static/description/index.html @@ -0,0 +1,431 @@ + + + + + +Web hide field with keys + + + +
+

Web hide field with keys

+ + +

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

+

This allows to hide field by pressing the ā€œpā€ key on the keyboard

+

Table of contents

+ +
+

Usage

+

Add the class web-hide-field to a field:

+
+<field name="name" class="web-hide-field">
+
+

Then press the ā€œpā€ key and the field will disappear

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

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.

+

Current maintainer:

+

franzpoize

+

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_hide_field_with_key/static/src/js/hide_custom_hidden_fields.js b/web_hide_field_with_key/static/src/js/hide_custom_hidden_fields.js new file mode 100644 index 000000000..90e461663 --- /dev/null +++ b/web_hide_field_with_key/static/src/js/hide_custom_hidden_fields.js @@ -0,0 +1,50 @@ +(function () { + "use strict"; + + // Those are weak because we don't want to prevent + // GC of the dom nodes when we leave a page + const elementStyleMap = new WeakMap(); + const alreadyRemove = new WeakSet(); + + function changeStyle(nodes) { + nodes.forEach((el) => { + if (el.style.display === "none") { + el.style.display = elementStyleMap.get(el) || "block"; + } else { + elementStyleMap.set(el, el.style.display); + el.style.display = "none"; + } + + if (el.tagName === "TD") { + const cellIndex = el.cellIndex; + const tableHead = el.parentNode.parentNode.previousSibling; + const header = tableHead.querySelectorAll("th")[cellIndex]; + header.style.display = el.style.display; + } + }); + } + + // Unfortunately we cannot trust the css because we need + // to store the base display style to restore it properly + function rafCallback() { + // Query only nodes that we did not already defaulted to none + const filteredNodes = Array.from( + document.querySelectorAll(".web-hide-field") + ).filter((e) => !alreadyRemove.has(e)); + // Add the filtered node to the weakset to avoid removing them multiple times + filteredNodes.forEach((e) => alreadyRemove.add(e)); + + if (filteredNodes.length > 0) { + changeStyle(filteredNodes); + } + requestAnimationFrame(rafCallback); + } + + rafCallback(); + + document.addEventListener("keypress", function (event) { + if (event.key === "p") { + changeStyle(document.querySelectorAll(".web-hide-field")); + } + }); +})();