diff options
| author | Aaron Bohy <aab@odoo.com> | 2016-04-08 14:53:34 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2016-04-21 15:21:39 +0200 |
| commit | 977db823c7c84e9edc7c8cf8384eb9cf47275b3a (patch) | |
| tree | c3312f745baf11d51f976a60d6e285480f557d4c /addons/web/static/src/js/widgets/user_menu.js | |
| parent | e1bfd3fbda97ac7a64a585b07be161d5be606cf9 (diff) | |
[REF] web: stop duplicating web
Avoid duplicating web addon in enterprise by extracting a common basis.
Enterprise features stay in enterprise, but use that common basis.
Mainly:
- JS refactoring and linting
- Conversion of .sass into .less split into multiple files
- Templates cleaning and DOM simplification
- Re-generation of web.pot, and update of .po files
Diffstat (limited to 'addons/web/static/src/js/widgets/user_menu.js')
| -rw-r--r-- | addons/web/static/src/js/widgets/user_menu.js | 100 |
1 files changed, 49 insertions, 51 deletions
diff --git a/addons/web/static/src/js/widgets/user_menu.js b/addons/web/static/src/js/widgets/user_menu.js index 31728dfa813..edeb059790a 100644 --- a/addons/web/static/src/js/widgets/user_menu.js +++ b/addons/web/static/src/js/widgets/user_menu.js @@ -4,7 +4,7 @@ odoo.define('web.UserMenu', function (require) { var core = require('web.core'); var Dialog = require('web.Dialog'); var framework = require('web.framework'); -var Model = require('web.DataModel'); +var Model = require('web.Model'); var session = require('web.session'); var Widget = require('web.Widget'); @@ -13,10 +13,6 @@ var QWeb = core.qweb; var UserMenu = Widget.extend({ template: "UserMenu", - init: function(parent) { - this._super(parent); - this.update_promise = $.Deferred().resolve(); - }, start: function() { var self = this; this.$el.on('click', '.dropdown-menu li a[data-menu]', function(ev) { @@ -26,32 +22,28 @@ var UserMenu = Widget.extend({ f($(this)); } }); - this.$el.parent().show(); - return this._super.apply(this, arguments); + return this._super.apply(this, arguments).then(function () { + return self.do_update(); + }); }, do_update: function () { var self = this; - var fct = function() { - var $avatar = self.$el.find('.oe_topbar_avatar'); - $avatar.attr('src', $avatar.data('default-src')); - if (!session.uid) - return; - var func = new Model("res.users").get_func("read"); - return self.alive(func(session.uid, ["name"])).then(function(res) { - var topbar_name = res.name; - if(session.debug) - topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db); - self.$el.find('.oe_topbar_name').text(topbar_name); - if (!session.debug) { - topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db); - } - var avatar_src = session.url('/web/image', {model:'res.users', field: 'image_small', id: session.uid}); - $avatar.attr('src', avatar_src); + var $avatar = self.$('.oe_topbar_avatar'); + $avatar.attr('src', $avatar.data('default-src')); + if (!session.uid) { + return $.when(); + } + var func = new Model("res.users").get_func("read"); + return self.alive(func(session.uid, ["name"])).then(function(res) { + var topbar_name = res.name; + if(session.debug) { + topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db); + } + self.$('.oe_topbar_name').text(topbar_name); - core.bus.trigger('resize'); // Re-trigger the reflow logic - }); - }; - this.update_promise = this.update_promise.then(fct, fct); + var avatar_src = session.url('/web/image', {model:'res.users', field: 'image_small', id: session.uid}); + $avatar.attr('src', avatar_src); + }); }, on_menu_documentation: function () { window.open('https://www.odoo.com/documentation/user', '_blank'); @@ -83,36 +75,42 @@ var UserMenu = Widget.extend({ }, on_menu_settings: function() { var self = this; - this.getParent().clear_uncommitted_changes().then(function() { - self.rpc("/web/action/load", { action_id: "base.action_res_users_my" }).done(function(result) { - result.res_id = session.uid; - self.getParent().action_manager.do_action(result); - }); + this.trigger_up('clear_uncommitted_changes', { + callback: function() { + self.rpc("/web/action/load", { action_id: "base.action_res_users_my" }).done(function(result) { + result.res_id = session.uid; + self.do_action(result); + }); + }, }); }, on_menu_account: function() { - this.getParent().clear_uncommitted_changes().then(function() { - var P = new Model('ir.config_parameter'); - P.call('get_param', ['database.uuid']).then(function(dbuuid) { - var state = { - 'd': session.db, - 'u': window.location.protocol + '//' + window.location.host, - }; - var params = { - response_type: 'token', - client_id: dbuuid || '', - state: JSON.stringify(state), - scope: 'userinfo', - }; - framework.redirect('https://accounts.odoo.com/oauth2/auth?'+$.param(params)); - }).fail(function(result, ev){ - ev.preventDefault(); - framework.redirect('https://accounts.odoo.com/account'); - }); + this.trigger_up('clear_uncommitted_changes', { + callback: function() { + var P = new Model('ir.config_parameter'); + P.call('get_param', ['database.uuid']).then(function(dbuuid) { + var state = { + 'd': session.db, + 'u': window.location.protocol + '//' + window.location.host, + }; + var params = { + response_type: 'token', + client_id: dbuuid || '', + state: JSON.stringify(state), + scope: 'userinfo', + }; + framework.redirect('https://accounts.odoo.com/oauth2/auth?'+$.param(params)); + }).fail(function(result, ev){ + ev.preventDefault(); + framework.redirect('https://accounts.odoo.com/account'); + }); + }, }); }, on_menu_logout: function() { - this.trigger('user_logout'); + this.trigger_up('clear_uncommitted_changes', { + callback: this.do_action.bind(this, 'logout'), + }); }, }); |
