Files
odoo_source/addons/website/static/tests/tours/conditional_visibility.js
T
Arthur Detroux (ard)andqsm-odoo 1c442782f8 [IMP] website, *: add visibility options on sections
*: web_editor

Provide the user with an option to hide or display a section tag
depending on the visitor's location (if geoip enabled), language,
utm_medium, utm_source and utm_campaign.

Users can use a M2M widget to select different records. These will be
used to create a CSS selector on save that will hide the section tag
depending on the various options they selected.
This CSS selectors will be applied, as well as various data attributes
when the page loads to hide the targeted tag. All of these operations
are handled client side.

The geoip country had to be added to the session for the feature to work
with countries.

Part of https://github.com/odoo/odoo/pull/67140
task-2381049

closes odoo/odoo#67140

Related: odoo/enterprise#19907
Related: odoo/upgrade#2658
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Co-authored-by: qsm-odoo <qsm@odoo.com>
2021-07-30 14:03:42 +00:00

77 lines
2.2 KiB
JavaScript

/** @odoo-module */
import tour from 'web_tour.tour';
import wTourUtils from 'website.tour_utils';
const snippets = [
{
id: 's_text_image',
name: 'Text - Image',
},
];
tour.register('conditional_visibility_1', {
test: true,
url: '/',
},
[{
content: "enter edit mode",
trigger: 'a[data-action=edit]',
},
wTourUtils.dragNDrop(snippets[0]),
wTourUtils.clickOnSnippet(snippets[0]),
wTourUtils.changeOption('ConditionalVisibility', 'we-toggler'),
{
content: 'click on conditional visibility',
trigger: '[data-name="visibility_conditional"]',
run: 'click',
},
{
content: 'click on utm medium toggler',
trigger: '[data-save-attribute="visibilityValueUtmMedium"] we-toggler',
run: 'click',
},
{
trigger: '[data-save-attribute="visibilityValueUtmMedium"] we-selection-items [data-add-record="Email"]',
content: 'click on Email',
run: 'click',
},
...wTourUtils.clickOnSave(),
{
content: 'Check if the rule was applied',
trigger: 'body:not(.editor_enable) #wrap',
run: function (actions) {
const style = window.getComputedStyle(this.$anchor[0].getElementsByClassName('s_text_image')[0]);
if (style.display !== 'none') {
console.error('error This item should be invisible and only visible if utm_medium === email');
}
},
},
wTourUtils.clickOnEdit(),
{
content: 'Check if the element is visible as it should always be visible in edit view',
trigger: 'body.editor_enable #wrap .s_text_image',
run: function (actions) {
const style = window.getComputedStyle((this.$anchor[0]));
if (style.display === 'none') {
console.error('error This item should now be visible because utm_medium === email');
}
},
},
]);
tour.register('conditional_visibility_2', {
test: true,
url: '/?utm_medium=Email',
},
[{
content: 'The content previously hidden should now be visible',
trigger: 'body #wrap',
run: function (actions) {
const style = window.getComputedStyle(this.$anchor[0].getElementsByClassName('s_text_image')[0]);
if (style.display === 'none') {
console.error('error This item should now be visible because utm_medium === email');
}
},
},
]);