[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.
This commit is contained in:
@@ -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')
|
||||
@@ -817,6 +816,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.
|
||||
*
|
||||
@@ -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);
|
||||
},
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user