diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index 923b78492b3..5ea843bcaae 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -226,7 +226,7 @@ class Web_Editor(http.Controller): @http.route('/web_editor/customize_template_get', type='json', auth='user', website=True) def customize_template_get(self, key, full=False, bundles=False): """ Get inherit view's informations of the template ``key``. - returns templates (which can be active or not) + returns templates info (which can be active or not) ``bundles=True`` returns also the asset bundles """ return request.env["ir.ui.view"].customize_template_get(key, full=full, bundles=bundles) diff --git a/addons/web_editor/models/ir_ui_view.py b/addons/web_editor/models/ir_ui_view.py index 64ee45b567d..2b0af052c23 100644 --- a/addons/web_editor/models/ir_ui_view.py +++ b/addons/web_editor/models/ir_ui_view.py @@ -175,42 +175,21 @@ class IrUiView(models.Model): return views_to_return @api.model - def customize_template_get(self, key, full=False, bundles=False): - """ Get inherit view's informations of the template ``key``. - returns templates (which can be active or not) + def _customize_template_get_views(self, key, full=False, bundles=False): + """ Get inherit views of the template ``key``. + returns views (which can be active or not) ``bundles=True`` returns also the asset bundles """ - user = self.env.user - user_groups = set(user.groups_id) + user_groups = set(self.env.user.groups_id) views = self.with_context(active_test=False)._views_get(key, bundles=bundles) + views = views.filtered(lambda v: user_groups.issuperset(v.groups_id)) + return views - view_theme_id = self.env['ir.model.data'].xmlid_to_res_id('website.theme') - done = set() - result = [] - for view in views: - if full or (view.customize_show and view.inherit_id.id != view_theme_id): - if not user_groups.issuperset(view.groups_id): - continue - if view.inherit_id not in done: - result.append({ - 'name': view.inherit_id.name, - 'id': view.id, - 'key': view.key, - 'xml_id': view.xml_id, - 'arch': view.arch, - 'inherit_id': view.inherit_id.id, - 'header': True, - 'active': False - }) - done.add(view.inherit_id) - result.append({ - 'name': view.name, - 'id': view.id, - 'key': view.key, - 'xml_id': view.xml_id, - 'arch': view.arch, - 'inherit_id': view.inherit_id.id, - 'header': False, - 'active': view.active, - }) - return result + @api.model + def customize_template_get(self, key, full=False, bundles=False): + """ Get inherit view's informations of the template ``key``. + returns templates info (which can be active or not) + ``bundles=True`` returns also the asset bundles + """ + views = self._customize_template_get_views(key, full=full, bundles=bundles) + return views.read(['name', 'id', 'key', 'xml_id', 'arch', 'active', 'inherit_id']) diff --git a/addons/web_editor/static/src/js/ace.js b/addons/web_editor/static/src/js/ace.js index 5fbe7589265..56500383851 100644 --- a/addons/web_editor/static/src/js/ace.js +++ b/addons/web_editor/static/src/js/ace.js @@ -149,7 +149,7 @@ var ViewEditor = Widget.extend({ view.children = []; }); _.each(index, function (view) { - var parentId = view.inherit_id; + var parentId = view.inherit_id[0]; if (parentId && index[parentId]) { index[parentId].children.push(view); } else { diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 0826ac839d7..68e3eab78cc 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -262,10 +262,10 @@ class Website(Home): @http.route('/website/customize_template_get', type='json', auth='user', website=True) def customize_template_get(self, key, full=False, bundles=False): - """ Get inherit view's informations of the template ``key``. By default, only - :returns ``customize_show`` templates (which can be active or not), if - ``full=True`` returns inherit view's informations of the template ``key``. - ``bundles=True`` returns also the asset bundles + """ Get inherit view's informations of the template ``key``. + returns templates info (which can be active or not) + ``full=False`` returns only the customize_show template + ``bundles=True`` returns also the asset bundles """ return request.env["ir.ui.view"].customize_template_get(key, full=full, bundles=bundles) diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index acd9256ea52..110ce7e39ee 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -136,25 +136,13 @@ class View(models.Model): return qcontext @api.model - def customize_template_get(self, key, full=False, bundles=False): - """ Get inherit view's informations of the template ``key``. By default, only - :returns ``customize_show`` templates (which can be active or not), if - ``full=True`` returns inherit view's informations of the template ``key``. - ``bundles=True`` returns also the asset bundles + def _customize_template_get_views(self, key, full=False, bundles=False): + """ Get inherit view's informations of the template ``key``. + returns views (which can be active or not) + ``full=False`` returns only the customize_show template + ``bundles=True`` returns also the asset bundles """ - result = super(View, self).customize_template_get(key, full=full, bundles=bundles) - - imd = self.env['ir.model.data'] - view_theme_id = imd.xmlid_to_res_id('website.theme') - - result_filtered = [] - for x in result: - if not full: - view = self.browse(x['id']) - if not view.customize_show: - continue - if view_theme_id and x['inherit_id'] == view_theme_id: - continue - result_filtered.append(x) - - return result_filtered + views = super(View, self)._customize_template_get_views(key, full=full, bundles=bundles) + if full: + return views + return views.filtered(lambda v: v.customize_show) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index 5d2d7706560..a110e6eca3e 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -74,16 +74,17 @@ website.TopBarCustomize = Widget.extend({ key: this.view_name, full: false }).then(function (result) { + var current_group = ""; _.each(result, function (item) { - if (item.header) { - $menu.append('