From 2432a1296a55dfe9894455d33a0a0cb546cb450d Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 30 Sep 2016 10:07:17 +0200 Subject: [PATCH] [FIX] website: load customize menu at once if already opened Following commit 3cbc7ebc4c3e0edb25d1a91dcbf4df163ef6d29e, the bug for customize menu could have been ignored but as it is an easy fix : The customize menu is filled after a rpc which is performed on mousedown on the menu toggle. But in the case the user clicked on the customize menu before the mousedown handler was attached... nothing occured. It is possible since the customize menu is rendered but its JS widget is only attached to it once everything is ready. Now, the menu is filled on first mousedown or if the menu is already opened when the JS widget is attached. --- .../website/static/src/js/website.editor.js | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index 8873703d790..e0cf880e611 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -54,39 +54,36 @@ website.TopBar.include({ website.TopBarCustomize = Widget.extend({ events: { - 'mousedown a.dropdown-toggle': 'load_menu', - 'click ul a[data-view-id]': 'do_customize', + 'click > ul a[data-view-id]': 'do_customize', }, start: function () { - var self = this; - this.$menu = self.$el.find('ul'); this.view_name = $(document.documentElement).data('view-xmlid'); if (!this.view_name) { this.$el.hide(); } - this.loaded = false; + + if (this.$el.is(".open")) { + this.load_menu(); + } else { + this.$el.one("mousedown", "> a.dropdown-toggle", this.load_menu.bind(this)); + } }, load_menu: function () { - var self = this; - if(this.loaded) { - return; - } + var $menu = this.$el.children("ul"); ajax.jsonRpc('/website/customize_template_get', 'call', { key: this.view_name, }).then(function (result) { _.each(result, function (item) { - if (item.key === "website.debugger" && !window.location.search.match(/[&?]debug(&|$)/)) return; if (item.header) { - self.$menu.append(''); + $menu.append(''); } else { var $li = $('
  • ', {role: 'presentation'}) .append($('', {href: '#', 'data-view-id': item.id, role: 'menuitem'}) .append(qweb.render('web_editor.components.switch', {id: 'switch-' + item.id, label: item.name}))); $li.find('input').prop('checked', !!item.active); - self.$menu.append($li); + $menu.append($li); } }); - self.loaded = true; }); }, do_customize: function (e) {