Skip to content

Commit

Permalink
[MIG] web_select_all_companies: Backporting from 15.0 to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaniszewska-dev committed Oct 15, 2024
1 parent a29b090 commit f9d48ea
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 96 deletions.
6 changes: 6 additions & 0 deletions setup/web_select_all_companies/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
12 changes: 6 additions & 6 deletions web_select_all_companies/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -43,7 +43,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/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 <https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -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 <https://github.com/OCA/web/tree/15.0/web_select_all_companies>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/14.0/web_select_all_companies>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
13 changes: 3 additions & 10 deletions web_select_all_companies/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
20 changes: 12 additions & 8 deletions web_select_all_companies/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -8,10 +9,11 @@

/*
:Author: David Goodger ([email protected])
: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.
Expand Down Expand Up @@ -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 }
Expand All @@ -300,7 +302,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,9 +370,9 @@ <h1 class="title">Web Select All Companies</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b2dd44d037d4c1129717952faf30f486f1ce3387df2f7a839ebed82e58bb1197
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/15.0/web_select_all_companies"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_select_all_companies"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/14.0/web_select_all_companies"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_select_all_companies"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to select or deselect all the companies in a single click.</p>
<img alt="https://raw.githubusercontent.com/OCA/web/15.0/web_select_all_companies/static/description/select_all_companies.png" src="https://raw.githubusercontent.com/OCA/web/15.0/web_select_all_companies/static/description/select_all_companies.png" />
<img alt="https://raw.githubusercontent.com/OCA/web/14.0/web_select_all_companies/static/description/select_all_companies.png" src="https://raw.githubusercontent.com/OCA/web/14.0/web_select_all_companies/static/description/select_all_companies.png" />
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -388,7 +390,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_select_all_companies%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -408,11 +410,13 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_select_all_companies">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_select_all_companies">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down

This file was deleted.

89 changes: 89 additions & 0 deletions web_select_all_companies/static/src/js/switch_all_company_menu.js
Original file line number Diff line number Diff line change
@@ -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);
}
},
});
}
);
54 changes: 27 additions & 27 deletions web_select_all_companies/static/src/xml/switch_all_company_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@
t-name="web_select_all_companies.SwitchAllCompanyMenu"
t-inherit="web.SwitchCompanyMenu"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//t[@t-as='company']" position="before">
<DropdownItem class="p-0 bg-white">
<div class="d-flex">
<div
role="menuitemcheckbox"
tabindex="0"
t-attf-class="{{isCurrent ? 'border-primary' : ''}}"
class="border-end toggle_company"
t-on-click.stop="toggleSelectAllCompanies()"
>
<span class="btn btn-light border-0 p-2">
<i
class="fa fa-fw py-2 text-primary"
t-att-class="isAllCompaniesSelected ? 'fa-check-square text-primary' : 'fa-square-o'"
/>
</span>
</div>
<div
role="button"
tabindex="0"
class="d-flex flex-grow-1 align-items-center py-0 ps-2 ms-1 me-2 all-companies-item"
title="Select All Companies"
name="select_all_companies"
>
<span>All Companies</span>
</div>
<div class="dropdown-item d-flex py-0 px-0" data-menu="company">
<div
role="menuitemcheckbox"
tabindex="0"
class="ml-auto pl-3 pr-3 border border-top-0 border-left-0 border-bottom-0 toggle_company o_py"
>
<span class="height: 2rem;">
<t t-if="widget.isAllCompaniesSelected">
<i class="fa fa-fw fa-check-square pt-2" />
</t>
<t t-else="">
<i class="fa fa-fw fa-square-o pt-2" />
</t>
</span>
</div>
</DropdownItem>
<div
class="d-flex flex-grow-1 align-items-center py-0 log_into pl-3 o_py"
>
<t t-if="widget.isAllCompaniesSelected">
<span class="mr-3 company_label">All Companies</span>
</t>
<t t-else="">
<span
class="mr-3 company_label text-muted"
>Select All Companies</span>
</t>
</div>
</div>
</xpath>
</t>
</templates>
15 changes: 15 additions & 0 deletions web_select_all_companies/views/web_select_all_companies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template
id="assets_backend"
name="web_select_all_companies assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_select_all_companies/static/src/js/switch_all_company_menu.js"
/>
</xpath>
</template>
</odoo>

0 comments on commit f9d48ea

Please sign in to comment.