From 603cbf3f240fbb479080666f727aee1ce6dd4581 Mon Sep 17 00:00:00 2001 From: Anna Janiszewska Date: Fri, 27 Sep 2024 15:15:10 +0200 Subject: [PATCH] [MIG] web_select_all_companies: Backporting from 15.0 to 14.0 --- .../odoo/addons/web_select_all_companies | 1 + setup/web_select_all_companies/setup.py | 6 ++ web_select_all_companies/README.rst | 12 +-- web_select_all_companies/__manifest__.py | 13 +-- .../static/description/index.html | 20 +++-- .../src/js/switch_all_company_menu.esm.js | 45 ---------- .../static/src/js/switch_all_company_menu.js | 89 +++++++++++++++++++ .../src/xml/switch_all_company_menu.xml | 54 +++++------ .../views/web_select_all_companies.xml | 15 ++++ 9 files changed, 159 insertions(+), 96 deletions(-) create mode 120000 setup/web_select_all_companies/odoo/addons/web_select_all_companies create mode 100644 setup/web_select_all_companies/setup.py delete mode 100644 web_select_all_companies/static/src/js/switch_all_company_menu.esm.js create mode 100644 web_select_all_companies/static/src/js/switch_all_company_menu.js create mode 100644 web_select_all_companies/views/web_select_all_companies.xml diff --git a/setup/web_select_all_companies/odoo/addons/web_select_all_companies b/setup/web_select_all_companies/odoo/addons/web_select_all_companies new file mode 120000 index 000000000000..012ec121cc9e --- /dev/null +++ b/setup/web_select_all_companies/odoo/addons/web_select_all_companies @@ -0,0 +1 @@ +../../../../web_select_all_companies \ No newline at end of file diff --git a/setup/web_select_all_companies/setup.py b/setup/web_select_all_companies/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/web_select_all_companies/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_select_all_companies/README.rst b/web_select_all_companies/README.rst index 5ac7662ab508..0765eff92682 100644 --- a/web_select_all_companies/README.rst +++ b/web_select_all_companies/README.rst @@ -17,20 +17,20 @@ Web Select All Companies :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :alt: License: LGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github - :target: https://github.com/OCA/web/tree/15.0/web_select_all_companies + :target: https://github.com/OCA/web/tree/14.0/web_select_all_companies :alt: OCA/web .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_select_all_companies + :target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_select_all_companies :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=15.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=14.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| This module allows you to select or deselect all the companies in a single click. -.. image:: https://raw.githubusercontent.com/OCA/web/15.0/web_select_all_companies/static/description/select_all_companies.png +.. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_select_all_companies/static/description/select_all_companies.png **Table of contents** @@ -43,7 +43,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -73,6 +73,6 @@ 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. +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_select_all_companies/__manifest__.py b/web_select_all_companies/__manifest__.py index 8631477f3afe..a44c3132e379 100644 --- a/web_select_all_companies/__manifest__.py +++ b/web_select_all_companies/__manifest__.py @@ -4,20 +4,13 @@ { "name": "Web Select All Companies", "summary": "Allows you to select all companies in one click.", - "version": "15.0.1.0.0", + "version": "14.0.1.0.0", "category": "Web", "website": "https://github.com/OCA/web", "author": "Camptocamp, Odoo Community Association (OCA)", "license": "LGPL-3", "depends": ["web"], - "assets": { - "web.assets_qweb": [ - "web_select_all_companies/static/src/xml/switch_all_company_menu.xml", - ], - "web.assets_backend": [ - "web_select_all_companies/static/src/scss/switch_all_company_menu.scss", - "web_select_all_companies/static/src/js/switch_all_company_menu.esm.js", - ], - }, + "qweb": ["static/src/xml/switch_all_company_menu.xml"], + "data": ["views/web_select_all_companies.xml"], "installable": True, } diff --git a/web_select_all_companies/static/description/index.html b/web_select_all_companies/static/description/index.html index b81fbbf289a1..c99a0c885215 100644 --- a/web_select_all_companies/static/description/index.html +++ b/web_select_all_companies/static/description/index.html @@ -1,3 +1,4 @@ + @@ -8,10 +9,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +276,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +302,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -368,9 +370,9 @@

Web Select All Companies

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:b2dd44d037d4c1129717952faf30f486f1ce3387df2f7a839ebed82e58bb1197 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

This module allows you to select or deselect all the companies in a single click.

-https://raw.githubusercontent.com/OCA/web/15.0/web_select_all_companies/static/description/select_all_companies.png +https://raw.githubusercontent.com/OCA/web/14.0/web_select_all_companies/static/description/select_all_companies.png

Table of contents

    @@ -388,7 +390,7 @@

    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.

    +feedback.

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

@@ -408,11 +410,13 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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.

