diff options
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/common_env.js | 37 | ||||
| -rw-r--r-- | addons/web/static/src/js/core/abstract_service.js | 45 | ||||
| -rw-r--r-- | addons/web/static/src/js/main.js | 11 | ||||
| -rw-r--r-- | addons/web/static/src/js/public/public_root_instance.js | 6 |
4 files changed, 58 insertions, 41 deletions
diff --git a/addons/web/static/src/js/common_env.js b/addons/web/static/src/js/common_env.js index 567607d50b5..792c3b966d4 100644 --- a/addons/web/static/src/js/common_env.js +++ b/addons/web/static/src/js/common_env.js @@ -19,7 +19,7 @@ odoo.define("web.commonEnv", function (require) { const { jsonRpc } = require("web.ajax"); const { device, isDebug } = require("web.config"); - const { bus, serviceRegistry } = require("web.core"); + const { bus } = require("web.core"); const rpc = require("web.rpc"); const session = require("web.session"); const { _t } = require("web.translation"); @@ -97,40 +97,5 @@ odoo.define("web.commonEnv", function (require) { session, }; - - // Deploy services in the env (specializations of AbstractService registered - // into the serviceRegistry) - const UndeployedServices = Object.assign({}, serviceRegistry.map); - function _deployServices() { - let done = false; - while (!done) { - // find a service with no missing dependency - const serviceName = Object.keys(UndeployedServices).find(serviceName => { - const Service = UndeployedServices[serviceName]; - return Service.prototype.dependencies.every(depName => { - return env.services[depName]; - }); - }); - if (serviceName) { - const Service = UndeployedServices[serviceName]; - const service = new Service(env); - env.services[serviceName] = service; - delete UndeployedServices[serviceName]; - service.start(); - } else { - done = true; - } - } - } - serviceRegistry.onAdd((serviceName, Service) => { - if (serviceName in env.services || serviceName in UndeployedServices) { - throw new Error(`Service ${serviceName} is already loaded.`); - } - UndeployedServices[serviceName] = Service; - _deployServices(); - }); - _deployServices(); - - return env; }); diff --git a/addons/web/static/src/js/core/abstract_service.js b/addons/web/static/src/js/core/abstract_service.js index f9ad859fef2..5157b5b55f4 100644 --- a/addons/web/static/src/js/core/abstract_service.js +++ b/addons/web/static/src/js/core/abstract_service.js @@ -2,6 +2,7 @@ odoo.define('web.AbstractService', function (require) { "use strict"; var Class = require('web.Class'); +const { serviceRegistry } = require("web.core"); var Mixins = require('web.mixins'); var ServicesMixin = require('web.ServicesMixin'); @@ -40,6 +41,50 @@ var AbstractService = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, { this.env.bus.trigger('do-action', payload); } }, + + //-------------------------------------------------------------------------- + // Static + //-------------------------------------------------------------------------- + + /** + * Deploy services in the env (specializations of AbstractService registered + * into the serviceRegistry). + * + * @static + * @param {Object} env + */ + deployServices(env) { + const UndeployedServices = Object.assign({}, serviceRegistry.map); + function _deployServices() { + let done = false; + while (!done) { + // find a service with no missing dependency + const serviceName = Object.keys(UndeployedServices).find(serviceName => { + const Service = UndeployedServices[serviceName]; + return Service.prototype.dependencies.every(depName => { + return env.services[depName]; + }); + }); + if (serviceName) { + const Service = UndeployedServices[serviceName]; + const service = new Service(env); + env.services[serviceName] = service; + delete UndeployedServices[serviceName]; + service.start(); + } else { + done = true; + } + } + } + serviceRegistry.onAdd((serviceName, Service) => { + if (serviceName in env.services || serviceName in UndeployedServices) { + throw new Error(`Service ${serviceName} is already loaded.`); + } + UndeployedServices[serviceName] = Service; + _deployServices(); + }); + _deployServices(); + } }); return AbstractService; diff --git a/addons/web/static/src/js/main.js b/addons/web/static/src/js/main.js index 49b90228ba2..465ea0d63d4 100644 --- a/addons/web/static/src/js/main.js +++ b/addons/web/static/src/js/main.js @@ -1,18 +1,20 @@ odoo.define('web.web_client', function (require) { "use strict"; + const AbstractService = require('web.AbstractService'); const env = require('web.env'); const session = require("web.session"); const WebClient = require('web.WebClient'); + // configure the env and set it on Owl Component owl.config.mode = env.isDebug() ? "dev" : "prod"; owl.Component.env = env; - const webClient = new WebClient(); + // deploy services in the env + AbstractService.prototype.deployServices(env); - /** - * Add the owl templates to the environment and start the web client. - */ + // add the owl templates to the environment and start the web client + const webClient = new WebClient(); async function startWebClient() { await session.is_bound; env.qweb.addTemplates(session.owlTemplates); @@ -21,7 +23,6 @@ odoo.define('web.web_client', function (require) { webClient.setElement($(document.body)); webClient.start(); } - startWebClient(); return webClient; diff --git a/addons/web/static/src/js/public/public_root_instance.js b/addons/web/static/src/js/public/public_root_instance.js index e368d421fbe..a7422a97c26 100644 --- a/addons/web/static/src/js/public/public_root_instance.js +++ b/addons/web/static/src/js/public/public_root_instance.js @@ -1,6 +1,7 @@ odoo.define('root.widget', function (require) { 'use strict'; +const AbstractService = require('web.AbstractService'); const env = require('web.public_env'); var lazyloader = require('web.public.lazyloader'); var rootData = require('web.public.root'); @@ -12,6 +13,11 @@ owl.config.mode = env.isDebug() ? "dev" : "prod"; owl.Component.env = env; /** + * Deploy services in the env + */ +AbstractService.prototype.deployServices(env); + +/** * This widget is important, because the tour manager needs a root widget in * order to work. The root widget must be a service provider with the ajax * service, so that the tour manager can let the server know when tours have |
