From fd1df3ee22cfe8558a7d6b1fb661c36fc97b084b Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 26 Jul 2013 14:15:14 +0200 Subject: [PATCH] [IMP] Removed openerp's ineffective JavaScript module loader and added retro-compatibility layer bzr revid: nicolas.vanhoren@openerp.com-20130726121514-ss0omrhed76ybv5a --- addons/web/__openerp__.py | 1 + addons/web/static/src/js/boot.js | 75 +++++++++++--------- addons/web/static/src/js/coresetup.js | 11 ++- addons/web/static/src/js/openerpframework.js | 18 +++++ 4 files changed, 68 insertions(+), 37 deletions(-) create mode 100644 addons/web/static/src/js/openerpframework.js diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index e8c2dd903d0..7a00b4c5a47 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -42,6 +42,7 @@ This module provides the core of the OpenERP Web Client. "static/lib/backbone/backbone.js", "static/lib/cleditor/jquery.cleditor.js", "static/lib/py.js/lib/py.js", + "static/src/js/openerpframework.js", "static/src/js/boot.js", "static/src/js/testing.js", "static/src/js/pyeval.js", diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 4565d220dc8..c255db36ff8 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -7,15 +7,20 @@ * @namespace openerp */ (function() { - if (this.openerp) - return; - var session_counter = 0; + var inited = false; - var openerp = this.openerp = { + _.extend(openerp, { // Per session namespace // openerp. will map to // openerp.instances.sessionname. using a closure - instances: {}, + instances: {instance0: openerp}, + // links to the global openerp + _openerp: openerp, + // this unique id will be replaced by hostname_databasename by + // openerp.web.Session on the first connection + _session_id: "instance0", + _modules: ['web'], + web_mobile: {}, /** * OpenERP instance constructor * @@ -24,41 +29,43 @@ init: function(modules) { if (modules === null) { modules = []; - } else { - modules = _.union(['web'], modules || []); } - var new_instance = { - // links to the global openerp - _openerp: openerp, - // this unique id will be replaced by hostname_databasename by - // openerp.web.Session on the first connection - _session_id: "instance" + session_counter++, - _modules: modules, - web: {}, - web_mobile: {} - }; - openerp.instances[new_instance._session_id] = new_instance; + if (inited) + throw new Error("OpenERP was already inited"); + inited = true; + init_web_modules(); for(var i=0; i < modules.length; i++) { - new_instance[modules[i]] = {}; - if (openerp[modules[i]]) { - openerp[modules[i]](new_instance,new_instance[modules[i]]); + if (modules[i] === "web") + continue; + var fct = openerp[modules[i]]; + if (typeof(fct) === "function") { + openerp[modules[i]] = {}; + for (k in fct) { + openerp[modules[i]][k] = fct[k]; + } + fct(openerp, openerp[modules[i]]); } } - return new_instance; + openerp._modules = ['web'].concat(modules); + return openerp; } - }; -})(); + }); -/*--------------------------------------------------------- - * OpenERP Web web module split - *---------------------------------------------------------*/ -openerp.web = function(session) { - var files = ["pyeval", "corelib","coresetup","dates","formats","chrome","data","views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import"]; - for(var i=0; i