diff options
| author | qsm-odoo <qsm@odoo.com> | 2020-08-13 15:35:40 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2020-08-13 15:44:48 +0000 |
| commit | c5fee9d009329691db58a16c1f90eac734749f4d (patch) | |
| tree | 35217344dca023e8156a172a7b81561a557106bc /addons/web_editor/static/src/js | |
| parent | 4afdebbb7e919878966a3b894ce99e913cf046e4 (diff) | |
[FIX] web_editor, *: restore custom snippets thumbnails
*: website
Since [1], the thumbnails of the saved snippets were not right anymore,
all fallbacking to the default image. This is because snippets thumbs
now use svg files instead of png and the snippet saving feature did not
allow it. This commit fixes that and makes the feature more robust.
- Allow to use any original thumbnail, and not only for website app.
- Remove useless defaut image, a fallback for when the feature is broken
is useless.
- Identify snippets by key instead of by main class (possible since
the new `data-snippet` attribute on snippets).
[1]: https://github.com/odoo/odoo/commit/b7fe2bdae2f45372c0d538767a226a413b806f3f
closes odoo/odoo#55896
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js')
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.editor.js | 9 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.options.js | 9 |
2 files changed, 17 insertions, 1 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 cf42d973eba..5c88807ddb1 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -828,6 +828,7 @@ var SnippetsMenu = Widget.extend({ 'snippet_removed': '_onSnippetRemoved', 'snippet_cloned': '_onSnippetCloned', 'snippet_option_visibility_update': '_onSnippetOptionVisibilityUpdate', + 'snippet_thumbnail_url_request': '_onSnippetThumbnailURLRequest', 'reload_snippet_dropzones': '_disableUndroppableSnippets', 'request_save': '_onSaveRequest', 'update_customize_elements': '_onUpdateCustomizeElements', @@ -2311,6 +2312,14 @@ var SnippetsMenu = Widget.extend({ * @private * @param {OdooEvent} ev */ + _onSnippetThumbnailURLRequest(ev) { + const $snippet = this.$snippets.has(`[data-snippet="${ev.data.key}"]`); + ev.data.onSuccess($snippet.length ? $snippet[0].dataset.oeThumbnail : ''); + }, + /** + * @private + * @param {OdooEvent} ev + */ _onUpdateCustomizeElements: function (ev) { this._updateLeftPanelContent({ content: ev.data.customize$Elements, diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index d5a2bc1ff00..bdb60869ebc 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -4355,6 +4355,12 @@ registry.SnippetSave = SnippetOptionWidget.extend({ const snippetName = dialog.el.querySelector('.o_we_snippet_name_input').value; const targetCopyEl = this.$target[0].cloneNode(true); delete targetCopyEl.dataset.name; + const snippetKey = this.$target[0].dataset.snippet; + let thumbnailURL; + this.trigger_up('snippet_thumbnail_url_request', { + key: snippetKey, + onSuccess: url => thumbnailURL = url, + }); await this._rpc({ model: 'ir.ui.view', method: 'save_snippet', @@ -4362,7 +4368,8 @@ registry.SnippetSave = SnippetOptionWidget.extend({ 'name': snippetName, 'arch': targetCopyEl.outerHTML, 'template_key': this.options.snippets, - 'snippet_class': [...this.$target[0].classList].filter(x => /\bs_./g.test(x))[0], + 'snippet_key': snippetKey, + 'thumbnail_url': thumbnailURL, }, }); this.trigger_up('reload_snippet_template'); |
