[WIP] Menu working from database (not yet multi-website)
bzr revid: fme@openerp.com-20131025152446-si9gsjujzcn40hip
This commit is contained in:
@@ -8,6 +8,16 @@
|
||||
<field name="default_lang_id" ref="base.lang_en"/>
|
||||
</record>
|
||||
|
||||
<record id="main_menu" model="website.menu">
|
||||
<field name="name">Main Menu</field>
|
||||
</record>
|
||||
|
||||
<record id="menu_contactus" model="website.menu">
|
||||
<field name="name">Contact us</field>
|
||||
<field name="url">/page/website.contactus</field>
|
||||
<field name="parent_id" ref="website.main_menu"/>
|
||||
</record>
|
||||
|
||||
<record id="public_user" model="res.users">
|
||||
<field name="name">public</field>
|
||||
<field name="login">public</field>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import fnmatch
|
||||
import functools
|
||||
import operator
|
||||
import simplejson
|
||||
|
||||
import openerp
|
||||
@@ -362,8 +363,7 @@ class website(osv.osv):
|
||||
return html
|
||||
|
||||
def get_menu_tree(self, cr, uid, ids, context=None):
|
||||
return self.pool['website.menu'].get_tree(cr, uid, ids[0])
|
||||
|
||||
return self.pool['website.menu'].get_tree(cr, uid, ids[0], context=context)
|
||||
|
||||
class website_menu(osv.osv):
|
||||
_name = "website.menu"
|
||||
@@ -378,21 +378,50 @@ class website_menu(osv.osv):
|
||||
'parent_left': fields.integer('Parent Left', select=True),
|
||||
'parent_right': fields.integer('Parent Right', select=True),
|
||||
}
|
||||
_defaults = {
|
||||
'url': '',
|
||||
'sequence': 0,
|
||||
}
|
||||
_order = "parent_left"
|
||||
|
||||
# TODO: ormcache
|
||||
def get_tree(self, cr, uid, website_id, fields=None, context=None):
|
||||
if not fields:
|
||||
fields = ['id', 'name', 'url', 'sequence', 'parent_id']
|
||||
root_domain = [('parent_id', '=', False)] # ('website_id', '=', website_id),
|
||||
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)
|
||||
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)
|
||||
|
||||
# sort by sequence a tree using parent_id
|
||||
for menu_item in menu_items:
|
||||
menu_item.setdefault('children', []).sort(
|
||||
key=operator.itemgetter('sequence'))
|
||||
|
||||
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))
|
||||
|
||||
def get_tree(self, cr, uid, website_id=False, context=None):
|
||||
menu_root = {
|
||||
'id': False,
|
||||
'name': 'root',
|
||||
'url': '',
|
||||
'children': [],
|
||||
'parent_id': 0,
|
||||
}
|
||||
domain = [('parent_id', '=', 0)] # ('website_id', '=', website_id)]
|
||||
root = self.search(cr, uid, domain, context=context)
|
||||
if root:
|
||||
pass
|
||||
#menu_ids = Menus.search([('id', 'child_of', root)], 0, False, False, context)
|
||||
return menu_root
|
||||
|
||||
class ir_attachment(osv.osv):
|
||||
_inherit = "ir.attachment"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_website_public,website,website.model_website,base.group_public,1,0,0,0
|
||||
access_website,website,website.model_website,base.group_user,1,0,0,0
|
||||
access_website_menu,access_website_menu,model_website_menu,,1,0,0,0
|
||||
access_website_converter_test,access_website_converter_test,model_website_converter_test,,1,1,1,1
|
||||
access_website_converter_test_sub,access_website_converter_test_sub,model_website_converter_test_sub,,1,1,1,1
|
||||
access_website_qweb,access_website_qweb,model_website_qweb,,0,0,0,0
|
||||
|
||||
|
@@ -674,6 +674,7 @@
|
||||
|
||||
return $.when(
|
||||
this.fetch_pages().done(this.proxy('fill_pages')),
|
||||
this.fetch_menus().done(this.proxy('fill_menus')),
|
||||
this._super()
|
||||
).done(this.proxy('bind_data'));
|
||||
},
|
||||
@@ -762,6 +763,23 @@
|
||||
'/pagenew/%s?noredirect', encodeURI(val)))
|
||||
.then(function (response) {
|
||||
self.make_link(response, false, val);
|
||||
var parent_id = self.$('.add-to-menu').val();
|
||||
if (parent_id) {
|
||||
return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
|
||||
model: 'website.menu',
|
||||
method: 'create',
|
||||
args: [{
|
||||
'name': val,
|
||||
'url': response,
|
||||
'sequence': 0, // TODO: better tree widget
|
||||
'website_id': website.id,
|
||||
'parent_id': parent_id|0,
|
||||
}],
|
||||
kwargs: {
|
||||
context: website.get_context()
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.make_link(val, this.$('input.window-new').prop('checked'));
|
||||
@@ -828,6 +846,26 @@
|
||||
new Option(result.name, result.url);
|
||||
});
|
||||
},
|
||||
fetch_menus: function () {
|
||||
var context = website.get_context();
|
||||
return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
|
||||
model: 'website.menu',
|
||||
method: 'get_list',
|
||||
args: [[context.website_id]],
|
||||
kwargs: {
|
||||
context: context
|
||||
},
|
||||
});
|
||||
},
|
||||
fill_menus: function (results) {
|
||||
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);
|
||||
});
|
||||
},
|
||||
});
|
||||
/**
|
||||
* ImageDialog widget. Lets users change an image, including uploading a
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
var tpl = website.load_templates(templates);
|
||||
all_ready = dom_ready.then(function () {
|
||||
if ($('html').data('editable')) {
|
||||
website.id = $('html').data('website-id');
|
||||
website.session = new openerp.Session();
|
||||
var modules = ['website'];
|
||||
return openerp._t.database.load_translations(website.session, modules, website.get_context().lang);
|
||||
|
||||
@@ -50,6 +50,13 @@
|
||||
</select>
|
||||
</li>
|
||||
<li class="list-group-item form-group">
|
||||
<div class="pull-right">
|
||||
<label>
|
||||
<select class="add-to-menu">
|
||||
<option>Create a menu entry in ...</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<h3 class="list-group-item-heading">
|
||||
<label for="link-new" class="control-label">
|
||||
New page
|
||||
|
||||
@@ -120,7 +120,6 @@
|
||||
<t t-call="website.submenu"/>
|
||||
</t>
|
||||
|
||||
<li name="contactus"><a t-href="/page/website.contactus">Contact us</a></li>
|
||||
<li t-if="user_id.id == website.public_user.id"><a href="/web">Sign in</a></li>
|
||||
<li t-if="user_id.id != website.public_user.id"><a href="/web"><span t-field="user_id.name"/></a></li>
|
||||
<li t-if="request.multilang and
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<!-- <data noupdate="1"> -->
|
||||
<data noupdate="1">
|
||||
<record id="menu_blog" model="website.menu">
|
||||
<field name="name">News</field>
|
||||
<field name="url">/blog</field>
|
||||
<field name="parent_id" ref="website.main_menu"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<data>
|
||||
|
||||
<!-- jump to blog at install -->
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
<data>
|
||||
<!-- Layout add nav and footer -->
|
||||
<template id="header_footer_custom" inherit_id="website.layout">
|
||||
<xpath expr="//header//ul[@id='top_menu']/li[@name='contactus']" position="before">
|
||||
<li><a t-attf-href="/blog/cat/%(website_blog.blog_category_1)d/">News</a></li>
|
||||
</xpath>
|
||||
<xpath expr="//footer//div[@name='info']/ul" position="inside">
|
||||
<li><a t-attf-href="/blog/cat/%(website_blog.blog_category_1)d/">News</a></li>
|
||||
</xpath>
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="menu_events" model="website.menu">
|
||||
<field name="name">Events</field>
|
||||
<field name="url">/events</field>
|
||||
<field name="parent_id" ref="website.main_menu"/>
|
||||
</record>
|
||||
<record id="action_open_website" model="ir.actions.act_url">
|
||||
<field name="name">Website Home</field>
|
||||
<field name="target">self</field>
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
<!-- Layout add nav and footer -->
|
||||
<template id="header_footer_custom" inherit_id="website.layout">
|
||||
<xpath expr="//header//ul[@id='top_menu']/li[@name='contactus']" position="before">
|
||||
<li><a t-href="/event">Events</a></li>
|
||||
</xpath>
|
||||
<xpath expr="//footer//div[@name='info']/ul" position="inside">
|
||||
<li><a t-href="/event">Events</a></li>
|
||||
</xpath>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="menu_jobs" model="website.menu">
|
||||
<field name="name">Jobs</field>
|
||||
<field name="url">/jobs</field>
|
||||
<field name="parent_id" ref="website.main_menu"/>
|
||||
</record>
|
||||
<record id="action_open_website" model="ir.actions.act_url">
|
||||
<field name="name">Website Recruitment Form</field>
|
||||
<field name="target">self</field>
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
</record>
|
||||
|
||||
<template id="job_footer_custom" inherit_id="website.layout" name="Custom Footer Job">
|
||||
<xpath expr="//header//ul[@id='top_menu']/li[@name='contactus']" position="before">
|
||||
<li><a href="/jobs">Jobs</a></li>
|
||||
</xpath>
|
||||
<xpath expr="//footer//div[@name='info']/ul" position="inside">
|
||||
<li><a href="/jobs">Jobs</a></li>
|
||||
</xpath>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
<template id="header" inherit_id="website.layout" name="Custom Header">
|
||||
<xpath expr="//header//ul[@id='top_menu']/li" position="before">
|
||||
<li><a t-href="/shop/">Shop</a></li>
|
||||
<li t-att-class="(not website_sale_order or not website_sale_order.get_total_quantity()) and 'hidden' or ''">
|
||||
<a t-href="/shop/mycart/">
|
||||
<i class="icon-shopping-cart"></i>
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="menu_shop" model="website.menu">
|
||||
<field name="name">Shop</field>
|
||||
<field name="url">/shop</field>
|
||||
<field name="parent_id" ref="website.main_menu"/>
|
||||
</record>
|
||||
<record id="action_open_website" model="ir.actions.act_url">
|
||||
<field name="name">Website Shop</field>
|
||||
<field name="target">self</field>
|
||||
|
||||
Reference in New Issue
Block a user