[IMP] web menu: add a context value for reload one submenus of a parent id menu. If no default_menu, load all menus

bzr revid: chm@openerp.com-20121113143220-zhwo06j7pl8rt2wi
This commit is contained in:
Christophe Matthieu 2012-11-13 15:32:20 +01:00
parent 14951003ab
commit 82cba0604f
2 changed files with 16 additions and 3 deletions

View File

@ -1047,8 +1047,13 @@ class Menu(openerpweb.Controller):
# 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)
menu_ids = Menus.search([], 0, False, False, context)
if req.context and 'default_menu' in req.context and int(req.context['default_menu']):
# for load only one sub menu
menu_ids = Menus.search([['id', 'child_of', req.context['default_menu']]], 0, False, False, context)
else:
menu_ids = Menus.search([], 0, False, False, context)
menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id', 'action', 'needaction_enabled', 'needaction_counter'], context)
# 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
# mapping, resulting in children being correctly set on the roots.

View File

@ -708,9 +708,17 @@ instance.web.Menu = instance.web.Widget.extend({
this.$secondary_menus.on('click', 'a[data-menu]', this.on_menu_click);
return this.do_reload();
},
do_reload: function() {
do_reload: function(id) {
var self = this;
return this.rpc("/web/menu/load", {}).done(function(r) {
return this.rpc("/web/menu/load", id ? {'context': {'default_menu': id}} : {}).done(function(r) {
if (id) {
_.each(self.data.data.children, function (val) {
if (val.id == id) {
val.children = _.find(r.data.children, function (r_val) {return r_val.id == id;}).children;
}
});
var r = self.data;
}
self.menu_loaded(r);
});
},