From 931e62fa9160d44fafc83305bba26840e4c0bdee Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 29 Oct 2019 11:01:35 +0000 Subject: [PATCH] [FIX] website: switch page_id from menu on cow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, if you had a page_id set on a menu, and that you fork this page, the page_id from the menu was always pointing to the previous one, so you see old page, but edit new page. > Reproduce: > Fork Contactus (Page_id on menu become wrong) > Refresh contact us (done on save btw) > You see old content > Edit with Html Editor, you sill see that forked view exists! Bug was hidden before that we set page_id on menu, but it is needed if we want to support the groups visibility on the menu item. closes odoo/odoo#39472 Signed-off-by: Jérémy Kersten (jke) --- addons/website/data/website_data.xml | 2 ++ addons/website/models/ir_ui_view.py | 3 ++- addons/website/static/src/js/menu/content.js | 12 +++++++----- addons/website/static/src/js/show_password.js | 7 ++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/addons/website/data/website_data.xml b/addons/website/data/website_data.xml index ce4091a6352..a1a9c9d689b 100644 --- a/addons/website/data/website_data.xml +++ b/addons/website/data/website_data.xml @@ -143,12 +143,14 @@ Home / + 10 Contact us /contactus + 60 diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 6b390a52bf2..89458b4a5b6 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -189,10 +189,11 @@ class View(models.Model): def _create_website_specific_pages_for_view(self, new_view, website): for page in self.page_ids: # create new pages for this view - page.copy({ + new_page = page.copy({ 'view_id': new_view.id, 'is_published': page.is_published, }) + page.menu_ids.filtered(lambda m: m.website_id.id == website.id).page_id = new_page.id @api.model def get_related_views(self, key, bundles=False): diff --git a/addons/website/static/src/js/menu/content.js b/addons/website/static/src/js/menu/content.js index 866d046bf99..521e4bf8760 100644 --- a/addons/website/static/src/js/menu/content.js +++ b/addons/website/static/src/js/menu/content.js @@ -103,10 +103,10 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({ this.$('.ask_for_redirect').addClass('d-none'); this.$('.redirect_type').addClass('d-none'); this.$('.warn_about_call').addClass('d-none'); - if (this.page.visibility != 'password') { + if (this.page.visibility !== 'password') { this.$('.show_visibility_password').addClass('d-none'); } - if (this.page.visibility != 'restricted_group') { + if (this.page.visibility !== 'restricted_group') { this.$('.show_visibility_group').addClass('d-none'); } this.autocompleteWithGroups(this.$('#visibility_group')); @@ -353,8 +353,8 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({ response(founds); }); }, - change: (event, ui) => { - var $target = $(event.target); + change: (ev, ui) => { + var $target = $(ev.target); if (!ui.item) { $target.val(""); $target.removeData('group-id'); @@ -396,7 +396,9 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({ var createRedirect = this.$('input#create_redirect').prop('checked'); this.$('.redirect_type').toggleClass('d-none', !createRedirect); }, - + /** + * @private + */ _onVisibilityChanged: function (ev) { this.$('.show_visibility_password').toggleClass('d-none', ev.target.value !== 'password'); this.$('.show_visibility_group').toggleClass('d-none', ev.target.value !== 'restricted_group'); diff --git a/addons/website/static/src/js/show_password.js b/addons/website/static/src/js/show_password.js index c9eb24df53c..a27d181208d 100644 --- a/addons/website/static/src/js/show_password.js +++ b/addons/website/static/src/js/show_password.js @@ -1,7 +1,8 @@ // -// This file is meant to determine the timezone of a website visitor -// If the visitor already exists, no need to keep the timezone cookie -// as the timezone is set on the visitor. +// This file is meant to allow to switch the type of an input #password +// from password to text on mousedown on an input group. +// On mouse down, we see the password in clear text +// On mouse up, we hide it again. // odoo.define('website.show_password', function (require) { 'use strict';