81 lines
3.6 KiB
JavaScript
81 lines
3.6 KiB
JavaScript
/** Part of Beyond. Collina Systems proprietary module. */
|
|
import { patch } from "@web/core/utils/patch";
|
|
import { useBus } from "@web/core/utils/hooks";
|
|
import { useRef } from "@odoo/owl";
|
|
import { useDropdownState } from "@web/core/dropdown/dropdown_hooks";
|
|
import { browser } from "@web/core/browser/browser";
|
|
import { NavBar } from "@web/webclient/navbar/navbar";
|
|
import { WebClient } from "@web/webclient/webclient";
|
|
|
|
const OPEN_LAUNCHER = "BEYOND:OPEN_LAUNCHER";
|
|
|
|
/**
|
|
* The apps dropdown gets a state the rest of the client can drive
|
|
* (@see useDropdownState), so the launcher can be opened without reaching
|
|
* into the DOM for the toggle button. The template hands this state to the
|
|
* Dropdown (beyond_launcher.xml).
|
|
*/
|
|
patch(NavBar.prototype, {
|
|
setup() {
|
|
super.setup();
|
|
this.beyondLauncher = useDropdownState();
|
|
this.beyondLauncherToggle = useRef("beyondLauncherToggle");
|
|
useBus(this.env.bus, OPEN_LAUNCHER, () => {
|
|
this.beyondLauncher.open();
|
|
// Focus goes where a click on the house would leave it. Without
|
|
// this the launcher is on top but the keyboard is still down in
|
|
// the app behind, and the first arrow key scrolls a list nobody
|
|
// can see.
|
|
this.beyondLauncherToggle.el?.focus();
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Cerrar sesión desde el lanzador.
|
|
*
|
|
* El enlace ya lleva su `href`, así que si esto no corriera la salida
|
|
* funcionaría igual. Lo único que agrega es avisarle al service worker,
|
|
* que es lo que hace el menú de usuario de Odoo: sin ese aviso, una
|
|
* aplicación instalada se queda con la sesión vieja en caché.
|
|
*/
|
|
cerrarSesion() {
|
|
browser.navigator.serviceWorker?.controller?.postMessage("user_logout");
|
|
},
|
|
});
|
|
|
|
patch(WebClient.prototype, {
|
|
/**
|
|
* The Menú Principal is the first screen (20-aug-2026).
|
|
*
|
|
* Odoo calls this exactly when the URL carries no action — a bare /odoo,
|
|
* which is where login lands — and otherwise never: a deep link sets
|
|
* stateLoaded and goes straight to its destination. That makes it the
|
|
* seam for "the launcher is home", with no route guessing on our side.
|
|
*
|
|
* The first app still loads BEHIND the launcher, which is what super
|
|
* does. The user does not see it (the launcher is full screen and opens
|
|
* synchronously, before the action resolves) but closing the launcher
|
|
* without choosing then lands on a real screen instead of an empty
|
|
* client. Picking a block navigates normally and nothing re-opens.
|
|
*/
|
|
async _loadDefaultApp() {
|
|
// En pantalla chica NO se abre solo. Ahí Odoo no pinta el botón de
|
|
// apps sino su barra lateral, que ADR-005 dejó intacta a propósito:
|
|
// el lanzador no es la puerta en un teléfono. Y si se dispara igual,
|
|
// el estado queda ABIERTO y el lanzador aparece encima en cuanto algo
|
|
// vuelve a montar el desplegable — que es justo lo que pasa al entrar
|
|
// al Panel General, donde la barra fuerza la variante de escritorio.
|
|
// El resultado era una pantalla tapada por el lanzador.
|
|
if (this.env.services.ui.isSmall) {
|
|
return super._loadDefaultApp();
|
|
}
|
|
this.env.bus.trigger(OPEN_LAUNCHER);
|
|
const cargada = await super._loadDefaultApp();
|
|
// Twice on purpose: the app that loads behind grabs focus for its own
|
|
// search box as it mounts, which happens after the first call. Opening
|
|
// an open dropdown is a no-op, so only the focus is re-applied.
|
|
this.env.bus.trigger(OPEN_LAUNCHER);
|
|
return cargada;
|
|
},
|
|
});
|