addons js loading

bzr revid: al@openerp.com-20110311132622-otrxhghgox9jqax6
This commit is contained in:
Antony Lesuisse
2011-03-11 14:26:22 +01:00
parent a0cc38df3b
commit 10104a2bf0
3 changed files with 80 additions and 30 deletions
+19 -20
View File
@@ -67,29 +67,13 @@ class Hello(openerpweb.Controller):
class Session(openerpweb.Controller):
_cp_path = "/base/session"
@openerpweb.jsonrequest
def login(self, req, db, login, password):
req.session.login('trunk', login, password)
res = {
"session_id" : req.session_id,
"uid": req.session._uid,
}
return res
@openerpweb.jsonrequest
def modules(self, req):
res={}
res["modules"] = ["base","base_hello"]
return res
def manifest_glob(self, modlist, key):
files = []
for i in modlist.split(','):
globlist = openerpweb.addons_manifest.get(i,{}).get('css',[])
for i in modlist:
globlist = openerpweb.addons_manifest.get(i, {}).get(key, [])
for j in globlist:
tmp = glob.glob(os.path.join(openerpweb.path_addons,i,j))
files.append(tmp)
print modlist, key, files
for k in glob.glob(os.path.join(openerpweb.path_addons, i, j)):
files.append(k[len(openerpweb.path_addons):])
return files
def concat_files(self, file_list):
@@ -110,6 +94,21 @@ class Session(openerpweb.Controller):
files_concat = "".join(files_content)
return files_concat
@openerpweb.jsonrequest
def login(self, req, db, login, password):
req.session.login('trunk', login, password)
res = {
"session_id" : req.session_id,
"uid": req.session._uid,
}
return res
@openerpweb.jsonrequest
def modules(self, req):
res={}
res["modules"] = ["base","base_hello"]
return res
@openerpweb.jsonrequest
def csslist(self, req, mods='base,base_hello'):
return {'files': self.manifest_glob(mods.split(','), 'css')}
+29 -10
View File
@@ -146,7 +146,7 @@ openerp.base.Session = openerp.base.BasicController.extend({
var post = { request: JSON.stringify(request) };
// Use a default error handler unless defined
error_callback = typeof(error_callback) != "undefined" ? error_callback : this.on_error;
error_callback = typeof(error_callback) != "undefined" ? error_callback : this.on_rpc_error;
// Call using the rpc_mode
this.rpc_ajax(url, post, success_callback, error_callback);
@@ -189,7 +189,7 @@ openerp.base.Session = openerp.base.BasicController.extend({
},
on_rpc_response: function() {
},
on_error: function(error) {
on_rpc_error: function(error) {
// TODO this should use the $element with focus and buttonsi displaying OPW etc...
this.on_log(error, error.message, error.data.type, error.data.debug);
},
@@ -207,29 +207,48 @@ openerp.base.Session = openerp.base.BasicController.extend({
this.rpc("/base/session/login", params, function(result) {
self.session_id = result.session_id;
self.uid = result.uid;
if (sucess_callback) sucess_callback();
self.session_check_modules();
if (sucess_callback)
sucess_callback();
});
},
session_check_modules: function() {
// TODO
if(!openerp._modules_loaded)
this.session_load_modules();
},
session_load_modules: function() {
var self = this;
this.rpc('/base/session/list_modules', {}, function(result) {
this.rpc('/base/session/modules', {}, function(result) {
this.module_list = result['modules'];
if(self.debug) {
// add the module code one by one as <script>
self.log(self.module_list);
self.rpc('/base/session/jslist', {"mods": this.module_list.join(',')}, function(result) {
var files = result.files;
self.log(files);
// Insert addons javascript in head
for(var i=0; i<files.length; i++) {
// use $.getScript(‘your_3rd_party-script.js’); ? i want to keep lineno !
var s = document.createElement("script");
s.src = files[i];
s.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(s);
// at this point the js should be loaded or not ?
}
for(var i=0; i<this.module_list.length; i++) {
var mod = this.module_list[i];
if(mod == "base")
continue;
self.log(mod);
self.log(openerp._openerp[mod]);
// init module mod
openerp._openerp[mod](openerp);
}
});
} else {
// load merged ones
// /base/session/css?mod=mod1,mod2,mod3
// /base/session/js?mod=mod1,mod2,mod3
}
// then init them
// for i in installed_modules:
// call openerp._openerp.<i>(openerp)
openerp._modules_loaded = true;
});
this.uid = false;
@@ -0,0 +1,32 @@
/*---------------------------------------------------------
* OpenERP base_hello (Example module)
*---------------------------------------------------------*/
openerp.base_hello = function(openerp) {
openerp.base_hello.HelloController = openerp.base.Controller.extend({
init:function() {
this._super.apply(this,arguments);
},
do_hello:function() {
alert("hello");
},
});
openerp.base.SearchView = openerp.base.SearchView.extend({
init:function() {
this._super.apply(this,arguments);
this.hello = openerp.base_hello.HelloController();
},
start:function() {
this._super.apply(this,arguments);
this.on_search.add(this.hello.do_hello);
},
});
// here you may tweak globals object, if any, and play with on_* or do_* callbacks on them
}
// vim:et fdc=0 fdl=0: