From 5e6c5d24be38e53d010a8489d2444a3fdaadaa5f Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 1 Jun 2017 17:36:13 +0200 Subject: [PATCH] [FIX] mass_mailing, *: duplicating two-columns snippets * web_editor, website This commit fixes a bug with table duplication in mailing template: - Click on a snippet with two columns - Duplicate it -> the snippet is duplicated but the two columns are transformed in two rows. This was because there is an implemented behavior for column duplication: if we duplicate a column which was alone on its row, we duplicate the row instead. This code should however be triggered when duplicating the column alone to be working, not the snippet that contains it. Note: this required a backport of a33ec972abf1cadbae2a6a04f759617c82f2a95e which was fixing a non-critical "bug" for 11.0. This non-critical "bug" is therefor fixed here too. opw-807105 --- .../mass_mailing/static/src/js/mass_mailing_editor.js | 4 ++-- addons/web_editor/static/src/js/snippets.editor.js | 4 +++- .../website/static/src/js/website.snippets.editor.js | 10 +++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/mass_mailing/static/src/js/mass_mailing_editor.js b/addons/mass_mailing/static/src/js/mass_mailing_editor.js index 9e62986b383..c84981e6a06 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_editor.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_editor.js @@ -87,11 +87,11 @@ options.registry["width-x"] = options.Class.extend({ }); options.registry.table_item = options.Class.extend({ - on_clone: function ($clone) { + on_clone: function ($clone, options) { this._super.apply(this, arguments); // If we cloned a td or th element... - if (this.$target.is("td, th")) { + if (options.isCurrent && this.$target.is("td, th")) { // ... and that the td or th element was alone on its row ... if (this.$target.siblings().length === 1) { var $tr = $clone.parent(); diff --git a/addons/web_editor/static/src/js/snippets.editor.js b/addons/web_editor/static/src/js/snippets.editor.js index 91269285235..97830d2ae8e 100644 --- a/addons/web_editor/static/src/js/snippets.editor.js +++ b/addons/web_editor/static/src/js/snippets.editor.js @@ -1010,7 +1010,9 @@ data.Editor = Class.extend({ this.$target.after($clone); this.buildingBlock.call_for_all_snippets($clone, function (editor, $snippet) { for (var i in editor.styles) { - editor.styles[i].on_clone($snippet); + editor.styles[i].on_clone($snippet, { + isCurrent: ($snippet.is($clone)), + }); } }); return false; diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js index ff41acfc677..4f9e66943e5 100644 --- a/addons/website/static/src/js/website.snippets.editor.js +++ b/addons/website/static/src/js/website.snippets.editor.js @@ -263,9 +263,13 @@ options.registry["margin-x"] = options.registry.marginAndResize.extend({ return this.grid; }, - on_clone: function ($clone) { - var _class = $clone.attr("class").replace(/\s*(col-lg-offset-|col-md-offset-)([0-9-]+)/g, ''); - $clone.attr("class", _class); + on_clone: function ($clone, options) { + // Below condition is added to remove offset of target element only + // and not its children to avoid design alteration of a container / block. + if (options.isCurrent) { + var _class = $clone.attr("class").replace(/\s*(col-lg-offset-|col-md-offset-)([0-9-]+)/g, ''); + $clone.attr("class", _class); + } return false; }, on_resize: function (compass, beginClass, current) {