diff options
| author | qsm-odoo <qsm@odoo.com> | 2018-06-20 15:14:08 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2018-06-21 12:54:17 +0200 |
| commit | f6bbc40fbe16ea5ab01ad03b8e1519c4e559bf6d (patch) | |
| tree | 836b21a73307745b26403b48e0a6f54f0e5b7df7 | |
| parent | fd5062eb633d29281b4f4ac68b02e7dbe1a0b9af (diff) | |
[FIX] web_editor: reset snippet editors on snippet move
As indicated in a code comment, destroying and rebuilding all snippet
editors when a snippet is moved is more accurate as the snippet options
may depend on the new locations in a way the 'onMove' callback cannot
handle. That operation seemed however too costly for no visual benefit
at the time. Now, not implementing it is a source of bugs and redundant
code (as with the new "number of columns" option which is not properly
updated once a column is moved in another row), so this commit
implements the feature.
This also allows for some improvement: the 'cleanForSave' part of
snippet editors is always performed when they are destroyed.
If this proves to be ok and safe, we might want to backport this in
previous versions.
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.editor.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 708f576ebc8..cc59d8af59b 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -90,6 +90,7 @@ var SnippetEditor = Widget.extend({ * @override */ destroy: function () { + this.cleanForSave(); this._super.apply(this, arguments); this.$target.removeData('snippet-editor'); }, @@ -634,9 +635,7 @@ var SnippetsMenu = Widget.extend({ */ cleanForSave: function () { this.trigger_up('ready_to_clean_for_save'); - _.each(this.snippetEditors, function (snippetEditor) { - snippetEditor.cleanForSave(); - }); + this._destroyEditors(); this.$editable.find('[contentEditable]') .removeAttr('contentEditable') @@ -818,6 +817,14 @@ var SnippetsMenu = Widget.extend({ return $.when(); }, /** + * @private + */ + _destroyEditors: function () { + _.each(this.snippetEditors, function (snippetEditor) { + snippetEditor.destroy(); + }); + }, + /** * Updates the cover dimensions of the current snippet editor. * * @private @@ -1355,15 +1362,11 @@ var SnippetsMenu = Widget.extend({ /** * Called when a snippet has moved in the page. * - * @todo technically, as a snippet has been moved, all editors should be - * destroyed as their snippet options may not correspond to their - * selector anymore. However this should rarely (maybe never ?) be the case, - * so we might not want to do this as it would slow the editor. - * * @private * @param {OdooEvent} ev */ _onDragAndDropStop: function (ev) { + this._destroyEditors(); this._activateSnippet(ev.data.$snippet); }, /** |