+

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_select_all_companies/static/src/js/switch_all_company_menu.esm.js b/web_select_all_companies/static/src/js/switch_all_company_menu.esm.js deleted file mode 100644 index c67fca2e59eb..000000000000 --- a/web_select_all_companies/static/src/js/switch_all_company_menu.esm.js +++ /dev/null @@ -1,45 +0,0 @@ -/** @odoo-module **/ -/* Copyright 2023 Camptocamp - Telmo Santos - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -import {SwitchCompanyMenu} from "@web/webclient/switch_company_menu/switch_company_menu"; -import {browser} from "@web/core/browser/browser"; -import {patch} from "@web/core/utils/patch"; - -patch(SwitchCompanyMenu.prototype, "SwitchAllCompanyMenu", { - setup() { - this._super(...arguments); - this.allCompanyIds = Object.values(this.companyService.availableCompanies).map( - (x) => x.id - ); - this.isAllCompaniesSelected = this.allCompanyIds.every((elem) => - this.selectedCompanies.includes(elem) - ); - }, - - toggleSelectAllCompanies() { - if (this.isAllCompaniesSelected) { - // Deselect all - this.state.companiesToToggle = this.allCompanyIds; - this.toggleCompany(this.currentCompany.id); - this.isAllCompaniesSelected = false; - browser.clearTimeout(this.toggleTimer); - this.toggleTimer = browser.setTimeout(() => { - this.companyService.setCompanies( - "toggle", - ...this.state.companiesToToggle - ); - }, this.constructor.toggleDelay); - } else { - // Select all - this.state.companiesToToggle = [this.allCompanyIds]; - this.isAllCompaniesSelected = true; - browser.clearTimeout(this.toggleTimer); - this.toggleTimer = browser.setTimeout(() => { - this.companyService.setCompanies( - "loginto", - ...this.state.companiesToToggle - ); - }, this.constructor.toggleDelay); - } - }, -}); diff --git a/web_select_all_companies/static/src/js/switch_all_company_menu.js b/web_select_all_companies/static/src/js/switch_all_company_menu.js new file mode 100644 index 000000000000..2eaadf646536 --- /dev/null +++ b/web_select_all_companies/static/src/js/switch_all_company_menu.js @@ -0,0 +1,89 @@ +/* Copyright 2023 Camptocamp - Telmo Santos + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +odoo.define( + "web_select_all_companies/static/src/js/switch_all_company_menu.js", + function (require) { + "use strict"; + + var session = require("web.session"); + var SwitchCompanyMenu = require("web.SwitchCompanyMenu"); + + SwitchCompanyMenu.include({ + init() { + this._super.apply(this, arguments); + this.allCompanyIds = session.user_companies.allowed_companies.map( + (x) => x[0] + ); + // Get allowed companies from user context and compare with all companies to check if all companies are selected or not + // and set flag accordingly + this.allowed_company_ids = session.user_context.allowed_company_ids; + this.isAllCompaniesSelected = + this.allowed_company_ids.length == this.allCompanyIds.length; + }, + + /** + * @private + * @param {MouseEvent|KeyEvent} ev + */ + _onToggleCompanyClick: function (ev) { + if ( + ev.type == "keydown" && + ev.which != $.ui.keyCode.ENTER && + ev.which != $.ui.keyCode.SPACE + ) { + return; + } + ev.preventDefault(); + ev.stopPropagation(); + var dropdownItem = $(ev.currentTarget).parent(); + var companyID = dropdownItem.data("company-id"); + var dropdownMenu = dropdownItem.parent(); + var all_items = dropdownMenu.children(); + var toggle_company_div = all_items[0].children[0]; + var toggle_company_i = toggle_company_div.children[0].children[0]; + if (!companyID) { + // Calculate length - 1 because one element is the 'toggle all companies' item + this.isAllCompaniesSelected = + dropdownMenu.find(".fa-check-square").length - 1 == + this.allCompanyIds.length; + // Deselect all companies by toggling class on html elements and setting company data in session + if (this.isAllCompaniesSelected) { + all_items + .find(".fa-check-square") + .removeClass("fa-check-square") + .addClass("fa-square-o"); + toggle_company_i.classList.replace( + "fa-check-square", + "fa-square-o" + ); + $(ev.currentTarget).attr("aria-checked", "false"); + session.setCompanies(this.allowed_company_ids[0], []); + session.user_context.allowed_company_ids = []; + } else { + // Select all companies by toggling class on html elements and setting company data in session + var allowed_company_ids = this.allowed_company_ids; + var current_company_id = allowed_company_ids[0]; + _.each(this.allCompanyIds, (company_id) => { + if (!allowed_company_ids.includes(company_id)) { + allowed_company_ids.push(company_id); + } + }); + all_items + .find(".fa-check-square") + .removeClass("fa-square-o") + .addClass("fa-check-square"); + toggle_company_i.classList.replace( + "fa-square-o", + "fa-check-square" + ); + $(ev.currentTarget).attr("aria-checked", "true"); + session.setCompanies(current_company_id, allowed_company_ids); + } + } else { + return this._super.apply(this, arguments); + } + }, + }); + } +); diff --git a/web_select_all_companies/static/src/xml/switch_all_company_menu.xml b/web_select_all_companies/static/src/xml/switch_all_company_menu.xml index 5c76e271f4d6..a31b4111ecd5 100644 --- a/web_select_all_companies/static/src/xml/switch_all_company_menu.xml +++ b/web_select_all_companies/static/src/xml/switch_all_company_menu.xml @@ -4,36 +4,36 @@ t-name="web_select_all_companies.SwitchAllCompanyMenu" t-inherit="web.SwitchCompanyMenu" t-inherit-mode="extension" - owl="1" > - -
-
- - - -
-
- All Companies -
+ diff --git a/web_select_all_companies/views/web_select_all_companies.xml b/web_select_all_companies/views/web_select_all_companies.xml new file mode 100644 index 000000000000..669764ac8a6c --- /dev/null +++ b/web_select_all_companies/views/web_select_all_companies.xml @@ -0,0 +1,15 @@ + + +