From a34043d4042fc274a4cf2a7610e8a2e0e81da9d2 Mon Sep 17 00:00:00 2001 From: fja-odoo Date: Fri, 20 Mar 2020 14:02:34 +0000 Subject: [PATCH] [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 --- .../static/src/js/editor/snippets.options.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) 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 c160ec38649..fa14b441d7c 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -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.