[IMP] Needaction: couters are not counter with the menu anymore.
Web-side: a call to get_needaction_data is performed to have action counters. Menus are then updated synchronously with this value. bzr revid: tde@openerp.com-20121127142944-m17zo62er5rh2lvg
This commit is contained in:
parent
ebf4ae991a
commit
c5d3036674
|
@ -1034,6 +1034,10 @@ class Menu(openerpweb.Controller):
|
||||||
def load(self, req):
|
def load(self, req):
|
||||||
return {'data': self.do_load(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
|
@openerpweb.jsonrequest
|
||||||
def get_user_roots(self, req):
|
def get_user_roots(self, req):
|
||||||
return self.do_get_user_roots(req)
|
return self.do_get_user_roots(req)
|
||||||
|
@ -1071,13 +1075,13 @@ class Menu(openerpweb.Controller):
|
||||||
context = req.session.eval_context(req.context)
|
context = req.session.eval_context(req.context)
|
||||||
Menus = req.session.model('ir.ui.menu')
|
Menus = req.session.model('ir.ui.menu')
|
||||||
|
|
||||||
menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled', 'needaction_counter'], context)
|
menu_roots = Menus.read(self.do_get_user_roots(req), ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled'], context)
|
||||||
menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, ''], 'children' : menu_roots}
|
menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, ''], 'children': menu_roots}
|
||||||
|
|
||||||
# menus are loaded fully unlike a regular tree view, cause there are a
|
# menus are loaded fully unlike a regular tree view, cause there are a
|
||||||
# limited number of items (752 when all 6.1 addons are installed)
|
# limited number of items (752 when all 6.1 addons are installed)
|
||||||
menu_ids = Menus.search([], 0, False, False, context)
|
menu_ids = Menus.search([], 0, False, False, context)
|
||||||
menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled', 'needaction_counter'], context)
|
menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled'], context)
|
||||||
# adds roots at the end of the sequence, so that they will overwrite
|
# adds roots at the end of the sequence, so that they will overwrite
|
||||||
# equivalent menu items from full menu read when put into id:item
|
# equivalent menu items from full menu read when put into id:item
|
||||||
# mapping, resulting in children being correctly set on the roots.
|
# mapping, resulting in children being correctly set on the roots.
|
||||||
|
@ -1101,6 +1105,23 @@ class Menu(openerpweb.Controller):
|
||||||
|
|
||||||
return menu_root
|
return menu_root
|
||||||
|
|
||||||
|
def do_load_needaction(self, req, menu_ids=False):
|
||||||
|
""" Loads needaction counters for all or some specific menu ids.
|
||||||
|
|
||||||
|
:param req: A request object, with an OpenERP session attribute
|
||||||
|
:type req: < session -> OpenERPSession >
|
||||||
|
:return: the menu root
|
||||||
|
:rtype: dict('children': menu_nodes)
|
||||||
|
"""
|
||||||
|
context = req.session.eval_context(req.context)
|
||||||
|
Menus = req.session.model('ir.ui.menu')
|
||||||
|
|
||||||
|
if menu_ids == False:
|
||||||
|
menu_ids = Menus.search([('needaction_enabled', '=', True)], context=context)
|
||||||
|
|
||||||
|
menu_needaction_data = Menus.get_needaction_data(menu_ids, context)
|
||||||
|
return menu_needaction_data
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@openerpweb.jsonrequest
|
||||||
def action(self, req, menu_id):
|
def action(self, req, menu_id):
|
||||||
actions = load_actions_from_ir_values(req,'action', 'tree_but_open',
|
actions = load_actions_from_ir_values(req,'action', 'tree_but_open',
|
||||||
|
|
|
@ -835,6 +835,21 @@ instance.web.Menu = instance.web.Widget.extend({
|
||||||
}
|
}
|
||||||
this.trigger('menu_loaded', data);
|
this.trigger('menu_loaded', data);
|
||||||
this.has_been_loaded.resolve();
|
this.has_been_loaded.resolve();
|
||||||
|
// Now launch the fetch of needaction counters, asynchronous
|
||||||
|
this.rpc("web/menu/load_needaction", {menu_ids: false}).done(function(r) {
|
||||||
|
self.on_needaction_loaded(r);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
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('<div class="oe_tag oe_tag_dark oe_menu_counter">' + item.needaction_counter + '</div>');
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
limit_entries: function() {
|
limit_entries: function() {
|
||||||
var maximum_visible_links = this.maximum_visible_links;
|
var maximum_visible_links = this.maximum_visible_links;
|
||||||
|
|
|
@ -43,7 +43,7 @@ class LoadTest(unittest2.TestCase):
|
||||||
[], 0, False, False, self.request.session.eval_context())
|
[], 0, False, False, self.request.session.eval_context())
|
||||||
self.MockMenus.read.assert_called_with(
|
self.MockMenus.read.assert_called_with(
|
||||||
[], ['name', 'sequence', 'parent_id',
|
[], ['name', 'sequence', 'parent_id',
|
||||||
'action', 'needaction_enabled', 'needaction_counter'],
|
'action', 'needaction_enabled'],
|
||||||
self.request.session.eval_context())
|
self.request.session.eval_context())
|
||||||
|
|
||||||
self.assertListEqual(
|
self.assertListEqual(
|
||||||
|
@ -62,7 +62,7 @@ class LoadTest(unittest2.TestCase):
|
||||||
|
|
||||||
self.MockMenus.read.assert_called_with(
|
self.MockMenus.read.assert_called_with(
|
||||||
[1, 2, 3], ['name', 'sequence', 'parent_id',
|
[1, 2, 3], ['name', 'sequence', 'parent_id',
|
||||||
'action', 'needaction_enabled', 'needaction_counter'],
|
'action', 'needaction_enabled'],
|
||||||
self.request.session.eval_context())
|
self.request.session.eval_context())
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in New Issue