mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[ADD] web_select_all_companies
This commit is contained in:
@@ -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);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
.all-companies-item {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user