Files
odoo_source/addons/web/static/src/start.js
T
Samuel Degueldre 8603d13d19 [FIX] web, test_assetsbundle: make useAssets work in owl 2
Previously, the useAssets hook would load the templates from the given
bundles into the qweb instance that was in the environment. In owl 2,
qweb is no longer in the environment, and templates need to be loaded in
the app.

This commit fixes that by exporting a function to load templates in the
main app from assets.js, when the main app is created, it should be
written on the function in a similar vein to renderToString, so that all
further calls to the function will load the templates in that app.

This commit also adds an actual lazy-loading test in the
test_assetsbundle module, as we don't want to pollute the manifest of
web with bundles that only exist for one specific test.

closes odoo/odoo#90122

Related: odoo/enterprise#26776
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-05-03 11:20:52 +02:00

74 lines
2.4 KiB
JavaScript

/** @odoo-module **/
import { makeEnv, startServices } from "./env";
import { legacySetupProm } from "./legacy/legacy_setup";
import { mapLegacyEnvToWowlEnv } from "./legacy/utils";
import { processTemplates, loadBundle } from "./core/assets";
import { localization } from "@web/core/l10n/localization";
import { session } from "@web/session";
import { renderToString } from "./core/utils/render";
const { App, whenReady } = owl;
/**
* Function to start a webclient.
* It is used both in community and enterprise in main.js.
* It's meant to be webclient flexible so we can have a subclass of
* webclient in enterprise with added features.
*
* @param {Component} Webclient
*/
export async function startWebClient(Webclient) {
odoo.info = {
db: session.db,
server_version: session.server_version,
server_version_info: session.server_version_info,
isEnterprise: session.server_version_info.slice(-1)[0] === "e",
};
odoo.isReady = false;
// setup environment
const env = makeEnv();
const [, templates] = await Promise.all([
startServices(env),
odoo.loadTemplatesPromise.then(processTemplates),
]);
// start web client
await whenReady();
window.__OWL_TEMPLATES__ = templates;
const legacyEnv = await legacySetupProm;
mapLegacyEnvToWowlEnv(legacyEnv, env);
const app = new App(Webclient, {
env,
dev: env.debug,
templates: window.__OWL_TEMPLATES__,
translatableAttributes: ["data-tooltip"],
translateFn: env._t,
});
renderToString.app = app;
loadBundle.app = app;
const root = await app.mount(document.body);
const classList = document.body.classList;
if (localization.direction === "rtl") {
classList.add("o_rtl");
}
if (env.services.user.userId === 1) {
classList.add("o_is_superuser");
}
// delete odoo.debug; // FIXME: some legacy code rely on this
odoo.__WOWL_DEBUG__ = { root };
odoo.isReady = true;
// Update Favicons
const favicon = `/web/image/res.company/${env.services.company.currentCompany.id}/favicon`;
const icons = document.querySelectorAll("link[rel*='icon']");
const msIcon = document.querySelector("meta[name='msapplication-TileImage']");
for (const icon of icons) {
icon.href = favicon;
}
if (msIcon) {
msIcon.content = favicon;
}
}