From ae0bf044ef1d63bc0bb19eb9dccc0218c63a9c65 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 2 Nov 2011 12:11:05 +0100 Subject: [PATCH 1/3] [IMP] qweb templates are stored in addon manifest and given by the server bzr revid: chs@openerp.com-20111102111105-ibyupno1e47sv9ho --- addons/web/__openerp__.py | 3 ++ addons/web/controllers/main.py | 38 +++++++++++++++++++ addons/web/static/src/js/chrome.js | 3 +- addons/web/static/src/js/core.js | 17 +++++++++ addons/web/static/src/js/search.js | 7 ++-- addons/web_calendar/__openerp__.py | 3 ++ addons/web_calendar/static/src/js/calendar.js | 1 - addons/web_dashboard/__openerp__.py | 3 ++ .../web_dashboard/static/src/js/dashboard.js | 1 - addons/web_diagram/__openerp__.py | 3 ++ addons/web_diagram/static/src/js/diagram.js | 1 - addons/web_gantt/__openerp__.py | 3 ++ addons/web_gantt/static/src/js/gantt.js | 1 - addons/web_graph/__openerp__.py | 3 ++ addons/web_graph/static/src/js/graph.js | 1 - addons/web_kanban/__openerp__.py | 3 ++ addons/web_kanban/static/src/js/kanban.js | 2 +- 17 files changed, 81 insertions(+), 12 deletions(-) diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index 314d7274879..2695709c68a 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -52,4 +52,7 @@ "static/src/css/data_export.css", "static/src/css/data_import.css", ], + 'qweb' : [ + "static/src/xml/*.xml", + ], } diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 6cc46b476a9..9f894dc9673 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -24,6 +24,32 @@ openerpweb = web.common.http # OpenERP Web web Controllers #---------------------------------------------------------- + +def concat_xml(file_list): + """Concatenate xml files + return (concat,timestamp) + concat: concatenation of file content + timestamp: max(os.path.getmtime of file_list) + """ + root = None + files_timestamp = 0 + for fname in file_list: + ftime = os.path.getmtime(fname) + if ftime > files_timestamp: + files_timestamp = ftime + + xml = ElementTree.parse(fname).getroot() + + if root is None: + root = ElementTree.Element(xml.tag) + #elif root.tag != xml.tag: + # raise ValueError("Root tags missmatch: %r != %r" % (root.tag, xml.tag)) + + for child in xml.getchildren(): + root.append(child) + return ElementTree.tostring(root, 'utf-8'), files_timestamp + + def concat_files(file_list): """ Concatenate file content return (concat,timestamp) @@ -98,6 +124,10 @@ class WebClient(openerpweb.Controller): def jslist(self, req, mods=None): return self.manifest_list(req, mods, 'js') + @openerpweb.jsonrequest + def qweblist(self, req, mods=None): + return self.manifest_list(req, mods, 'qweb') + @openerpweb.httprequest def css(self, req, mods=None): files = [f[0] for f in self.manifest_glob(req, mods, 'css')] @@ -112,6 +142,14 @@ class WebClient(openerpweb.Controller): # TODO use timestamp to set Last mofified date and E-tag return req.make_response(content, [('Content-Type', 'application/javascript')]) + @openerpweb.httprequest + def qweb(self, req, mods=None): + files = [f[0] for f in self.manifest_glob(req, mods, 'qweb')] + content,timestamp = concat_xml(files) + # TODO use timestamp to set Last mofified date and E-tag + return req.make_response(content, [('Content-Type', 'text/xml')]) + + @openerpweb.httprequest def home(self, req, s_action=None, **kw): js = "\n ".join(''%i for i in self.manifest_list(req, None, 'js')) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index c8ebbb2b12a..f2b90c5cf7f 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -943,14 +943,13 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this._super(null, element_id); openerp.webclient = this; - QWeb.add_template("/web/static/src/xml/base.xml"); var params = {}; if(jQuery.param != undefined && jQuery.deparam(jQuery.param.querystring()).kitten != undefined) { this.$element.addClass("kitten-mode-activated"); } this.$element.html(QWeb.render("Interface", params)); - this.notification = new openerp.web.Notification(); + this.notification = new openerp.web.Notification(this); this.loading = new openerp.web.Loading(this,"oe_loading"); this.crashmanager = new openerp.web.CrashManager(); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 75f2bb8ef71..837e9faab64 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -364,7 +364,9 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. // TODO: session should have an optional name indicating that they'll // be saved to (and revived from) cookies this.name = 'session'; + this.do_load_qweb(['/web/webclient/qweb']); }, + start: function() { this.session_restore(); }, @@ -487,6 +489,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.user_context = result.context; self.db = result.db; self.session_save(); + self.on_session_valid(); return true; }).then(success_callback); }, @@ -578,6 +581,7 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. self.rpc('/web/webclient/jslist', {"mods": modules}, function(files) { self.do_load_js(file_list.concat(files)); }); + self.rpc('/web/webclient/qweblist', {"mods": modules}, self.do_load_qweb); openerp._modules_loaded = true; }); }); @@ -611,6 +615,19 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. this.on_modules_loaded(); } }, + do_load_qweb: function(files) { + var self = this; + _.each(files, function(file) { + $.ajax({ + url: file, + type: 'get', + async: false, + dataType: 'text', + }).then(function(xml) { + openerp.web.qweb.add_template(_(xml).trim()); + }); + }); + }, on_modules_loaded: function() { for(var j=0; j Date: Thu, 3 Nov 2011 11:28:28 +0100 Subject: [PATCH 2/3] [FIX] do not add kanban qweb template explicitly bzr revid: chs@openerp.com-20111103102828-wbx5aujiwdscb6hx --- addons/web_kanban/static/src/js/kanban.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index a2a9c07f6d0..1873af02984 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -1,7 +1,6 @@ openerp.web_kanban = function (openerp) { var QWeb = openerp.web.qweb; -QWeb.add_template('/web_kanban/static/src/xml/web_kanban.xml'); openerp.web.views.add('kanban', 'openerp.web_kanban.KanbanView'); openerp.web_kanban.KanbanView = openerp.web.View.extend({ init: function (parent, dataset, view_id, options) { From 5290ada81f998e29da7777116e317478c69d05e6 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 8 Nov 2011 16:56:33 +0100 Subject: [PATCH 3/3] [FIX] correct criss-cross merge bzr revid: chs@openerp.com-20111108155633-8lymglmg46sfv0ko --- addons/web/static/src/js/boot.js | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index fef9b5168a8..5fba5f4d8d4 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -21,16 +21,7 @@ * * @param {Array} modules list of modules to initialize */ - init: function(modules, connection, callback) { - - if (/^(function|undefined)$/.test(typeof connection)) { - callback = connection; - connection = { - host: document.location.protocol + '//' + document.location.host, - }; - } - - + init: function(modules) { var new_instance = { // links to the global openerp _openerp: openerp, @@ -48,20 +39,6 @@ for(var i=0; i < modules.length; i++) { openerp[modules[i]](new_instance); } - - new_instance.connector = new new_instance.web.Connection(connection.host); - if (connection.login) { - new_instance.connector.login(connection.database, connection.login, connection.password, function() { - if (callback) { - callback(new_instance); - } - }); - } else { - if (callback) { - callback(new_instance); - } - } - return new_instance; } };