Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding filter menu to differentiate between Odoo CMS and OCA we… #1

Open
wants to merge 4 commits into
base: 9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website_cms/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"views/cms_media.xml",
"views/cms_media_category.xml",
'views/website_menu.xml',
'views/res_config.xml',
# templates
"templates/assets.xml",
"templates/misc.xml",
Expand Down
1 change: 1 addition & 0 deletions website_cms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from . import cms_page
from . import cms_media
from . import cms_tag
from . import res_config
15 changes: 15 additions & 0 deletions website_cms/models/res_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-

from openerp import models, fields


class WebsiteConfigSettings(models.TransientModel):
"""Override website config model."""

_inherit = "website.config.settings"

filter_menu = fields.Selection(
string='Menu Filter',
related='website_id.filter_menu',
help='Filter to determine which menu shows in the front-end'
)
13 changes: 13 additions & 0 deletions website_cms/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# from openerp import fields
from openerp import api
from openerp import tools
from openerp import fields
from openerp.addons.web.http import request
from openerp.addons.website.models.website import unslug

Expand All @@ -20,6 +21,18 @@ class Website(models.Model):

_inherit = "website"

filter_menu = fields.Selection(
string="Show Menu",
required=True,
selection=[
('1', 'Odoo'),
('2', 'CMS'),
('3', 'Odoo & CMS'),
],
default='1',
help="Filter to determine which menu shows in the front-end"
)

@api.model
@tools.ormcache('max_depth', 'pages', 'nav', 'type_ids', 'published')
def get_nav_pages(self, max_depth=3, pages=None,
Expand Down
13 changes: 13 additions & 0 deletions website_cms/templates/layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
<t t-call="website_cms.alternate_languages" />
</xpath>

<xpath expr="//ul[@id='top_menu']/t[@t-foreach='website.menu_id.child_id']" position="replace">
<t t-if="website.filter_menu in ['1','3']">
<t t-foreach="website.menu_id.child_id" t-as="submenu">
<t t-call="website.submenu"/>
</t>
</t>
<t t-if="website.filter_menu in ['2','3']">
<t t-foreach="website.get_nav_pages()" t-as="submenu">
<t t-call="website_cms.submenu"/>
</t>
</t>
</xpath>

</template>

<template id="add_status_message" inherit_id="website.layout">
Expand Down
22 changes: 22 additions & 0 deletions website_cms/templates/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@

</template>

<template id="submenu" name="Website CMS Submenu">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PCatinean any way to make this readable? :)

Maybe we can move this logic to a website helper method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied and pasted the original navbar template from stock Odoo. I thought about using the original template but it's highly unlikely it will work.

Methods in the website helper might be a bit overkill, I set some variables at the start.

What do you think?

<li t-if="not submenu.get('children')" t-att-class="
'active' if submenu.get('url') and submenu.get('url') != '/' and request.httprequest.path == submenu.get('url') else None">
<a t-att-href="submenu.get('url')" t-ignore="true">
<span t-esc="submenu.get('name')"/>
</a>
</li>
<li t-if="submenu.get('children')" t-attf-class="dropdown #{
(submenu.get('url') and submenu.get('url') != '/' and any([request.httprequest.path == child.get('url') for child in submenu.get('children', [])]) or
(submenu.get('url') and request.httprequest.path == submenu.get('url'))) and 'active'
}">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<span t-esc="submenu.get('name')"/> <span class="caret" t-ignore="true"></span>
</a>
<ul class="dropdown-menu" role="menu">
<t t-foreach="submenu.get('children')" t-as="submenu">
<t t-call="website_cms.submenu"/>
</t>
</ul>
</li>
</template>

</data>
</openerp>

Expand Down
20 changes: 20 additions & 0 deletions website_cms/views/res_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<openerp>
Copy link

@leemannd leemannd Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<odoo> without <data>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a small change but seems good to me 👍

<data>

<record id="website_config_settings" model="ir.ui.view">
<field name="name">website settings form</field>
<field name="model">website.config.settings</field>
<field name="inherit_id" ref="website.view_website_config_settings"/>
<field name="arch" type="xml">

<xpath expr="//group[@name='advanced']" position="after">
<group string="CMS" name="website-cms">
<field name="filter_menu" />
</group>
</xpath>

</field>
</record>

</data>
</openerp>