[IMP] website, *: allow to handle snippets with a list of items

*: web_editor

The goal of this commit is to add the "MultipleItems" option
to be able to add new elements in snippets with a list of items.

In this commit, the option is used for "Media List" & "Tabs".

Part of https://github.com/odoo/odoo/pull/68061
task-2431484
This commit is contained in:
xO-Tx
2021-07-12 08:30:57 +00:00
committed by qsm-odoo
parent 33b74a0fba
commit ebfa28638b
4 changed files with 104 additions and 50 deletions
@@ -6363,6 +6363,75 @@ registry.DynamicSvg = SnippetOptionWidget.extend({
},
});
/**
* Allows to handle snippets with a list of items.
*/
registry.MultipleItems = SnippetOptionWidget.extend({
//--------------------------------------------------------------------------
// Options
//--------------------------------------------------------------------------
/**
* @see this.selectClass for parameters
*/
async addItem(previewMode, widgetValue, params) {
const $target = this.$(params.item);
const addBeforeItem = params.addBefore === 'true';
if ($target.length) {
await new Promise(resolve => {
this.trigger_up('clone_snippet', {
$snippet: $target,
onSuccess: resolve,
});
});
if (addBeforeItem) {
$target.before($target.next());
}
if (params.selectItem !== 'false') {
this.trigger_up('activate_snippet', {
$snippet: addBeforeItem ? $target.prev() : $target.next(),
});
}
this._addItemCallback($target);
}
},
/**
* @see this.selectClass for parameters
*/
async removeItem(previewMode, widgetValue, params) {
const $target = this.$(params.item);
if ($target.length) {
await new Promise(resolve => {
this.trigger_up('remove_snippet', {
$snippet: $target,
onSuccess: resolve,
});
});
this._removeItemCallback($target);
}
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* Allows to add behaviour when item added.
*
* @private
* @abstract
* @param {jQueryElement} $target
*/
_addItemCallback($target) {},
/**
* @private
* @abstract
* @param {jQueryElement} $target
*/
_removeItemCallback($target) {},
});
return {
SnippetOptionWidget: SnippetOptionWidget,
snippetOptionRegistry: registry,