summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2013-07-26 14:15:14 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2013-07-26 14:15:14 +0200
commitfd1df3ee22cfe8558a7d6b1fb661c36fc97b084b (patch)
tree39b64c630dfc7766c80e9068c2b759ac28ac454d /addons/web
parent6e6108e9b69b296bb30d8d36e258027ad7860cbd (diff)
[IMP] Removed openerp's ineffective JavaScript module loader and added retro-compatibility layer
bzr revid: nicolas.vanhoren@openerp.com-20130726121514-ss0omrhed76ybv5a
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/__openerp__.py1
-rw-r--r--addons/web/static/src/js/boot.js75
-rw-r--r--addons/web/static/src/js/coresetup.js11
-rw-r--r--addons/web/static/src/js/openerpframework.js18
4 files changed, 68 insertions, 37 deletions
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.<module> will map to
// openerp.instances.sessionname.<module> 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<files.length; i++) {
- if(openerp.web[files[i]]) {
- openerp.web[files[i]](session);
+ /*---------------------------------------------------------
+ * OpenERP Web web module split
+ *---------------------------------------------------------*/
+ function init_web_modules() {
+ 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<files.length; i++) {
+ var fct = openerp.web[files[i]];
+ if(typeof(fct) === "function") {
+ openerp.web[files[i]] = {};
+ for (k in fct) {
+ openerp.web[files[i]][k] = fct[k];
+ }
+ fct(openerp, openerp.web[files[i]]);
+ }
}
}
-};
+})();
-// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js
index 8eea24345d2..d4e1c6bc8a5 100644
--- a/addons/web/static/src/js/coresetup.js
+++ b/addons/web/static/src/js/coresetup.js
@@ -250,10 +250,15 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess
continue;
instance[mod] = {};
// init module mod
- if(instance._openerp[mod] !== undefined) {
- instance._openerp[mod](instance,instance[mod]);
- this.module_loaded[mod] = true;
+ var fct = instance._openerp[mod];
+ if(typeof(fct) === "function") {
+ instance._openerp[mod] = {};
+ for (k in fct) {
+ instance._openerp[mod][k] = fct[k];
+ }
+ fct(instance, instance._openerp[mod]);
}
+ this.module_loaded[mod] = true;
}
},
/**
diff --git a/addons/web/static/src/js/openerpframework.js b/addons/web/static/src/js/openerpframework.js
new file mode 100644
index 00000000000..f481f0ce6b1
--- /dev/null
+++ b/addons/web/static/src/js/openerpframework.js
@@ -0,0 +1,18 @@
+
+(function() {
+
+function declare($, _, QWeb) {
+ var openerp = {};
+
+ openerp.web = {};
+
+ return openerp;
+};
+
+if (typeof(define) !== "undefined") { // amd
+ define(["jquery", "underscore", "qweb"], declare);
+} else {
+ window.openerp = declare($, _, QWeb2);
+}
+
+})(); \ No newline at end of file