[IMP] web_editor: add selectProperty option method
This method will enable property selection as an option default method. Part of: https://github.com/odoo/odoo/pull/47949 task-2011583
This commit is contained in:
@@ -2287,6 +2287,22 @@ const SnippetOptionWidget = Widget.extend({
|
||||
const value = this._selectAttributeHelper(widgetValue, params);
|
||||
this.$target[0].setAttribute(params.attributeName, value);
|
||||
},
|
||||
/**
|
||||
* Default option method which allows to select a value and set it on the
|
||||
* associated snippet as a property. The name of the property is
|
||||
* given by the propertyName parameter.
|
||||
*
|
||||
* @param {boolean} previewMode - @see this.selectClass
|
||||
* @param {string} widgetValue
|
||||
* @param {Object} params
|
||||
*/
|
||||
selectProperty: function (previewMode, widgetValue, params) {
|
||||
if (!params.propertyName) {
|
||||
throw new Error('Property name missing');
|
||||
}
|
||||
const value = this._selectValueHelper(widgetValue, params);
|
||||
this.$target[0][params.propertyName] = value;
|
||||
},
|
||||
/**
|
||||
* Default option method which allows to select a value and set it on the
|
||||
* associated snippet as a css style. The name of the css property is
|
||||
@@ -2938,14 +2954,22 @@ const SnippetOptionWidget = Widget.extend({
|
||||
/**
|
||||
* Used to handle attribute or data attribute value change
|
||||
*
|
||||
* @param {string} value
|
||||
* @param {Object} params
|
||||
* @returns {string|undefined}
|
||||
* @see this._selectValueHelper for parameters
|
||||
*/
|
||||
_selectAttributeHelper(value, params) {
|
||||
if (!params.attributeName) {
|
||||
throw new Error('Attribute name missing');
|
||||
}
|
||||
return this._selectValueHelper(value, params);
|
||||
},
|
||||
/**
|
||||
* Used to handle value of a select
|
||||
*
|
||||
* @param {string} value
|
||||
* @param {Object} params
|
||||
* @returns {string|undefined}
|
||||
*/
|
||||
_selectValueHelper(value, params) {
|
||||
if (params.saveUnit && !params.withUnit) {
|
||||
// Values that come with an unit are saved without unit as
|
||||
// data-attribute unless told otherwise.
|
||||
|
||||
Reference in New Issue
Block a user