[ADD] web_select_all_companies

This commit is contained in:
Telmo Santos
2023-02-13 09:21:27 +01:00
committed by BT-mrobles
parent db87b3bc41
commit 83fd19ad9f
13 changed files with 666 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/** @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);
}
},
});

View File

@@ -0,0 +1,4 @@
.all-companies-item {
font-size: 16px;
font-weight: bold;
}

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t
t-name="web_select_all_companies.SwitchAllCompanyMenu"
t-inherit="web.SwitchCompanyMenu"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//t[@t-key='company.id']" 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="() => this.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>Companies</span>
</div>
</div>
</DropdownItem>
</xpath>
</t>
</templates>