diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index fee5216974a..060c603ab1c 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -398,6 +398,9 @@ class Website(Home): t['numOfEl'] = attribs.get('data-number-of-elements') t['numOfElSm'] = attribs.get('data-number-of-elements-sm') t['numOfElFetch'] = attribs.get('data-number-of-elements-fetch') + t['rowPerSlide'] = attribs.get('data-row-per-slide') + t['arrowPosition'] = attribs.get('data-arrow-position') + t['extraClasses'] = attribs.get('data-extra-classes') return templates @http.route('/website/get_current_currency', type='json', auth="public", website=True) diff --git a/addons/website/static/src/snippets/s_dynamic_snippet/000.js b/addons/website/static/src/snippets/s_dynamic_snippet/000.js index 4424ba0c078..3213d9da99a 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet/000.js +++ b/addons/website/static/src/snippets/s_dynamic_snippet/000.js @@ -5,6 +5,8 @@ const core = require('web.core'); const config = require('web.config'); const publicWidget = require('web.public.widget'); const {Markup} = require('web.utils'); +const DEFAULT_NUMBER_OF_ELEMENTS = 4; +const DEFAULT_NUMBER_OF_ELEMENTS_SM = 1; const DynamicSnippet = publicWidget.Widget.extend({ selector: '.s_dynamic_snippet', @@ -134,28 +136,31 @@ const DynamicSnippet = publicWidget.Widget.extend({ * @private */ _prepareContent: function () { - if (this.$target[0].dataset.numberOfElements && this.$target[0].dataset.numberOfElementsSmallDevices) { - this.renderedContent = core.qweb.render( - this.template_key, - this._getQWebRenderOptions()); - } else { - this.renderedContent = ''; - } + this.renderedContent = core.qweb.render( + this.template_key, + this._getQWebRenderOptions() + ); }, /** * Method to be overridden in child components in order to prepare QWeb * options. * @private */ - _getQWebRenderOptions: function () { + _getQWebRenderOptions: function () { + const dataset = this.$target[0].dataset; + const numberOfRecords = parseInt(dataset.numberOfRecords); + let numberOfElements; + if (config.device.isMobile) { + numberOfElements = parseInt(dataset.numberOfElementsSmallDevices) || DEFAULT_NUMBER_OF_ELEMENTS_SM; + } else { + numberOfElements = parseInt(dataset.numberOfElements) || DEFAULT_NUMBER_OF_ELEMENTS; + } + const chunkSize = numberOfRecords < numberOfElements ? numberOfRecords : numberOfElements; return { - chunkSize: parseInt( - config.device.isMobile - ? this.$target[0].dataset.numberOfElementsSmallDevices - : this.$target[0].dataset.numberOfElements - ), + chunkSize: chunkSize, data: this.data, - uniqueId: this.uniqueId + uniqueId: this.uniqueId, + extraClasses: dataset.extraClasses || '', }; }, /** diff --git a/addons/website/static/src/snippets/s_dynamic_snippet/000.xml b/addons/website/static/src/snippets/s_dynamic_snippet/000.xml index 68153dd3453..2498e6c1a85 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet/000.xml +++ b/addons/website/static/src/snippets/s_dynamic_snippet/000.xml @@ -6,7 +6,7 @@ -
+
diff --git a/addons/website/static/src/snippets/s_dynamic_snippet/options.js b/addons/website/static/src/snippets/s_dynamic_snippet/options.js index a0ae018dc21..0540aad9d4e 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet/options.js +++ b/addons/website/static/src/snippets/s_dynamic_snippet/options.js @@ -47,18 +47,6 @@ const dynamicSnippetOptions = options.Class.extend({ if (params.attributeName === 'templateKey' && previewMode === false) { this._templateUpdated(widgetValue, params.activeValue); } - if (params.attributeName === 'numberOfRecords' && previewMode === false) { - const dataSet = this.$target.get(0).dataset; - const numberOfElements = parseInt(dataSet.numberOfElements); - const numberOfRecords = parseInt(dataSet.numberOfRecords); - const numberOfElementsSmallDevices = parseInt(dataSet.numberOfElementsSmallDevices); - if (numberOfElements > numberOfRecords) { - dataSet.numberOfElements = numberOfRecords; - } - if (numberOfElementsSmallDevices > numberOfRecords) { - dataSet.numberOfElementsSmallDevices = numberOfRecords; - } - } }, //-------------------------------------------------------------------------- @@ -79,16 +67,6 @@ const dynamicSnippetOptions = options.Class.extend({ await this._super(...arguments); }, - /** - * @override - */ - async updateUIVisibility() { - await this._super(...arguments); - const template = this._getCurrentTemplate(); - const groupingMessage = this.el.querySelector('.o_grouping_message'); - groupingMessage.classList.toggle('d-none', template && !!template.numOfEl && !!template.numOfElSm); - }, - //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -112,16 +90,6 @@ const dynamicSnippetOptions = options.Class.extend({ return Object.keys(this.dynamicFilters).length !== 1; } - if (widgetName === 'number_of_elements_opt') { - const template = this._getCurrentTemplate(); - return template && !template.numOfEl; - } - - if (widgetName === 'number_of_elements_small_devices_opt') { - const template = this._getCurrentTemplate(); - return template && !template.numOfElSm; - } - if (widgetName === 'number_of_records_opt') { const template = this._getCurrentTemplate(); return template && !template.numOfElFetch; @@ -249,8 +217,6 @@ const dynamicSnippetOptions = options.Class.extend({ // numberOfElements or numberOfElementsSmallDevices) might throw an // exception by not finding the attribute on the element. this.options.wysiwyg.odooEditor.observerUnactive(); - this._setOptionValue('numberOfElements', 4); - this._setOptionValue('numberOfElementsSmallDevices', 1); const filterKeys = this.$el.find("we-select[data-attribute-name='filterId'] we-selection-items we-button"); if (filterKeys.length > 0) { this._setOptionValue('numberOfRecords', this.dynamicFilters[Object.keys(this.dynamicFilters)[0]].limit); @@ -285,13 +251,22 @@ const dynamicSnippetOptions = options.Class.extend({ const template = this.dynamicFilterTemplates[newTemplate]; if (template.numOfEl) { this.$target[0].dataset.numberOfElements = template.numOfEl; + } else { + delete this.$target[0].dataset.numberOfElements; } if (template.numOfElSm) { this.$target[0].dataset.numberOfElementsSmallDevices = template.numOfElSm; + } else { + delete this.$target[0].dataset.numberOfElementsSmallDevices; } if (template.numOfElFetch) { this.$target[0].dataset.numberOfRecords = template.numOfElFetch; } + if (template.extraClasses) { + this.$target[0].dataset.extraClasses = template.extraClasses; + } else { + delete this.$target[0].dataset.extraClasses; + } }, /** * Sets the option value. diff --git a/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.js b/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.js index adae0ab86bd..0948f4acbaf 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.js +++ b/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.js @@ -3,6 +3,7 @@ odoo.define('website.s_dynamic_snippet_carousel', function (require) { const publicWidget = require('web.public.widget'); const DynamicSnippet = require('website.s_dynamic_snippet'); +const config = require('web.config'); const DynamicSnippetCarousel = DynamicSnippet.extend({ selector: '.s_dynamic_snippet_carousel', @@ -26,6 +27,8 @@ const DynamicSnippetCarousel = DynamicSnippet.extend({ this._super.apply(this, arguments), { interval: parseInt(this.$target[0].dataset.carouselInterval), + rowPerSlide: parseInt(config.device.isMobile ? 1 : this.$target[0].dataset.rowPerSlide || 1), + arrowPosition: this.$target[0].dataset.arrowPosition || '', }, ); }, diff --git a/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.scss b/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.scss index 16b2c2ba523..2e2756de413 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.scss +++ b/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.scss @@ -18,4 +18,9 @@ text-overflow: ellipsis; overflow: hidden; } + .s_dynamic_snippet_arrow_bottom { + > .carousel-control-prev, .carousel-control-next { + position: relative; + } + } } diff --git a/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.xml b/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.xml index 9cafb768cf8..6968ced6539 100644 --- a/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.xml +++ b/addons/website/static/src/snippets/s_dynamic_snippet_carousel/000.xml @@ -1,36 +1,60 @@ + + + + Previous + + + + Next + + @@ -47,7 +34,6 @@ - Items per row diff --git a/addons/website/views/snippets/s_dynamic_snippet_carousel.xml b/addons/website/views/snippets/s_dynamic_snippet_carousel.xml index b7042e3cebe..289d807a1f8 100644 --- a/addons/website/views/snippets/s_dynamic_snippet_carousel.xml +++ b/addons/website/views/snippets/s_dynamic_snippet_carousel.xml @@ -9,7 +9,6 @@ - Items per slide diff --git a/addons/website_blog/static/src/snippets/s_blog_posts/options.js b/addons/website_blog/static/src/snippets/s_blog_posts/options.js index 00c82c8fd79..41e5c5c9e95 100644 --- a/addons/website_blog/static/src/snippets/s_blog_posts/options.js +++ b/addons/website_blog/static/src/snippets/s_blog_posts/options.js @@ -78,7 +78,6 @@ const dynamicSnippetBlogPostsOptions = dynamicSnippetOptions.extend({ * @private */ _setOptionsDefaultValues: function () { - this._setOptionValue('numberOfElements', 3); this._setOptionValue('filterByBlogId', -1); this._super.apply(this, arguments); }, diff --git a/addons/website_blog/views/snippets/s_blog_posts.xml b/addons/website_blog/views/snippets/s_blog_posts.xml index d3c58e7e742..d6364c9d926 100644 --- a/addons/website_blog/views/snippets/s_blog_posts.xml +++ b/addons/website_blog/views/snippets/s_blog_posts.xml @@ -11,7 +11,7 @@