[MERGE] Needaction loading update.
This web revision modifies the way needaction are loaded. Now they are loaded independently of the menus. After having loaded and displayed the various menus, a call to the server is done to avoid a long latency between the login and the display of menus. Needaction counter will be displayed as soon as they are available. bzr revid: tde@openerp.com-20121210131658-pgy3t9t71f0z2yd5
This commit is contained in:
commit
5d2d4dea2c
|
@ -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',
|
||||
|
|
|
@ -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') {
|
||||
|
|
|
@ -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] : ''">
|
||||
<t t-esc="menu.name"/>
|
||||
<t t-if="menu.needaction_enabled and menu.needaction_counter">
|
||||
<div class="oe_tag oe_tag_dark oe_menu_counter">
|
||||
<t t-if="menu.needaction_counter > 99"> 99+ </t><t t-if="menu.needaction_counter <= 99"> <t t-esc="menu.needaction_counter"/> </t>
|
||||
</div>
|
||||
</t>
|
||||
</a>
|
||||
</t>
|
||||
|
||||
<t t-name="Menu.needaction_counter">
|
||||
<div class="oe_tag oe_tag_dark oe_menu_counter">
|
||||
<t t-if="widget.needaction_counter > 99"> 99+ </t>
|
||||
<t t-if="widget.needaction_counter <= 99"> <t t-esc="widget.needaction_counter"/> </t>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="UserMenu">
|
||||
<span class="oe_user_menu oe_topbar_item oe_dropdown_toggle oe_dropdown_arrow">
|
||||
<img class="oe_topbar_avatar" t-att-data-default-src="_s + '/web/static/src/img/user_menu_avatar.png'"/>
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue