[FIX] website: remove ToC snippet on removing last content

The user has the option to remove the last block from the Table of
Content snippet prior to this commit, but doing so breaks the Add Item
feature because there is no reference to adding a new item in the
snippet area, and doing so is also not a good idea.

If the block is the final one in the Table of Content after this commit,
removing the last Content will remove the ToC snippet.

task-3081442

closes odoo/odoo#135733

X-original-commit: 164db4013439042725c94f1690ae0a311be9d554
Signed-off-by: Guillaume Dieleman (gdi) <gdi@odoo.com>
This commit is contained in:
can-odoo
2023-09-17 14:37:09 +00:00
committed by Guillaume (gdi)
parent 31f0b21cda
commit 402bf48fb5
@@ -78,6 +78,16 @@ options.registry.TableOfContent = options.Class.extend({
* @private
*/
_generateNav: function (ev) {
const blockTextContent = this.$target[0].textContent.replaceAll('\n', '').trim();
if (blockTextContent === '') {
// destroy public widget and remove the ToC since there are no more
// child elements, before doing so the observer needs to be
// disconnected else observer observe mutation and _generateNav
// gets called even after there's no more ToC.
this.observer.disconnect();
this.trigger_up('remove_snippet', {$snippet: this.$target});
return;
}
this.options.wysiwyg && this.options.wysiwyg.odooEditor.unbreakableStepUnactive();
const headingsEls = this.$target.find(this.targetedElements).toArray()
.filter(el => !el.closest('.o_snippet_desktop_invisible'));