diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index f5710e87218..0e93103d84a 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -923,6 +923,10 @@ class Menu(openerpweb.Controller): def load(self, req): return {'data': self.do_load(req)} + @openerpweb.jsonrequest + def load_needaction(self, req, menu_ids): + return {'data': self.do_load_needaction(req, menu_ids)} + @openerpweb.jsonrequest def get_user_roots(self, req): return self.do_get_user_roots(req) @@ -961,7 +965,7 @@ class Menu(openerpweb.Controller): Menus = req.session.model('ir.ui.menu') fields = ['name', 'sequence', 'parent_id', 'action', - 'needaction_enabled', 'needaction_counter'] + 'needaction_enabled'] menu_roots = Menus.read(self.do_get_user_roots(req), fields, req.context) menu_root = { 'id': False, @@ -998,6 +1002,20 @@ class Menu(openerpweb.Controller): return menu_root + def do_load_needaction(self, req, menu_ids=False): + """ Loads needaction counters for all or some specific menu ids. + + :return: needaction data + :rtype: dict(menu_id: {'needaction_enabled': boolean, 'needaction_counter': int}) + """ + Menus = req.session.model('ir.ui.menu') + + if menu_ids == False: + menu_ids = Menus.search([('needaction_enabled', '=', True)], context=req.context) + + menu_needaction_data = Menus.get_needaction_data(menu_ids, req.context) + return menu_needaction_data + @openerpweb.jsonrequest def action(self, req, menu_id): actions = load_actions_from_ir_values(req,'action', 'tree_but_open', diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 5783afb987a..55e14d6d783 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -799,10 +799,18 @@ instance.web.client_actions.add("change_password", "instance.web.ChangePassword" instance.web.Menu = instance.web.Widget.extend({ template: 'Menu', init: function() { + var self = this; this._super.apply(this, arguments); this.has_been_loaded = $.Deferred(); this.maximum_visible_links = 'auto'; // # of menu to show. 0 = do not crop, 'auto' = algo this.data = {data:{children:[]}}; + this.on("menu_loaded", this, function (e) { + // launch the fetch of needaction counters, asynchronous + this.rpc("/web/menu/load_needaction", {menu_ids: false}).done(function(r) { + self.on_needaction_loaded(r); + }); + }); + }, start: function() { this._super.apply(this, arguments); @@ -836,6 +844,17 @@ instance.web.Menu = instance.web.Widget.extend({ this.trigger('menu_loaded', data); this.has_been_loaded.resolve(); }, + on_needaction_loaded: function(data) { + var self = this; + this.needaction_data = data; + _.each(this.needaction_data.data, function (item, menu_id) { + var $item = self.$secondary_menus.find('a[data-menu="' + menu_id + '"]'); + $item.remove('oe_menu_counter'); + if (item.needaction_counter && item.needaction_counter > 0) { + $item.append(QWeb.render("Menu.needaction_counter", { widget : item })); + } + }); + }, limit_entries: function() { var maximum_visible_links = this.maximum_visible_links; if (maximum_visible_links === 'auto') { diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index e742f336dc0..5ad24a43a6a 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -388,14 +388,16 @@ t-att-data-action-model="menu.action ? menu.action.split(',')[0] : ''" t-att-data-action-id="menu.action ? menu.action.split(',')[1] : ''"> - -
- 99+ -
-
+ +
+ 99+ + +
+
+ diff --git a/addons/web/tests/test_menu.py b/addons/web/tests/test_menu.py index 75d1d009408..42d41923517 100644 --- a/addons/web/tests/test_menu.py +++ b/addons/web/tests/test_menu.py @@ -42,7 +42,7 @@ class LoadTest(unittest2.TestCase): [], 0, False, False, self.request.context) self.MockMenus.read.assert_called_with( [], ['name', 'sequence', 'parent_id', - 'action', 'needaction_enabled', 'needaction_counter'], + 'action', 'needaction_enabled'], self.request.context) self.assertListEqual( @@ -61,7 +61,7 @@ class LoadTest(unittest2.TestCase): self.MockMenus.read.assert_called_with( [1, 2, 3], ['name', 'sequence', 'parent_id', - 'action', 'needaction_enabled', 'needaction_counter'], + 'action', 'needaction_enabled'], self.request.context) self.assertEqual(