From ff9a9d703f5582d1d1032e6ee056057bf03da2db Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 5 Aug 2016 13:59:05 +0200 Subject: [PATCH] [FIX] web_editor: properly handle many2one fields The many2one fields and their search bar were not working anymore since the loss of some functionnalities with commit b309f3ab543b5195eedc5b06ad08cfa81f43171a. * The dropdown which regroups a snippet options list is hidden if it does not contain any option. This was not the case anymore because it now always contains a dropdown title. This is fixed by simply removing this title if it is alone in the dropdown. * Snippet options attached to an element whose parent is not editable cannot be moved/deleted/duplicated as it is supposed to remain where it is. This is often the case for many2one fields and the feature was simply lost in the refactoring. --- .../web_editor/static/src/js/snippets.editor.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/static/src/js/snippets.editor.js b/addons/web_editor/static/src/js/snippets.editor.js index 19f60a25741..3f7561a8d98 100644 --- a/addons/web_editor/static/src/js/snippets.editor.js +++ b/addons/web_editor/static/src/js/snippets.editor.js @@ -827,9 +827,13 @@ data.Editor = Class.extend({ this.load_style_options(); // Initialize move/clone/remove buttons - this.$overlay.on('click', '.oe_snippet_clone', _.bind(this.on_clone, this)); - this.$overlay.on('click', '.oe_snippet_remove', _.bind(this.on_remove, this)); - this._drag_and_drop(); + if (!this.$target.parent().is(':o_editable')) { + this.$overlay.find('.oe_snippet_move, .oe_snippet_clone, .oe_snippet_remove').remove(); + } else { + this.$overlay.on('click', '.oe_snippet_clone', _.bind(this.on_clone, this)); + this.$overlay.on('click', '.oe_snippet_remove', _.bind(this.on_remove, this)); + this._drag_and_drop(); + } }, getName: function () { @@ -973,7 +977,11 @@ data.Editor = Class.extend({ self.styles[option].start(); self.styles[option].__order = i++; }); - $ul.append($("
  • ", {"class": "divider"})); + if ($ul.children().length > 1) { + $ul.append($("
  • ", {"class": "divider"})); + } else { + $ul.empty(); + } var $parents = this.$target.parents(); _.each($parents, function (parent) {