From 22c56b1dd85b5302c03886fe5f6096f817a981a5 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 5 Aug 2013 13:12:50 +0200 Subject: Ported some authentication methods to the Session class bzr revid: nicolas.vanhoren@openerp.com-20130805111250-ws23n3b6os54qsp3 --- addons/web/static/src/js/coresetup.js | 54 ++++++----------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) (limited to 'addons/web/static/src/js/coresetup.js') diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index c8deca1c9ac..3f4ea4a183b 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -14,27 +14,23 @@ if (!console) { openerp.web.coresetup = function(instance) { +/* + Some retro-compatibility. +*/ +instance.web.JsonRPC = instance.web.Session; + /** Session openerp specific RPC class */ -instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Session# */{ +instance.web.Session.include( /** @lends instance.web.Session# */{ init: function() { this._super.apply(this, arguments); // TODO: session store in cookie should be optional this.name = instance._session_id; this.qweb_mutex = new $.Mutex(); }, - rpc: function(url, params, options) { - return this._super(url, params, options); - }, /** * Setup a sessionm */ session_bind: function(origin) { - if (!_.isUndefined(this.origin)) { - if (this.origin === origin) { - return $.when(); - } - throw new Error('Session already bound to ' + this.origin); - } var self = this; this.setup(origin); instance.web.qweb.default_dict['_s'] = this.origin; @@ -69,33 +65,6 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess ); }); }, - /** - * (re)loads the content of a session: db name, username, user id, session - * context and status of the support contract - * - * @returns {$.Deferred} deferred indicating the session is done reloading - */ - session_reload: function () { - var self = this; - var def = $.when(); - if (this.override_session) { - if (! this.session_id) { - def = this.rpc("/gen_session_id", {}).then(function(result) { - self.session_id = result; - }); - } - } else { - this.session_id = this.get_cookie('session_id'); - } - return def.then(function() { - return self.rpc("/web/session/get_session_info", {}); - }).then(function(result) { - // If immediately follows a login (triggered by trying to restore - // an invalid session or no session at all), refresh session data - // (should not change, but just in case...) - _.extend(self, result); - }); - }, session_is_valid: function() { var db = $.deparam.querystring().db; if (db && this.db !== db) { @@ -106,15 +75,9 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess /** * The session is validated either by login or by restoration of a previous session */ - session_authenticate: function(db, login, password, _volatile) { + session_authenticate: function() { var self = this; - var base_location = document.location.protocol + '//' + document.location.host; - var params = { db: db, login: login, password: password, base_location: base_location }; - return this.rpc("/web/session/authenticate", params).then(function(result) { - if (!result.uid) { - return $.Deferred().reject(); - } - _.extend(self, result); + return $.when(this._super.apply(this, arguments)).then(function() { return self.load_modules(); }); }, @@ -550,6 +513,7 @@ instance.session = new instance.web.Session(); /** Configure default qweb */ instance.web._t = new instance.web.TranslationDataBase().build_translation_function(); +instance.web._t = new instance.web.TranslationDataBase().build_translation_function(); /** * Lazy translation function, only performs the translation when actually * printed (e.g. inserted into a template) -- cgit v1.2.3 From b3c4d025908bc8923069154de4673fae283cd18e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 5 Aug 2013 16:44:31 +0200 Subject: Improved translation controller to be more flexible bzr revid: nicolas.vanhoren@openerp.com-20130805144431-ycv6gwv99c5bh1p1 --- addons/web/static/src/js/coresetup.js | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/web/static/src/js/coresetup.js') diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 3f4ea4a183b..59f2c6a3a96 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -513,7 +513,6 @@ instance.session = new instance.web.Session(); /** Configure default qweb */ instance.web._t = new instance.web.TranslationDataBase().build_translation_function(); -instance.web._t = new instance.web.TranslationDataBase().build_translation_function(); /** * Lazy translation function, only performs the translation when actually * printed (e.g. inserted into a template) -- cgit v1.2.3 From 38699e04cf74399c4ee35881feddc170e4073c87 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 5 Aug 2013 16:55:14 +0200 Subject: Copied a part of translation database to openerpframework.js bzr revid: nicolas.vanhoren@openerp.com-20130805145514-uuywlhleyfz2xoj4 --- addons/web/static/src/js/coresetup.js | 54 ++--------------------------------- 1 file changed, 3 insertions(+), 51 deletions(-) (limited to 'addons/web/static/src/js/coresetup.js') diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 59f2c6a3a96..7f73b867a0e 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -375,58 +375,13 @@ instance.web.Bus = instance.web.Class.extend(instance.web.EventDispatcherMixin, }); instance.web.bus = new instance.web.Bus(); -/** OpenERP Translations */ -instance.web.TranslationDataBase = instance.web.Class.extend(/** @lends instance.web.TranslationDataBase# */{ - /** - * @constructs instance.web.TranslationDataBase - * @extends instance.web.Class - */ - init: function() { - this.db = {}; - this.parameters = {"direction": 'ltr', - "date_format": '%m/%d/%Y', - "time_format": '%H:%M:%S', - "grouping": [], - "decimal_point": ".", - "thousands_sep": ","}; - }, +instance.web.TranslationDataBase.include({ set_bundle: function(translation_bundle) { - var self = this; - this.db = {}; - var modules = _.keys(translation_bundle.modules); - modules.sort(); - if (_.include(modules, "web")) { - modules = ["web"].concat(_.without(modules, "web")); - } - _.each(modules, function(name) { - self.add_module_translation(translation_bundle.modules[name]); - }); + this._super(translation_bundle); if (translation_bundle.lang_parameters) { - this.parameters = translation_bundle.lang_parameters; - this.parameters.grouping = py.eval( - this.parameters.grouping); + this.parameters.grouping = py.eval(this.parameters.grouping); } }, - add_module_translation: function(mod) { - var self = this; - _.each(mod.messages, function(message) { - self.db[message.id] = message.string; - }); - }, - build_translation_function: function() { - var self = this; - var fcnt = function(str) { - var tmp = self.get(str); - return tmp === undefined ? str : tmp; - }; - fcnt.database = this; - return fcnt; - }, - get: function(key) { - if (this.db[key]) - return this.db[key]; - return undefined; - } }); /** Custom jQuery plugins */ @@ -511,8 +466,6 @@ $.async_when = function() { /** Setup default session */ instance.session = new instance.web.Session(); -/** Configure default qweb */ -instance.web._t = new instance.web.TranslationDataBase().build_translation_function(); /** * Lazy translation function, only performs the translation when actually * printed (e.g. inserted into a template) @@ -529,7 +482,6 @@ instance.web._lt = function (s) { }; instance.web.qweb.debug = instance.session.debug; _.extend(instance.web.qweb.default_dict, { - '_t' : instance.web._t, '__debug__': instance.session.debug, }); instance.web.qweb.preprocess_node = function() { -- cgit v1.2.3 From 1bd4b621425c7a96a501e61a37256453c6311cff Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 5 Aug 2013 17:10:12 +0200 Subject: Perfected translations integration in the framework bzr revid: nicolas.vanhoren@openerp.com-20130805151012-wnc7wkyiz0eay5oh --- addons/web/static/src/js/coresetup.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'addons/web/static/src/js/coresetup.js') diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 7f73b867a0e..77af4808605 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -156,10 +156,7 @@ instance.web.Session.include( /** @lends instance.web.Session# */{ }); }, load_translations: function() { - var params = { mods: this.module_list, lang: this.user_context.lang }; - return this.rpc('/web/webclient/translations', params).done(function(trans) { - instance.web._t.database.set_bundle(trans); - }); + return instance.web._t.database.load_translations(this, this.module_list, this.user_context.lang); }, load_css: function (files) { var self = this; -- cgit v1.2.3