[IMP] Menu tree from client side
bzr revid: fme@openerp.com-20131028112350-9or1z3e3ndgk4mfg
This commit is contained in:
parent
321bf56b99
commit
26e62b0e0e
|
@ -392,16 +392,17 @@ class website_menu(osv.osv):
|
|||
root_menu_id = self.search(cr, uid, root_domain, limit=1, context=context)[0]
|
||||
menu_ids = self.search(cr, uid, [('id', 'child_of', root_menu_id)], 0, False, False, context)
|
||||
menu_items = self.read(cr, uid, menu_ids, fields, context=context)
|
||||
menu_items_map = dict(
|
||||
(menu_item["id"], menu_item) for menu_item in menu_items)
|
||||
menu_items_map = dict((menu_item["id"], menu_item) for menu_item in menu_items)
|
||||
for menu_item in menu_items:
|
||||
if menu_item['parent_id']:
|
||||
parent = menu_item['parent_id'][0]
|
||||
else:
|
||||
parent = False
|
||||
if parent in menu_items_map:
|
||||
menu_items_map[parent].setdefault(
|
||||
'children', []).append(menu_item)
|
||||
parent_obj = menu_items_map[parent]
|
||||
parent_obj.setdefault('level', 0)
|
||||
parent_obj.setdefault('children', []).append(menu_item)
|
||||
menu_item['level'] = parent_obj['level'] + 1
|
||||
|
||||
# sort by sequence a tree using parent_id
|
||||
for menu_item in menu_items:
|
||||
|
@ -410,19 +411,6 @@ class website_menu(osv.osv):
|
|||
|
||||
return menu_items[0]
|
||||
|
||||
def get_list(self, cr, uid, website_id, context=None):
|
||||
def get_menu_item(node, level=0):
|
||||
item = node.copy()
|
||||
item['level'] = level
|
||||
item.pop('children')
|
||||
yield item
|
||||
level += 1
|
||||
for child in node['children']:
|
||||
yield get_menu_item(child, level)
|
||||
tree = self.get_tree(cr, uid, website_id)
|
||||
return list(get_menu_item(tree))
|
||||
|
||||
|
||||
class ir_attachment(osv.osv):
|
||||
_inherit = "ir.attachment"
|
||||
def _website_url_get(self, cr, uid, ids, name, arg, context=None):
|
||||
|
|
|
@ -849,21 +849,24 @@
|
|||
var context = website.get_context();
|
||||
return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
|
||||
model: 'website.menu',
|
||||
method: 'get_list',
|
||||
method: 'get_tree',
|
||||
args: [[context.website_id]],
|
||||
kwargs: {
|
||||
context: context
|
||||
},
|
||||
});
|
||||
},
|
||||
fill_menus: function (results) {
|
||||
fill_menus: function (tree) {
|
||||
var self = this;
|
||||
var menus = this.$('select.add-to-menu')[0];
|
||||
_(results).each(function (result) {
|
||||
var name = (new Array(result.level).join('|-')) + ' ' + result.name;
|
||||
menus.options[menus.options.length] =
|
||||
new Option(name, result.id || 0);
|
||||
});
|
||||
var process_tree = function(node) {
|
||||
var name = (new Array(node.level + 1).join('|-')) + ' ' + node.name;
|
||||
menus.options[menus.options.length] = new Option(name, node.id);
|
||||
node.children.forEach(function (child) {
|
||||
process_tree(child);
|
||||
});
|
||||
};
|
||||
process_tree(tree);
|
||||
},
|
||||
});
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue